From 43399778dd95c35a5d03d85b398275bb0f618ff7 Mon Sep 17 00:00:00 2001 From: William Zijie Zhang Date: Thu, 1 Jan 2026 14:59:56 -0500 Subject: [PATCH 1/3] adds jacobian of log of a matrix --- tests/all_tests.c | 1 + tests/jacobian_tests/test_log.h | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/tests/all_tests.c b/tests/all_tests.c index efe5baf..f52ab38 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_matrix_log, 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..75b116d 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_matrix_log() +{ + 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("matrix log vals fail", cmp_double_array(log_node->jacobian->x, expected_Ax, 4)); + mu_assert("matrix log rows fail", cmp_int_array(log_node->jacobian->p, expected_Ap, 5)); + mu_assert("matrix log cols fail", cmp_int_array(log_node->jacobian->i, expected_Ai, 4)); + free_expr(log_node); + free_expr(u); + return 0; +} From d7ba47b3a9123b0539aeb8704e0e183d35406395 Mon Sep 17 00:00:00 2001 From: William Zijie Zhang Date: Fri, 2 Jan 2026 05:07:52 -0500 Subject: [PATCH 2/3] edit after formatting --- tests/jacobian_tests/test_log.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/jacobian_tests/test_log.h b/tests/jacobian_tests/test_log.h index 75b116d..fe378c8 100644 --- a/tests/jacobian_tests/test_log.h +++ b/tests/jacobian_tests/test_log.h @@ -36,9 +36,9 @@ const char *test_jacobian_matrix_log() log_node->forward(log_node, u_vals); log_node->jacobian_init(log_node); log_node->eval_jacobian(log_node); - mu_assert("matrix log vals fail", cmp_double_array(log_node->jacobian->x, expected_Ax, 4)); - mu_assert("matrix log rows fail", cmp_int_array(log_node->jacobian->p, expected_Ap, 5)); - mu_assert("matrix log cols fail", cmp_int_array(log_node->jacobian->i, expected_Ai, 4)); + 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; From dd460306712b2a9132e68c2e0a444ac98346c09d Mon Sep 17 00:00:00 2001 From: William Zijie Zhang Date: Fri, 2 Jan 2026 05:16:02 -0500 Subject: [PATCH 3/3] change naming of test --- tests/all_tests.c | 2 +- tests/jacobian_tests/test_log.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/all_tests.c b/tests/all_tests.c index f52ab38..ad9225d 100644 --- a/tests/all_tests.c +++ b/tests/all_tests.c @@ -44,7 +44,7 @@ int main(void) printf("\n--- Jacobian Tests ---\n"); mu_run_test(test_jacobian_log, tests_run); - mu_run_test(test_jacobian_matrix_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 fe378c8..2708d84 100644 --- a/tests/jacobian_tests/test_log.h +++ b/tests/jacobian_tests/test_log.h @@ -25,7 +25,7 @@ const char *test_jacobian_log() return 0; } -const char *test_jacobian_matrix_log() +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};