Skip to content

Commit 10340df

Browse files
authored
[WIP] more tests (#62)
* more tests * run formatter
1 parent 7f671cb commit 10340df

4 files changed

Lines changed: 34 additions & 1 deletion

File tree

src/affine/trace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ static void wsum_hess_init(expr *node)
102102

103103
/* initialize child's hessian */
104104
x->wsum_hess_init(x);
105-
105+
106106
node->work->dwork = (double *) calloc(x->size, sizeof(double));
107107

108108
/* We copy over the sparsity pattern from the child. This also includes the

tests/all_tests.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ int main(void)
133133
mu_run_test(test_jacobian_composite_exp, tests_run);
134134
mu_run_test(test_jacobian_exp_sum, tests_run);
135135
mu_run_test(test_jacobian_exp_sum_mult, tests_run);
136+
mu_run_test(test_jacobian_sin_cos, tests_run);
136137
mu_run_test(test_jacobian_composite_exp_add, tests_run);
137138
mu_run_test(test_jacobian_const_scalar_mult_log_vector, tests_run);
138139
mu_run_test(test_jacobian_const_scalar_mult_log_matrix, tests_run);
@@ -265,6 +266,7 @@ int main(void)
265266
mu_run_test(test_wsum_hess_exp_sum_matmul, tests_run);
266267
mu_run_test(test_wsum_hess_sin_sum_axis0_matmul, tests_run);
267268
mu_run_test(test_wsum_hess_logistic_sum_axis0_matmul, tests_run);
269+
mu_run_test(test_wsum_hess_sin_cos, tests_run);
268270

269271
printf("\n--- Utility Tests ---\n");
270272
mu_run_test(test_cblas_ddot, tests_run);

tests/jacobian_tests/test_chain_rule_jacobian.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,18 @@ const char *test_jacobian_exp_sum_mult(void)
3535
free_expr(exp_sum_xy);
3636
return 0;
3737
}
38+
39+
const char *test_jacobian_sin_cos(void)
40+
{
41+
double u_vals[5] = {0.5, 1.0, 1.5, 2.0, 2.5};
42+
43+
expr *x = new_variable(5, 1, 0, 5);
44+
expr *cos_x = new_cos(x);
45+
expr *sin_cos_x = new_sin(cos_x);
46+
47+
mu_assert("check_jacobian failed",
48+
check_jacobian(sin_cos_x, u_vals, NUMERICAL_DIFF_DEFAULT_H));
49+
50+
free_expr(sin_cos_x);
51+
return 0;
52+
}

tests/wsum_hess/test_chain_rule_wsum_hess.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,19 @@ const char *test_wsum_hess_logistic_sum_axis0_matmul(void)
9898
free_expr(logistic_sum_XY);
9999
return 0;
100100
}
101+
102+
const char *test_wsum_hess_sin_cos(void)
103+
{
104+
double u_vals[5] = {0.5, 1.0, 1.5, 2.0, 2.5};
105+
double w[5] = {1.0, 2.0, 3.0, 4.0, 5.0};
106+
107+
expr *x = new_variable(5, 1, 0, 5);
108+
expr *cos_x = new_cos(x);
109+
expr *sin_cos_x = new_sin(cos_x);
110+
111+
mu_assert("check_wsum_hess failed",
112+
check_wsum_hess(sin_cos_x, u_vals, w, NUMERICAL_DIFF_DEFAULT_H));
113+
114+
free_expr(sin_cos_x);
115+
return 0;
116+
}

0 commit comments

Comments
 (0)