|
7 | 7 | #include "test_helpers.h" |
8 | 8 | #include "utils/CSC_Matrix.h" |
9 | 9 |
|
| 10 | +const char *test_csr_to_csc1() |
| 11 | +{ |
| 12 | + CSR_Matrix *A = new_csr_matrix(4, 5, 5); |
| 13 | + double Ax[5] = {1.0, 1.0, 3.0, 2.0, 4.0}; |
| 14 | + int Ai[5] = {0, 4, 1, 0, 1}; |
| 15 | + int Ap[5] = {0, 2, 3, 4, 5}; |
| 16 | + memcpy(A->x, Ax, 5 * sizeof(double)); |
| 17 | + memcpy(A->i, Ai, 5 * sizeof(int)); |
| 18 | + memcpy(A->p, Ap, 5 * sizeof(int)); |
| 19 | + |
| 20 | + CSC_Matrix *C = csr_to_csc(A); |
| 21 | + |
| 22 | + double Cx_correct[5] = {1.0, 2.0, 3.0, 4.0, 1.0}; |
| 23 | + int Ci_correct[5] = {0, 2, 1, 3, 0}; |
| 24 | + int Cp_correct[6] = {0, 2, 4, 4, 4, 5}; |
| 25 | + |
| 26 | + mu_assert("C vals incorrect", cmp_double_array(C->x, Cx_correct, 5)); |
| 27 | + mu_assert("C rows incorrect", cmp_int_array(C->i, Ci_correct, 5)); |
| 28 | + mu_assert("C cols incorrect", cmp_int_array(C->p, Cp_correct, 6)); |
| 29 | + |
| 30 | + free_csr_matrix(A); |
| 31 | + free_csc_matrix(C); |
| 32 | + |
| 33 | + return 0; |
| 34 | +} |
| 35 | + |
| 36 | +const char *test_csr_to_csc2() |
| 37 | +{ |
| 38 | + CSR_Matrix *A = new_csr_matrix(20, 30, 120); |
| 39 | + double Ax[120] = {9, 6, 5, 9, 7, 3, 8, 2, 6, 1, 3, 9, 2, 8, 9, 1, 4, 9, 2, 1, |
| 40 | + 3, 4, 2, 8, 6, 2, 9, 7, 3, 8, 3, 7, 9, 2, 2, 2, 5, 5, 3, 5, |
| 41 | + 1, 6, 7, 2, 7, 3, 3, 7, 3, 5, 4, 7, 7, 3, 6, 3, 6, 1, 8, 8, |
| 42 | + 3, 2, 2, 3, 4, 5, 5, 5, 8, 3, 5, 3, 7, 5, 1, 4, 9, 6, 6, 7, |
| 43 | + 4, 6, 8, 2, 7, 3, 5, 3, 3, 4, 7, 3, 6, 4, 2, 1, 1, 5, 5, 8, |
| 44 | + 1, 9, 5, 2, 3, 8, 5, 8, 4, 5, 5, 6, 9, 6, 4, 4, 1, 8, 9, 8}; |
| 45 | + int Ai[120] = {1, 2, 3, 19, 21, 22, 9, 10, 19, 20, 25, 0, 6, 8, 9, |
| 46 | + 12, 15, 19, 20, 21, 26, 2, 5, 6, 8, 12, 14, 16, 19, 27, |
| 47 | + 8, 11, 13, 15, 25, 26, 27, 10, 12, 19, 22, 23, 24, 25, 28, |
| 48 | + 1, 11, 12, 15, 18, 24, 13, 22, 2, 5, 6, 9, 18, 24, 3, |
| 49 | + 6, 8, 22, 20, 27, 7, 9, 17, 26, 29, 0, 1, 11, 13, 15, |
| 50 | + 16, 18, 23, 24, 4, 5, 8, 9, 16, 20, 23, 4, 6, 14, 15, |
| 51 | + 24, 8, 9, 11, 12, 20, 22, 29, 2, 5, 12, 14, 15, 19, 21, |
| 52 | + 10, 19, 27, 1, 5, 6, 9, 11, 15, 21, 26, 3, 15, 26, 27}; |
| 53 | + int Ap[21] = {0, 6, 11, 21, 30, 37, 45, 51, 53, 59, 63, |
| 54 | + 65, 70, 79, 86, 91, 98, 105, 108, 116, 120}; |
| 55 | + memcpy(A->x, Ax, 120 * sizeof(double)); |
| 56 | + memcpy(A->i, Ai, 120 * sizeof(int)); |
| 57 | + memcpy(A->p, Ap, 21 * sizeof(int)); |
| 58 | + |
| 59 | + CSC_Matrix *C = csr_to_csc(A); |
| 60 | + |
| 61 | + double Cx_correct[120] = { |
| 62 | + 9, 5, 9, 3, 3, 4, 6, 4, 3, 5, 5, 8, 1, 7, 5, 2, 6, 4, 8, 5, 2, 8, 3, 3, |
| 63 | + 3, 5, 5, 8, 6, 3, 2, 6, 3, 8, 9, 6, 5, 8, 6, 6, 2, 5, 8, 7, 3, 7, 4, 9, |
| 64 | + 1, 2, 3, 7, 2, 1, 9, 7, 5, 9, 3, 9, 4, 2, 3, 1, 4, 5, 6, 8, 7, 4, 2, 5, |
| 65 | + 5, 1, 9, 9, 6, 9, 3, 5, 2, 5, 1, 2, 3, 7, 1, 7, 1, 3, 4, 3, 1, 7, 2, 1, |
| 66 | + 6, 6, 3, 7, 4, 8, 6, 7, 3, 2, 2, 3, 2, 8, 4, 9, 8, 5, 4, 8, 8, 7, 3, 5}; |
| 67 | + int Ci_correct[120] = { |
| 68 | + 2, 12, 0, 6, 12, 18, 0, 3, 8, 16, 0, 9, 19, 13, 14, 3, 8, 13, |
| 69 | + 16, 18, 2, 3, 8, 9, 14, 18, 11, 2, 3, 4, 9, 13, 15, 1, 2, 8, |
| 70 | + 11, 13, 15, 18, 1, 5, 17, 4, 6, 12, 15, 18, 2, 3, 5, 6, 15, 16, |
| 71 | + 4, 7, 12, 3, 14, 16, 2, 4, 6, 12, 14, 16, 18, 19, 3, 12, 13, 11, |
| 72 | + 6, 8, 12, 0, 1, 2, 3, 5, 16, 17, 1, 2, 10, 13, 15, 0, 2, 16, |
| 73 | + 18, 0, 5, 7, 9, 15, 5, 12, 13, 5, 6, 8, 12, 14, 1, 4, 5, 2, |
| 74 | + 4, 11, 18, 19, 3, 4, 10, 17, 19, 5, 11, 15}; |
| 75 | + int Cp_correct[31] = {0, 2, 6, 10, 13, 15, 20, 26, 27, 33, 40, |
| 76 | + 43, 48, 54, 57, 60, 68, 71, 72, 75, 82, 87, |
| 77 | + 91, 96, 99, 104, 107, 112, 117, 118, 120}; |
| 78 | + |
| 79 | + mu_assert("C vals incorrect", cmp_double_array(C->x, Cx_correct, 120)); |
| 80 | + mu_assert("C rows incorrect", cmp_int_array(C->i, Ci_correct, 120)); |
| 81 | + mu_assert("C cols incorrect", cmp_int_array(C->p, Cp_correct, 31)); |
| 82 | + |
| 83 | + free_csr_matrix(A); |
| 84 | + free_csc_matrix(C); |
| 85 | + |
| 86 | + return 0; |
| 87 | +} |
| 88 | + |
10 | 89 | /* Test ATA_alloc with a simple 3x3 example |
11 | 90 | * A is 4x3 (4 rows, 3 columns): |
12 | 91 | * [x 0 x] |
|
0 commit comments