|
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" |
@@ -36,7 +37,16 @@ const char *test_jacobian_left_matmul_log() |
36 | 37 | expr *A_param = new_parameter(4, 3, PARAM_FIXED, 3, A_vals); |
37 | 38 |
|
38 | 39 | expr *log_x = new_log(x); |
39 | | - expr *A_log_x = new_left_matmul(A_param, log_x); |
| 40 | + CSR_Matrix *A_csr = new_csr_matrix(4, 3, 7); |
| 41 | + int A_p[5] = {0, 2, 4, 6, 7}; |
| 42 | + int A_i[7] = {0, 2, 0, 2, 0, 2, 0}; |
| 43 | + double A_x[7] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0}; |
| 44 | + memcpy(A_csr->p, A_p, 5 * sizeof(int)); |
| 45 | + memcpy(A_csr->i, A_i, 7 * sizeof(int)); |
| 46 | + memcpy(A_csr->x, A_x, 7 * sizeof(double)); |
| 47 | + |
| 48 | + expr *A_log_x = new_left_matmul(A_param, log_x, A_csr); |
| 49 | + free_csr_matrix(A_csr); |
40 | 50 |
|
41 | 51 | A_log_x->forward(A_log_x, x_vals); |
42 | 52 | A_log_x->jacobian_init(A_log_x); |
@@ -74,7 +84,16 @@ const char *test_jacobian_left_matmul_log_matrix() |
74 | 84 | expr *A_param = new_parameter(4, 3, PARAM_FIXED, 6, A_vals); |
75 | 85 |
|
76 | 86 | expr *log_x = new_log(x); |
77 | | - expr *A_log_x = new_left_matmul(A_param, log_x); |
| 87 | + CSR_Matrix *A_csr = new_csr_matrix(4, 3, 7); |
| 88 | + int A_p[5] = {0, 2, 4, 6, 7}; |
| 89 | + int A_i[7] = {0, 2, 0, 2, 0, 2, 0}; |
| 90 | + double A_x[7] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0}; |
| 91 | + memcpy(A_csr->p, A_p, 5 * sizeof(int)); |
| 92 | + memcpy(A_csr->i, A_i, 7 * sizeof(int)); |
| 93 | + memcpy(A_csr->x, A_x, 7 * sizeof(double)); |
| 94 | + |
| 95 | + expr *A_log_x = new_left_matmul(A_param, log_x, A_csr); |
| 96 | + free_csr_matrix(A_csr); |
78 | 97 |
|
79 | 98 | A_log_x->forward(A_log_x, x_vals); |
80 | 99 | A_log_x->jacobian_init(A_log_x); |
@@ -140,7 +159,16 @@ const char *test_jacobian_left_matmul_log_composite() |
140 | 159 |
|
141 | 160 | expr *Bx = new_linear(x, B, NULL); |
142 | 161 | expr *log_Bx = new_log(Bx); |
143 | | - expr *A_log_Bx = new_left_matmul(A_param, log_Bx); |
| 162 | + CSR_Matrix *A_csr = new_csr_matrix(4, 3, 7); |
| 163 | + int A_p[5] = {0, 2, 4, 6, 7}; |
| 164 | + int A_i[7] = {0, 2, 0, 2, 0, 2, 0}; |
| 165 | + double A_x[7] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0}; |
| 166 | + memcpy(A_csr->p, A_p, 5 * sizeof(int)); |
| 167 | + memcpy(A_csr->i, A_i, 7 * sizeof(int)); |
| 168 | + memcpy(A_csr->x, A_x, 7 * sizeof(double)); |
| 169 | + |
| 170 | + expr *A_log_Bx = new_left_matmul(A_param, log_Bx, A_csr); |
| 171 | + free_csr_matrix(A_csr); |
144 | 172 |
|
145 | 173 | A_log_Bx->forward(A_log_Bx, x_vals); |
146 | 174 | A_log_Bx->jacobian_init(A_log_Bx); |
|
0 commit comments