|
1 | 1 | #include <math.h> |
2 | 2 | #include <stdio.h> |
| 3 | +#include <string.h> |
3 | 4 |
|
4 | 5 | #include "bivariate.h" |
5 | 6 | #include "elementwise_univariate.h" |
@@ -31,12 +32,18 @@ const char *test_jacobian_left_matmul_log() |
31 | 32 | double x_vals[3] = {1.0, 2.0, 3.0}; |
32 | 33 | expr *x = new_variable(3, 1, 0, 3); |
33 | 34 |
|
34 | | - /* A is 4x3: [1, 0, 2; 3, 0, 4; 5, 0, 6; 7, 0, 0] in column-major order */ |
35 | | - double A_vals[12] = {1.0, 3.0, 5.0, 7.0, 0.0, 0.0, 0.0, 0.0, 2.0, 4.0, 6.0, 0.0}; |
36 | | - expr *A_param = new_parameter(4, 3, PARAM_FIXED, 3, A_vals); |
| 35 | + /* A is 4x3: [1, 0, 2; 3, 0, 4; 5, 0, 6; 7, 0, 0] */ |
| 36 | + CSR_Matrix *A = new_csr_matrix(4, 3, 7); |
| 37 | + int A_p[5] = {0, 2, 4, 6, 7}; |
| 38 | + int A_i[7] = {0, 2, 0, 2, 0, 2, 0}; |
| 39 | + double A_x[7] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0}; |
| 40 | + memcpy(A->p, A_p, 5 * sizeof(int)); |
| 41 | + memcpy(A->i, A_i, 7 * sizeof(int)); |
| 42 | + memcpy(A->x, A_x, 7 * sizeof(double)); |
37 | 43 |
|
38 | 44 | expr *log_x = new_log(x); |
39 | | - expr *A_log_x = new_left_matmul(A_param, log_x); |
| 45 | + expr *A_log_x = new_left_matmul(NULL, log_x, A); |
| 46 | + free_csr_matrix(A); |
40 | 47 |
|
41 | 48 | A_log_x->forward(A_log_x, x_vals); |
42 | 49 | A_log_x->jacobian_init(A_log_x); |
@@ -69,12 +76,18 @@ const char *test_jacobian_left_matmul_log_matrix() |
69 | 76 | double x_vals[6] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0}; |
70 | 77 | expr *x = new_variable(3, 2, 0, 6); |
71 | 78 |
|
72 | | - /* A is 4x3: [1, 0, 2; 3, 0, 4; 5, 0, 6; 7, 0, 0] in column-major order */ |
73 | | - double A_vals[12] = {1.0, 3.0, 5.0, 7.0, 0.0, 0.0, 0.0, 0.0, 2.0, 4.0, 6.0, 0.0}; |
74 | | - expr *A_param = new_parameter(4, 3, PARAM_FIXED, 6, A_vals); |
| 79 | + /* A is 4x3: [1, 0, 2; 3, 0, 4; 5, 0, 6; 7, 0, 0] */ |
| 80 | + CSR_Matrix *A = new_csr_matrix(4, 3, 7); |
| 81 | + int A_p[5] = {0, 2, 4, 6, 7}; |
| 82 | + int A_i[7] = {0, 2, 0, 2, 0, 2, 0}; |
| 83 | + double A_x[7] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0}; |
| 84 | + memcpy(A->p, A_p, 5 * sizeof(int)); |
| 85 | + memcpy(A->i, A_i, 7 * sizeof(int)); |
| 86 | + memcpy(A->x, A_x, 7 * sizeof(double)); |
75 | 87 |
|
76 | 88 | expr *log_x = new_log(x); |
77 | | - expr *A_log_x = new_left_matmul(A_param, log_x); |
| 89 | + expr *A_log_x = new_left_matmul(NULL, log_x, A); |
| 90 | + free_csr_matrix(A); |
78 | 91 |
|
79 | 92 | A_log_x->forward(A_log_x, x_vals); |
80 | 93 | A_log_x->jacobian_init(A_log_x); |
@@ -134,13 +147,19 @@ const char *test_jacobian_left_matmul_log_composite() |
134 | 147 | memcpy(B->i, B_i, 9 * sizeof(int)); |
135 | 148 | memcpy(B->x, B_x, 9 * sizeof(double)); |
136 | 149 |
|
137 | | - /* A is 4x3: [1, 0, 2; 3, 0, 4; 5, 0, 6; 7, 0, 0] in column-major order */ |
138 | | - double A_vals[12] = {1.0, 3.0, 5.0, 7.0, 0.0, 0.0, 0.0, 0.0, 2.0, 4.0, 6.0, 0.0}; |
139 | | - expr *A_param = new_parameter(4, 3, PARAM_FIXED, 3, A_vals); |
| 150 | + /* A is 4x3: [1, 0, 2; 3, 0, 4; 5, 0, 6; 7, 0, 0] */ |
| 151 | + CSR_Matrix *A = new_csr_matrix(4, 3, 7); |
| 152 | + int A_p[5] = {0, 2, 4, 6, 7}; |
| 153 | + int A_i[7] = {0, 2, 0, 2, 0, 2, 0}; |
| 154 | + double A_x[7] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0}; |
| 155 | + memcpy(A->p, A_p, 5 * sizeof(int)); |
| 156 | + memcpy(A->i, A_i, 7 * sizeof(int)); |
| 157 | + memcpy(A->x, A_x, 7 * sizeof(double)); |
140 | 158 |
|
141 | 159 | expr *Bx = new_linear(x, B, NULL); |
142 | 160 | expr *log_Bx = new_log(Bx); |
143 | | - expr *A_log_Bx = new_left_matmul(A_param, log_Bx); |
| 161 | + expr *A_log_Bx = new_left_matmul(NULL, log_Bx, A); |
| 162 | + free_csr_matrix(A); |
144 | 163 |
|
145 | 164 | A_log_Bx->forward(A_log_Bx, x_vals); |
146 | 165 | A_log_Bx->jacobian_init(A_log_Bx); |
|
0 commit comments