diff --git a/tests/all_tests.c b/tests/all_tests.c index efe5baf..ad9225d 100644 --- a/tests/all_tests.c +++ b/tests/all_tests.c @@ -44,6 +44,7 @@ int main(void) printf("\n--- Jacobian Tests ---\n"); mu_run_test(test_jacobian_log, tests_run); + mu_run_test(test_jacobian_log_matrix, tests_run); mu_run_test(test_jacobian_composite_log, tests_run); mu_run_test(test_jacobian_composite_log_add, tests_run); mu_run_test(test_jacobian_rel_entr_vector_args_1, tests_run); diff --git a/tests/jacobian_tests/test_log.h b/tests/jacobian_tests/test_log.h index 7660bec..2708d84 100644 --- a/tests/jacobian_tests/test_log.h +++ b/tests/jacobian_tests/test_log.h @@ -24,3 +24,22 @@ const char *test_jacobian_log() free_expr(u); return 0; } + +const char *test_jacobian_log_matrix() +{ + double u_vals[7] = {0.0, 0.0, 0.0, 1.0, 2.0, 4.0, 5.0}; + double expected_Ax[4] = {1.0, 0.5, 0.25, 0.2}; + int expected_Ap[5] = {0, 1, 2, 3, 4}; + int expected_Ai[4] = {3, 4, 5, 6}; + expr *u = new_variable(2, 2, 3, 7); + expr *log_node = new_log(u); + log_node->forward(log_node, u_vals); + log_node->jacobian_init(log_node); + log_node->eval_jacobian(log_node); + mu_assert("vals fail", cmp_double_array(log_node->jacobian->x, expected_Ax, 4)); + mu_assert("rows fail", cmp_int_array(log_node->jacobian->p, expected_Ap, 5)); + mu_assert("cols fail", cmp_int_array(log_node->jacobian->i, expected_Ai, 4)); + free_expr(log_node); + free_expr(u); + return 0; +}