From f0ac285b8e5f336c4b7f0b743fff1b713686420d Mon Sep 17 00:00:00 2001 From: dance858 Date: Fri, 27 Mar 2026 08:02:37 -0700 Subject: [PATCH 1/5] function for random matrices and two tessts --- src/bivariate_full_dom/multiply.c | 3 + tests/all_tests.c | 3 + .../composite/test_chain_rule_jacobian.h | 61 +++++++++++++++++++ tests/test_helpers.c | 60 +++++++++++++++++- tests/test_helpers.h | 8 ++- 5 files changed, 132 insertions(+), 3 deletions(-) diff --git a/src/bivariate_full_dom/multiply.c b/src/bivariate_full_dom/multiply.c index 9d31c737..a20ed5d9 100644 --- a/src/bivariate_full_dom/multiply.c +++ b/src/bivariate_full_dom/multiply.c @@ -63,6 +63,9 @@ static void eval_jacobian(expr *node) expr *x = node->left; expr *y = node->right; + x->eval_jacobian(x); + y->eval_jacobian(y); + /* chain rule */ sum_scaled_csr_matrices_fill_values(x->jacobian, y->jacobian, node->jacobian, y->value, x->value); diff --git a/tests/all_tests.c b/tests/all_tests.c index dc1f5c43..d8ba5b4e 100644 --- a/tests/all_tests.c +++ b/tests/all_tests.c @@ -134,6 +134,9 @@ int main(void) mu_run_test(test_jacobian_exp_sum, tests_run); mu_run_test(test_jacobian_exp_sum_mult, tests_run); mu_run_test(test_jacobian_sin_cos, tests_run); + mu_run_test(test_jacobian_cos_sin_multiply, tests_run); + mu_run_test(test_jacobian_Ax_Bx_multiply, tests_run); + mu_run_test(test_jacobian_AX_BX_multiply, tests_run); mu_run_test(test_jacobian_composite_exp_add, tests_run); mu_run_test(test_jacobian_const_scalar_mult_log_vector, tests_run); mu_run_test(test_jacobian_const_scalar_mult_log_matrix, tests_run); diff --git a/tests/jacobian_tests/composite/test_chain_rule_jacobian.h b/tests/jacobian_tests/composite/test_chain_rule_jacobian.h index d0348421..52bb7223 100644 --- a/tests/jacobian_tests/composite/test_chain_rule_jacobian.h +++ b/tests/jacobian_tests/composite/test_chain_rule_jacobian.h @@ -1,8 +1,11 @@ #include "affine.h" #include "bivariate_full_dom.h" #include "elementwise_full_dom.h" +#include "expr.h" #include "minunit.h" #include "numerical_diff.h" +#include "utils/CSR_Matrix.h" +#include "test_helpers.h" const char *test_jacobian_exp_sum(void) { @@ -50,3 +53,61 @@ const char *test_jacobian_sin_cos(void) free_expr(sin_cos_x); return 0; } + +const char *test_jacobian_cos_sin_multiply(void) +{ + double u_vals[4] = {1.0, 2.0, 3.0, 4.0}; + + expr *x = new_variable(2, 1, 0, 4); + expr *y = new_variable(2, 1, 2, 4); + expr *cos_x = new_cos(x); + expr *cos_y = new_cos(y); + expr *sum = new_add(cos_x, cos_y); + expr *sin_y = new_sin(y); + expr *multiply = new_elementwise_mult(sum, sin_y); + + mu_assert("check_jacobian failed", + check_jacobian(multiply, u_vals, NUMERICAL_DIFF_DEFAULT_H)); + + free_expr(multiply); + return 0; +} + +const char *test_jacobian_Ax_Bx_multiply(void) +{ + /* the first and last values are not used, but good to include them in test */ + double u_vals[4] = {1.0, 2.0, 3.0, 4.0}; + + CSR_Matrix *A = new_csr_random(2, 2, 1.0); + CSR_Matrix *B = new_csr_random(2, 2, 1.0); + expr *x = new_variable(2, 1, 1, 4); + expr *Ax = new_left_matmul(x, A); + expr *Bx = new_left_matmul(x, B); + expr *multiply = new_elementwise_mult(Ax, Bx); + + mu_assert("check_jacobian failed", + check_jacobian(multiply, u_vals, NUMERICAL_DIFF_DEFAULT_H)); + + free_expr(multiply); + return 0; +} + +const char *test_jacobian_AX_BX_multiply(void) +{ + double u_vals[4] = {1.0, 2.0, 3.0, 4.0}; + + CSR_Matrix *A = new_csr_random(2, 2, 1.0); + CSR_Matrix *B = new_csr_random(2, 2, 1.0); + expr *X = new_variable(2, 2, 0, 4); + expr *AX = new_left_matmul(X, A); + expr *BX = new_left_matmul(X, B); + expr *multiply = new_elementwise_mult(new_sin(AX), new_cos(BX)); + + mu_assert("check_jacobian failed", + check_jacobian(multiply, u_vals, NUMERICAL_DIFF_DEFAULT_H)); + + free_expr(multiply); + return 0; +} + + diff --git a/tests/test_helpers.c b/tests/test_helpers.c index 8085e669..9dc1c35a 100644 --- a/tests/test_helpers.c +++ b/tests/test_helpers.c @@ -1,7 +1,10 @@ #include #include +#include +#include #include "expr.h" +#include "utils/CSR_Matrix.h" #define EPSILON 1e-7 @@ -33,10 +36,63 @@ int cmp_int_array(const int *actual, const int *expected, int size) { if (actual[i] != expected[i]) { - printf(" FAILED: actual[%d] = %d, expected %d\n", i, actual[i], - expected[i]); + printf(" FAILED: actual[%d] = %d, expected %d\n", i, + actual[i], expected[i]); return 0; } } return 1; } + +/* Standard normal via Box-Muller transform */ +static double randn(void) +{ + double u1 = ((double) rand() + 1.0) / ((double) RAND_MAX + 1.0); + double u2 = ((double) rand() + 1.0) / ((double) RAND_MAX + 1.0); + return sqrt(-2.0 * log(u1)) * cos(2.0 * M_PI * u2); +} + +CSR_Matrix *new_csr_random(int m, int n, double density) +{ + /* Single pass: over-allocate, fill, then copy to exact size */ + int cap = (int) ((double) m * (double) n * density * 1.5) + m; + int *tmp_p = (int *) malloc(((size_t) m + 1) * sizeof(int)); + int *tmp_i = (int *) malloc((size_t) cap * sizeof(int)); + double *tmp_x = (double *) malloc((size_t) cap * sizeof(double)); + + int nnz = 0; + for (int r = 0; r < m; r++) + { + tmp_p[r] = nnz; + for (int c = 0; c < n; c++) + { + double u = (double) rand() / (double) RAND_MAX; + if (u < density) + { + if (nnz >= cap) + { + cap *= 2; + tmp_i = (int *) realloc( + tmp_i, (size_t) cap * sizeof(int)); + tmp_x = (double *) realloc( + tmp_x, + (size_t) cap * sizeof(double)); + } + tmp_i[nnz] = c; + tmp_x[nnz] = randn(); + nnz++; + } + } + } + tmp_p[m] = nnz; + + CSR_Matrix *A = new_csr_matrix(m, n, nnz); + memcpy(A->p, tmp_p, ((size_t) m + 1) * sizeof(int)); + memcpy(A->i, tmp_i, (size_t) nnz * sizeof(int)); + memcpy(A->x, tmp_x, (size_t) nnz * sizeof(double)); + + free(tmp_p); + free(tmp_i); + free(tmp_x); + return A; +} diff --git a/tests/test_helpers.h b/tests/test_helpers.h index e5bbde93..b9ecaf15 100644 --- a/tests/test_helpers.h +++ b/tests/test_helpers.h @@ -2,13 +2,19 @@ #define TEST_HELPERS_H #include "expr.h" +#include "utils/CSR_Matrix.h" /* Compare two double arrays directly * Returns 1 if all values match, 0 otherwise */ -int cmp_double_array(const double *actual, const double *expected, int size); +int cmp_double_array(const double *actual, const double *expected, + int size); /* Compare two int arrays directly * Returns 1 if all values match, 0 otherwise */ int cmp_int_array(const int *actual, const int *expected, int size); +/* Create a random m x n CSR matrix with approximate nonzero density + * in [0, 1]. Nonzero values are standard Gaussian (Box-Muller). */ +CSR_Matrix *new_csr_random(int m, int n, double density); + #endif /* TEST_HELPERS_H */ From cc69b9169cd4f866cff52623eee9e619528184ea Mon Sep 17 00:00:00 2001 From: dance858 Date: Fri, 27 Mar 2026 08:05:48 -0700 Subject: [PATCH 2/5] run forammter --- .../composite/test_chain_rule_jacobian.h | 4 +--- tests/test_helpers.c | 15 ++++++++------- tests/test_helpers.h | 3 +-- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/tests/jacobian_tests/composite/test_chain_rule_jacobian.h b/tests/jacobian_tests/composite/test_chain_rule_jacobian.h index 52bb7223..69cd163f 100644 --- a/tests/jacobian_tests/composite/test_chain_rule_jacobian.h +++ b/tests/jacobian_tests/composite/test_chain_rule_jacobian.h @@ -4,8 +4,8 @@ #include "expr.h" #include "minunit.h" #include "numerical_diff.h" -#include "utils/CSR_Matrix.h" #include "test_helpers.h" +#include "utils/CSR_Matrix.h" const char *test_jacobian_exp_sum(void) { @@ -109,5 +109,3 @@ const char *test_jacobian_AX_BX_multiply(void) free_expr(multiply); return 0; } - - diff --git a/tests/test_helpers.c b/tests/test_helpers.c index 9dc1c35a..90d84461 100644 --- a/tests/test_helpers.c +++ b/tests/test_helpers.c @@ -36,14 +36,18 @@ int cmp_int_array(const int *actual, const int *expected, int size) { if (actual[i] != expected[i]) { - printf(" FAILED: actual[%d] = %d, expected %d\n", i, - actual[i], expected[i]); + printf(" FAILED: actual[%d] = %d, expected %d\n", i, actual[i], + expected[i]); return 0; } } return 1; } +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif + /* Standard normal via Box-Muller transform */ static double randn(void) { @@ -72,11 +76,8 @@ CSR_Matrix *new_csr_random(int m, int n, double density) if (nnz >= cap) { cap *= 2; - tmp_i = (int *) realloc( - tmp_i, (size_t) cap * sizeof(int)); - tmp_x = (double *) realloc( - tmp_x, - (size_t) cap * sizeof(double)); + tmp_i = (int *) realloc(tmp_i, (size_t) cap * sizeof(int)); + tmp_x = (double *) realloc(tmp_x, (size_t) cap * sizeof(double)); } tmp_i[nnz] = c; tmp_x[nnz] = randn(); diff --git a/tests/test_helpers.h b/tests/test_helpers.h index b9ecaf15..fd471512 100644 --- a/tests/test_helpers.h +++ b/tests/test_helpers.h @@ -6,8 +6,7 @@ /* Compare two double arrays directly * Returns 1 if all values match, 0 otherwise */ -int cmp_double_array(const double *actual, const double *expected, - int size); +int cmp_double_array(const double *actual, const double *expected, int size); /* Compare two int arrays directly * Returns 1 if all values match, 0 otherwise */ From 3bab767569d1109c523e9f7e22029053800acad5 Mon Sep 17 00:00:00 2001 From: dance858 Date: Fri, 27 Mar 2026 08:08:03 -0700 Subject: [PATCH 3/5] free matrices --- tests/jacobian_tests/composite/test_chain_rule_jacobian.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/jacobian_tests/composite/test_chain_rule_jacobian.h b/tests/jacobian_tests/composite/test_chain_rule_jacobian.h index 69cd163f..4a6dde97 100644 --- a/tests/jacobian_tests/composite/test_chain_rule_jacobian.h +++ b/tests/jacobian_tests/composite/test_chain_rule_jacobian.h @@ -89,6 +89,8 @@ const char *test_jacobian_Ax_Bx_multiply(void) check_jacobian(multiply, u_vals, NUMERICAL_DIFF_DEFAULT_H)); free_expr(multiply); + free_csr_matrix(A); + free_csr_matrix(B); return 0; } @@ -107,5 +109,7 @@ const char *test_jacobian_AX_BX_multiply(void) check_jacobian(multiply, u_vals, NUMERICAL_DIFF_DEFAULT_H)); free_expr(multiply); + free_csr_matrix(A); + free_csr_matrix(B); return 0; } From 77903ec42fe6b3c18b5c51c9bb453a9a742daa09 Mon Sep 17 00:00:00 2001 From: dance858 Date: Fri, 27 Mar 2026 08:25:39 -0700 Subject: [PATCH 4/5] add guard for initializing jacobian or hessian twice --- include/expr.h | 9 +++++++-- src/affine/add.c | 16 ++++++++-------- src/affine/broadcast.c | 12 ++++++------ src/affine/const_scalar_mult.c | 12 ++++++------ src/affine/const_vector_mult.c | 12 ++++++------ src/affine/constant.c | 8 ++++---- src/affine/diag_vec.c | 12 ++++++------ src/affine/hstack.c | 12 ++++++------ src/affine/index.c | 12 ++++++------ src/affine/left_matmul.c | 16 ++++++++-------- src/affine/linear_op.c | 4 ++-- src/affine/neg.c | 16 ++++++++-------- src/affine/promote.c | 12 ++++++------ src/affine/reshape.c | 12 ++++++------ src/affine/sum.c | 12 ++++++------ src/affine/trace.c | 12 ++++++------ src/affine/transpose.c | 12 ++++++------ src/affine/variable.c | 8 ++++---- src/bivariate_full_dom/matmul.c | 8 ++++---- src/bivariate_full_dom/multiply.c | 12 ++++++------ src/bivariate_restricted_dom/quad_over_lin.c | 8 ++++---- src/elementwise_full_dom/common.c | 4 ++-- src/expr.c | 16 ++++++++++++++-- src/other/prod.c | 10 +++++----- src/other/prod_axis_one.c | 10 +++++----- src/other/prod_axis_zero.c | 10 +++++----- src/other/quad_form.c | 10 +++++----- src/problem.c | 8 ++++---- tests/jacobian_tests/affine/test_broadcast.h | 8 ++++---- .../affine/test_const_scalar_mult.h | 4 ++-- .../affine/test_const_vector_mult.h | 4 ++-- tests/jacobian_tests/affine/test_hstack.h | 4 ++-- tests/jacobian_tests/affine/test_index.h | 8 ++++---- tests/jacobian_tests/affine/test_left_matmul.h | 4 ++-- tests/jacobian_tests/affine/test_neg.h | 4 ++-- tests/jacobian_tests/affine/test_promote.h | 4 ++-- tests/jacobian_tests/affine/test_right_matmul.h | 4 ++-- tests/jacobian_tests/affine/test_sum.h | 10 +++++----- tests/jacobian_tests/affine/test_trace.h | 4 ++-- tests/jacobian_tests/affine/test_transpose.h | 2 +- tests/jacobian_tests/affine/test_vstack.h | 4 ++-- .../bivariate_full_dom/test_elementwise_mult.h | 8 ++++---- .../bivariate_full_dom/test_matmul.h | 2 +- .../test_quad_over_lin.h | 10 +++++----- .../bivariate_restricted_dom/test_rel_entr.h | 6 +++--- .../test_rel_entr_scalar_vector.h | 2 +- .../test_rel_entr_vector_scalar.h | 2 +- .../composite/test_composite_exp.h | 2 +- .../elementwise_restricted_dom/test_log.h | 4 ++-- tests/jacobian_tests/other/test_prod.h | 6 +++--- tests/jacobian_tests/other/test_prod_axis_one.h | 4 ++-- tests/jacobian_tests/other/test_prod_axis_zero.h | 2 +- tests/jacobian_tests/other/test_quad_form.h | 4 ++-- tests/numerical_diff.c | 6 +++--- tests/profiling/profile_left_matmul.h | 2 +- tests/wsum_hess/affine/test_broadcast.h | 12 ++++++------ tests/wsum_hess/affine/test_const_scalar_mult.h | 4 ++-- tests/wsum_hess/affine/test_const_vector_mult.h | 4 ++-- tests/wsum_hess/affine/test_hstack.h | 6 +++--- tests/wsum_hess/affine/test_index.h | 12 ++++++------ tests/wsum_hess/affine/test_left_matmul.h | 8 ++++---- tests/wsum_hess/affine/test_right_matmul.h | 8 ++++---- tests/wsum_hess/affine/test_sum.h | 8 ++++---- tests/wsum_hess/affine/test_trace.h | 12 ++++++------ tests/wsum_hess/affine/test_transpose.h | 2 +- tests/wsum_hess/affine/test_vstack.h | 8 ++++---- tests/wsum_hess/bivariate_full_dom/test_matmul.h | 4 ++-- .../wsum_hess/bivariate_full_dom/test_multiply.h | 8 ++++---- .../test_quad_over_lin.h | 4 ++-- .../bivariate_restricted_dom/test_rel_entr.h | 6 +++--- .../test_rel_entr_scalar_vector.h | 2 +- .../test_rel_entr_vector_scalar.h | 2 +- tests/wsum_hess/elementwise_full_dom/test_exp.h | 2 +- .../elementwise_full_dom/test_hyperbolic.h | 8 ++++---- .../elementwise_full_dom/test_logistic.h | 4 ++-- .../wsum_hess/elementwise_full_dom/test_power.h | 2 +- tests/wsum_hess/elementwise_full_dom/test_trig.h | 6 +++--- tests/wsum_hess/elementwise_full_dom/test_xexp.h | 2 +- .../elementwise_restricted_dom/test_entr.h | 2 +- .../elementwise_restricted_dom/test_log.h | 2 +- tests/wsum_hess/other/test_prod.h | 8 ++++---- tests/wsum_hess/other/test_prod_axis_one.h | 8 ++++---- tests/wsum_hess/other/test_prod_axis_zero.h | 6 +++--- tests/wsum_hess/other/test_quad_form.h | 4 ++-- 84 files changed, 305 insertions(+), 288 deletions(-) diff --git a/include/expr.h b/include/expr.h index 65a0e99a..b2ea35c1 100644 --- a/include/expr.h +++ b/include/expr.h @@ -73,8 +73,8 @@ typedef struct expr CSR_Matrix *jacobian; CSR_Matrix *wsum_hess; forward_fn forward; - jacobian_init_fn jacobian_init; - wsum_hess_init_fn wsum_hess_init; + jacobian_init_fn jacobian_init_impl; + wsum_hess_init_fn wsum_hess_init_impl; eval_jacobian_fn eval_jacobian; wsum_hess_fn eval_wsum_hess; @@ -99,6 +99,11 @@ void init_expr(expr *node, int d1, int d2, int n_vars, forward_fn forward, void free_expr(expr *node); +/* Guarded init: skips if already initialized (safe for DAGs + * where a node may be visited through multiple parents). */ +void jacobian_init(expr *node); +void wsum_hess_init(expr *node); + /* Initialize CSC form of the Jacobian from the CSR Jacobian. * Must be called after jacobian_init. */ void jacobian_csc_init(expr *node); diff --git a/src/affine/add.c b/src/affine/add.c index ce7b4b1d..f34160b1 100644 --- a/src/affine/add.c +++ b/src/affine/add.c @@ -34,11 +34,11 @@ static void forward(expr *node, const double *u) } } -static void jacobian_init(expr *node) +static void jacobian_init_impl(expr *node) { /* initialize children's jacobians */ - node->left->jacobian_init(node->left); - node->right->jacobian_init(node->right); + jacobian_init(node->left); + jacobian_init(node->right); /* we never have to store more than the sum of children's nnz */ int nnz_max = node->left->jacobian->nnz + node->right->jacobian->nnz; @@ -60,11 +60,11 @@ static void eval_jacobian(expr *node) node->jacobian); } -static void wsum_hess_init(expr *node) +static void wsum_hess_init_impl(expr *node) { /* initialize children's wsum_hess */ - node->left->wsum_hess_init(node->left); - node->right->wsum_hess_init(node->right); + wsum_hess_init(node->left); + wsum_hess_init(node->right); /* we never have to store more than the sum of children's nnz */ int nnz_max = node->left->wsum_hess->nnz + node->right->wsum_hess->nnz; @@ -95,8 +95,8 @@ expr *new_add(expr *left, expr *right) { assert(left->d1 == right->d1 && left->d2 == right->d2); expr *node = (expr *) calloc(1, sizeof(expr)); - init_expr(node, left->d1, left->d2, left->n_vars, forward, jacobian_init, - eval_jacobian, is_affine, wsum_hess_init, eval_wsum_hess, NULL); + init_expr(node, left->d1, left->d2, left->n_vars, forward, jacobian_init_impl, + eval_jacobian, is_affine, wsum_hess_init_impl, eval_wsum_hess, NULL); node->left = left; node->right = right; expr_retain(left); diff --git a/src/affine/broadcast.c b/src/affine/broadcast.c index e0f09bb8..bec72989 100644 --- a/src/affine/broadcast.c +++ b/src/affine/broadcast.c @@ -66,10 +66,10 @@ static void forward(expr *node, const double *u) } } -static void jacobian_init(expr *node) +static void jacobian_init_impl(expr *node) { expr *x = node->left; - x->jacobian_init(x); + jacobian_init(x); broadcast_expr *bcast = (broadcast_expr *) node; int total_nnz; @@ -185,10 +185,10 @@ static void eval_jacobian(expr *node) } } -static void wsum_hess_init(expr *node) +static void wsum_hess_init_impl(expr *node) { expr *x = node->left; - x->wsum_hess_init(x); + wsum_hess_init(x); /* Same sparsity as child - weights get summed */ node->wsum_hess = new_csr_copy_sparsity(x->wsum_hess); @@ -279,8 +279,8 @@ expr *new_broadcast(expr *child, int d1, int d2) // -------------------------------------------------------------------------- // initialize the rest of the expression // -------------------------------------------------------------------------- - init_expr(node, d1, d2, child->n_vars, forward, jacobian_init, eval_jacobian, - is_affine, wsum_hess_init, eval_wsum_hess, NULL); + init_expr(node, d1, d2, child->n_vars, forward, jacobian_init_impl, eval_jacobian, + is_affine, wsum_hess_init_impl, eval_wsum_hess, NULL); node->left = child; expr_retain(child); bcast->type = type; diff --git a/src/affine/const_scalar_mult.c b/src/affine/const_scalar_mult.c index 47777298..0c81aff9 100644 --- a/src/affine/const_scalar_mult.c +++ b/src/affine/const_scalar_mult.c @@ -39,12 +39,12 @@ static void forward(expr *node, const double *u) } } -static void jacobian_init(expr *node) +static void jacobian_init_impl(expr *node) { expr *x = node->left; /* initialize child jacobian */ - x->jacobian_init(x); + jacobian_init(x); /* same sparsity as child */ node->jacobian = new_csr_copy_sparsity(x->jacobian); @@ -65,12 +65,12 @@ static void eval_jacobian(expr *node) } } -static void wsum_hess_init(expr *node) +static void wsum_hess_init_impl(expr *node) { expr *x = node->left; /* initialize child's weighted Hessian */ - x->wsum_hess_init(x); + wsum_hess_init(x); /* same sparsity as child */ node->wsum_hess = new_csr_copy_sparsity(x->wsum_hess); @@ -100,8 +100,8 @@ expr *new_const_scalar_mult(double a, expr *child) (const_scalar_mult_expr *) calloc(1, sizeof(const_scalar_mult_expr)); expr *node = &mult_node->base; - init_expr(node, child->d1, child->d2, child->n_vars, forward, jacobian_init, - eval_jacobian, is_affine, wsum_hess_init, eval_wsum_hess, NULL); + init_expr(node, child->d1, child->d2, child->n_vars, forward, jacobian_init_impl, + eval_jacobian, is_affine, wsum_hess_init_impl, eval_wsum_hess, NULL); node->left = child; mult_node->a = a; expr_retain(child); diff --git a/src/affine/const_vector_mult.c b/src/affine/const_vector_mult.c index 3e3f01f0..ad7c81e3 100644 --- a/src/affine/const_vector_mult.c +++ b/src/affine/const_vector_mult.c @@ -38,12 +38,12 @@ static void forward(expr *node, const double *u) } } -static void jacobian_init(expr *node) +static void jacobian_init_impl(expr *node) { expr *x = node->left; /* initialize child jacobian */ - x->jacobian_init(x); + jacobian_init(x); /* same sparsity as child */ node->jacobian = new_csr_copy_sparsity(x->jacobian); @@ -67,12 +67,12 @@ static void eval_jacobian(expr *node) } } -static void wsum_hess_init(expr *node) +static void wsum_hess_init_impl(expr *node) { expr *x = node->left; /* initialize child's weighted Hessian */ - x->wsum_hess_init(x); + wsum_hess_init(x); /* same sparsity as child */ node->wsum_hess = new_csr_copy_sparsity(x->wsum_hess); @@ -115,8 +115,8 @@ expr *new_const_vector_mult(const double *a, expr *child) (const_vector_mult_expr *) calloc(1, sizeof(const_vector_mult_expr)); expr *node = &vnode->base; - init_expr(node, child->d1, child->d2, child->n_vars, forward, jacobian_init, - eval_jacobian, is_affine, wsum_hess_init, eval_wsum_hess, + init_expr(node, child->d1, child->d2, child->n_vars, forward, jacobian_init_impl, + eval_jacobian, is_affine, wsum_hess_init_impl, eval_wsum_hess, free_type_data); node->left = child; expr_retain(child); diff --git a/src/affine/constant.c b/src/affine/constant.c index 59da3e27..3e1c6b39 100644 --- a/src/affine/constant.c +++ b/src/affine/constant.c @@ -26,7 +26,7 @@ static void forward(expr *node, const double *u) (void) u; } -static void jacobian_init(expr *node) +static void jacobian_init_impl(expr *node) { /* Constant jacobian is all zeros: size x n_vars with 0 nonzeros. * new_csr_matrix uses calloc for row pointers, so they're already 0. */ @@ -39,7 +39,7 @@ static void eval_jacobian(expr *node) (void) node; } -static void wsum_hess_init(expr *node) +static void wsum_hess_init_impl(expr *node) { /* Constant Hessian is all zeros: n_vars x n_vars with 0 nonzeros. */ node->wsum_hess = new_csr_matrix(node->n_vars, node->n_vars, 0); @@ -61,8 +61,8 @@ static bool is_affine(const expr *node) expr *new_constant(int d1, int d2, int n_vars, const double *values) { expr *node = (expr *) calloc(1, sizeof(expr)); - init_expr(node, d1, d2, n_vars, forward, jacobian_init, eval_jacobian, is_affine, - wsum_hess_init, eval_wsum_hess, NULL); + init_expr(node, d1, d2, n_vars, forward, jacobian_init_impl, eval_jacobian, is_affine, + wsum_hess_init_impl, eval_wsum_hess, NULL); memcpy(node->value, values, node->size * sizeof(double)); return node; diff --git a/src/affine/diag_vec.c b/src/affine/diag_vec.c index 53d2aec8..05404d18 100644 --- a/src/affine/diag_vec.c +++ b/src/affine/diag_vec.c @@ -44,11 +44,11 @@ static void forward(expr *node, const double *u) } } -static void jacobian_init(expr *node) +static void jacobian_init_impl(expr *node) { expr *x = node->left; int n = x->size; - x->jacobian_init(x); + jacobian_init(x); CSR_Matrix *Jx = x->jacobian; CSR_Matrix *J = new_csr_matrix(node->size, node->n_vars, Jx->nnz); @@ -92,12 +92,12 @@ static void eval_jacobian(expr *node) } } -static void wsum_hess_init(expr *node) +static void wsum_hess_init_impl(expr *node) { expr *x = node->left; /* initialize child's wsum_hess */ - x->wsum_hess_init(x); + wsum_hess_init(x); /* workspace for extracting diagonal weights */ node->work->dwork = (double *) calloc(x->size, sizeof(double)); @@ -137,8 +137,8 @@ expr *new_diag_vec(expr *child) /* n is the number of elements (works for both row and column vectors) */ int n = child->size; expr *node = (expr *) calloc(1, sizeof(expr)); - init_expr(node, n, n, child->n_vars, forward, jacobian_init, eval_jacobian, - is_affine, wsum_hess_init, eval_wsum_hess, NULL); + init_expr(node, n, n, child->n_vars, forward, jacobian_init_impl, eval_jacobian, + is_affine, wsum_hess_init_impl, eval_wsum_hess, NULL); node->left = child; expr_retain(child); diff --git a/src/affine/hstack.c b/src/affine/hstack.c index e2235d61..08c09546 100644 --- a/src/affine/hstack.c +++ b/src/affine/hstack.c @@ -42,7 +42,7 @@ static void forward(expr *node, const double *u) } } -static void jacobian_init(expr *node) +static void jacobian_init_impl(expr *node) { hstack_expr *hnode = (hstack_expr *) node; @@ -51,7 +51,7 @@ static void jacobian_init(expr *node) for (int i = 0; i < hnode->n_args; i++) { assert(hnode->args[i] != NULL); - hnode->args[i]->jacobian_init(hnode->args[i]); + jacobian_init(hnode->args[i]); nnz += hnode->args[i]->jacobian->nnz; } @@ -100,14 +100,14 @@ static void eval_jacobian(expr *node) } } -static void wsum_hess_init(expr *node) +static void wsum_hess_init_impl(expr *node) { /* initialize children's hessians */ hstack_expr *hnode = (hstack_expr *) node; int nnz = 0; for (int i = 0; i < hnode->n_args; i++) { - hnode->args[i]->wsum_hess_init(hnode->args[i]); + wsum_hess_init(hnode->args[i]); nnz += hnode->args[i]->wsum_hess->nnz; } @@ -187,8 +187,8 @@ expr *new_hstack(expr **args, int n_args, int n_vars) /* Allocate the type-specific struct */ hstack_expr *hnode = (hstack_expr *) calloc(1, sizeof(hstack_expr)); expr *node = &hnode->base; - init_expr(node, args[0]->d1, d2, n_vars, forward, jacobian_init, eval_jacobian, - is_affine, wsum_hess_init, wsum_hess_eval, free_type_data); + init_expr(node, args[0]->d1, d2, n_vars, forward, jacobian_init_impl, eval_jacobian, + is_affine, wsum_hess_init_impl, wsum_hess_eval, free_type_data); /* Set type-specific fields (deep copy args array) */ hnode->args = (expr **) calloc(n_args, sizeof(expr *)); diff --git a/src/affine/index.c b/src/affine/index.c index d47f3ffa..c18154ec 100644 --- a/src/affine/index.c +++ b/src/affine/index.c @@ -57,11 +57,11 @@ static void forward(expr *node, const double *u) } } -static void jacobian_init(expr *node) +static void jacobian_init_impl(expr *node) { expr *x = node->left; index_expr *idx = (index_expr *) node; - x->jacobian_init(x); + jacobian_init(x); CSR_Matrix *Jx = x->jacobian; CSR_Matrix *J = new_csr_matrix(node->size, node->n_vars, Jx->nnz); @@ -96,12 +96,12 @@ static void eval_jacobian(expr *node) } } -static void wsum_hess_init(expr *node) +static void wsum_hess_init_impl(expr *node) { expr *x = node->left; /* initialize child's wsum_hess */ - x->wsum_hess_init(x); + wsum_hess_init(x); /* for setting weight vector to evaluate hessian of child */ node->work->dwork = (double *) calloc(x->size, sizeof(double)); @@ -166,8 +166,8 @@ expr *new_index(expr *child, int d1, int d2, const int *indices, int n_idxs) index_expr *idx = (index_expr *) calloc(1, sizeof(index_expr)); expr *node = &idx->base; - init_expr(node, d1, d2, child->n_vars, forward, jacobian_init, eval_jacobian, - is_affine, wsum_hess_init, eval_wsum_hess, free_type_data); + init_expr(node, d1, d2, child->n_vars, forward, jacobian_init_impl, eval_jacobian, + is_affine, wsum_hess_init_impl, eval_wsum_hess, free_type_data); node->left = child; expr_retain(child); diff --git a/src/affine/left_matmul.c b/src/affine/left_matmul.c index 20f5ce8e..be62f288 100644 --- a/src/affine/left_matmul.c +++ b/src/affine/left_matmul.c @@ -81,13 +81,13 @@ static void free_type_data(expr *node) lnode->csc_to_csr_work = NULL; } -static void jacobian_init(expr *node) +static void jacobian_init_impl(expr *node) { expr *x = node->left; left_matmul_expr *lnode = (left_matmul_expr *) node; /* initialize child's jacobian and precompute sparsity of its CSC */ - x->jacobian_init(x); + jacobian_init(x); lnode->Jchild_CSC = csr_to_csc_fill_sparsity(x->jacobian, node->work->iwork); /* precompute sparsity of this node's jacobian in CSC and CSR */ @@ -113,11 +113,11 @@ static void eval_jacobian(expr *node) csc_to_csr_fill_values(J_CSC, node->jacobian, lnode->csc_to_csr_work); } -static void wsum_hess_init(expr *node) +static void wsum_hess_init_impl(expr *node) { /* initialize child's hessian */ expr *x = node->left; - x->wsum_hess_init(x); + wsum_hess_init(x); /* allocate this node's hessian with the same sparsity as child's */ node->wsum_hess = new_csr_copy_sparsity(x->wsum_hess); @@ -169,8 +169,8 @@ expr *new_left_matmul(expr *u, const CSR_Matrix *A) left_matmul_expr *lnode = (left_matmul_expr *) calloc(1, sizeof(left_matmul_expr)); expr *node = &lnode->base; - init_expr(node, d1, d2, u->n_vars, forward, jacobian_init, eval_jacobian, - is_affine, wsum_hess_init, eval_wsum_hess, free_type_data); + init_expr(node, d1, d2, u->n_vars, forward, jacobian_init_impl, eval_jacobian, + is_affine, wsum_hess_init_impl, eval_wsum_hess, free_type_data); node->left = u; expr_retain(u); @@ -214,8 +214,8 @@ expr *new_left_matmul_dense(expr *u, int m, int n, const double *data) left_matmul_expr *lnode = (left_matmul_expr *) calloc(1, sizeof(left_matmul_expr)); expr *node = &lnode->base; - init_expr(node, d1, d2, u->n_vars, forward, jacobian_init, eval_jacobian, - is_affine, wsum_hess_init, eval_wsum_hess, free_type_data); + init_expr(node, d1, d2, u->n_vars, forward, jacobian_init_impl, eval_jacobian, + is_affine, wsum_hess_init_impl, eval_wsum_hess, free_type_data); node->left = u; expr_retain(u); diff --git a/src/affine/linear_op.c b/src/affine/linear_op.c index d9895e15..1dee37a4 100644 --- a/src/affine/linear_op.c +++ b/src/affine/linear_op.c @@ -69,7 +69,7 @@ static void free_type_data(expr *node) lin_node->A_csc = NULL; } -static void jacobian_init(expr *node) +static void jacobian_init_impl(expr *node) { node->jacobian = ((linear_op_expr *) node)->A_csr; } @@ -86,7 +86,7 @@ expr *new_linear(expr *u, const CSR_Matrix *A, const double *b) /* Allocate the type-specific struct */ linear_op_expr *lin_node = (linear_op_expr *) calloc(1, sizeof(linear_op_expr)); expr *node = &lin_node->base; - init_expr(node, A->m, 1, u->n_vars, forward, jacobian_init, eval_jacobian, + init_expr(node, A->m, 1, u->n_vars, forward, jacobian_init_impl, eval_jacobian, is_affine, NULL, NULL, free_type_data); node->left = u; expr_retain(u); diff --git a/src/affine/neg.c b/src/affine/neg.c index 316d65d2..2c86267f 100644 --- a/src/affine/neg.c +++ b/src/affine/neg.c @@ -32,11 +32,11 @@ static void forward(expr *node, const double *u) } } -static void jacobian_init(expr *node) +static void jacobian_init_impl(expr *node) { expr *x = node->left; /* initialize child's jacobian */ - x->jacobian_init(x); + jacobian_init(x); /* same sparsity pattern as child */ node->jacobian = new_csr_copy_sparsity(x->jacobian); @@ -47,7 +47,7 @@ static void eval_jacobian(expr *node) /* evaluate child's jacobian */ node->left->eval_jacobian(node->left); - /* negate values only (sparsity pattern set in jacobian_init) */ + /* negate values only (sparsity pattern set in jacobian_init_impl) */ CSR_Matrix *child_jac = node->left->jacobian; for (int k = 0; k < child_jac->nnz; k++) { @@ -55,12 +55,12 @@ static void eval_jacobian(expr *node) } } -static void wsum_hess_init(expr *node) +static void wsum_hess_init_impl(expr *node) { expr *x = node->left; /* initialize child's wsum_hess */ - x->wsum_hess_init(x); + wsum_hess_init(x); /* same sparsity pattern as child */ CSR_Matrix *child_hess = x->wsum_hess; @@ -72,7 +72,7 @@ static void eval_wsum_hess(expr *node, const double *w) /* For f(x) = -g(x): d²f/dx² = -d²g/dx² */ node->left->eval_wsum_hess(node->left, w); - /* negate values (sparsity pattern set in wsum_hess_init) */ + /* negate values (sparsity pattern set in wsum_hess_init_impl) */ CSR_Matrix *child_hess = node->left->wsum_hess; for (int k = 0; k < child_hess->nnz; k++) { @@ -88,8 +88,8 @@ static bool is_affine(const expr *node) expr *new_neg(expr *child) { expr *node = (expr *) calloc(1, sizeof(expr)); - init_expr(node, child->d1, child->d2, child->n_vars, forward, jacobian_init, - eval_jacobian, is_affine, wsum_hess_init, eval_wsum_hess, NULL); + init_expr(node, child->d1, child->d2, child->n_vars, forward, jacobian_init_impl, + eval_jacobian, is_affine, wsum_hess_init_impl, eval_wsum_hess, NULL); node->left = child; expr_retain(child); diff --git a/src/affine/promote.c b/src/affine/promote.c index a244746d..57c73c19 100644 --- a/src/affine/promote.c +++ b/src/affine/promote.c @@ -34,10 +34,10 @@ static void forward(expr *node, const double *u) } } -static void jacobian_init(expr *node) +static void jacobian_init_impl(expr *node) { expr *x = node->left; - x->jacobian_init(x); + jacobian_init(x); /* each output row copies the single row from child's jacobian */ int nnz = node->size * x->jacobian->nnz; @@ -72,9 +72,9 @@ static void eval_jacobian(expr *node) } } -static void wsum_hess_init(expr *node) +static void wsum_hess_init_impl(expr *node) { - node->left->wsum_hess_init(node->left); + wsum_hess_init(node->left); /* same sparsity as child since we're summing weights */ CSR_Matrix *child_hess = node->left->wsum_hess; @@ -107,8 +107,8 @@ expr *new_promote(expr *child, int d1, int d2) { assert(child->size == 1); expr *node = (expr *) calloc(1, sizeof(expr)); - init_expr(node, d1, d2, child->n_vars, forward, jacobian_init, eval_jacobian, - is_affine, wsum_hess_init, eval_wsum_hess, NULL); + init_expr(node, d1, d2, child->n_vars, forward, jacobian_init_impl, eval_jacobian, + is_affine, wsum_hess_init_impl, eval_wsum_hess, NULL); node->left = child; expr_retain(child); diff --git a/src/affine/reshape.c b/src/affine/reshape.c index 26b6b9f0..deb72fc8 100644 --- a/src/affine/reshape.c +++ b/src/affine/reshape.c @@ -31,10 +31,10 @@ static void forward(expr *node, const double *u) memcpy(node->value, node->left->value, node->size * sizeof(double)); } -static void jacobian_init(expr *node) +static void jacobian_init_impl(expr *node) { expr *x = node->left; - x->jacobian_init(x); + jacobian_init(x); node->jacobian = new_csr_copy_sparsity(x->jacobian); } @@ -45,10 +45,10 @@ static void eval_jacobian(expr *node) memcpy(node->jacobian->x, x->jacobian->x, x->jacobian->nnz * sizeof(double)); } -static void wsum_hess_init(expr *node) +static void wsum_hess_init_impl(expr *node) { expr *x = node->left; - x->wsum_hess_init(x); + wsum_hess_init(x); node->wsum_hess = new_csr_copy_sparsity(x->wsum_hess); } @@ -68,8 +68,8 @@ expr *new_reshape(expr *child, int d1, int d2) { assert(d1 * d2 == child->size); expr *node = (expr *) calloc(1, sizeof(expr)); - init_expr(node, d1, d2, child->n_vars, forward, jacobian_init, eval_jacobian, - is_affine, wsum_hess_init, eval_wsum_hess, NULL); + init_expr(node, d1, d2, child->n_vars, forward, jacobian_init_impl, eval_jacobian, + is_affine, wsum_hess_init_impl, eval_wsum_hess, NULL); node->left = child; expr_retain(child); diff --git a/src/affine/sum.c b/src/affine/sum.c index 258b1b76..346075e3 100644 --- a/src/affine/sum.c +++ b/src/affine/sum.c @@ -77,14 +77,14 @@ static void forward(expr *node, const double *u) } } -static void jacobian_init(expr *node) +static void jacobian_init_impl(expr *node) { expr *x = node->left; sum_expr *snode = (sum_expr *) node; int axis = snode->axis; /* initialize child's jacobian */ - x->jacobian_init(x); + jacobian_init(x); /* we never have to store more than the child's nnz */ node->jacobian = new_csr_matrix(node->size, node->n_vars, x->jacobian->nnz); @@ -129,11 +129,11 @@ static void eval_jacobian(expr *node) node->jacobian->x); } -static void wsum_hess_init(expr *node) +static void wsum_hess_init_impl(expr *node) { expr *x = node->left; /* initialize child's wsum_hess */ - x->wsum_hess_init(x); + wsum_hess_init(x); /* we never have to store more than the child's nnz */ node->wsum_hess = new_csr_copy_sparsity(x->wsum_hess); @@ -202,8 +202,8 @@ expr *new_sum(expr *child, int axis) /* to be consistent with CVXPY and NumPy we treat the result from sum with an axis argument as a row vector */ - init_expr(node, 1, d2, child->n_vars, forward, jacobian_init, eval_jacobian, - is_affine, wsum_hess_init, eval_wsum_hess, free_type_data); + init_expr(node, 1, d2, child->n_vars, forward, jacobian_init_impl, eval_jacobian, + is_affine, wsum_hess_init_impl, eval_wsum_hess, free_type_data); node->left = child; expr_retain(child); diff --git a/src/affine/trace.c b/src/affine/trace.c index 289dc317..f68bc480 100644 --- a/src/affine/trace.c +++ b/src/affine/trace.c @@ -43,13 +43,13 @@ static void forward(expr *node, const double *u) node->value[0] = sum; } -static void jacobian_init(expr *node) +static void jacobian_init_impl(expr *node) { expr *x = node->left; assert(x->d1 == x->d2); /* initialize child's jacobian */ - x->jacobian_init(x); + jacobian_init(x); // --------------------------------------------------------------- // count total nnz and allocate matrix with sufficient space @@ -96,12 +96,12 @@ static void eval_jacobian(expr *node) } /* Placeholders for Hessian-related functions */ -static void wsum_hess_init(expr *node) +static void wsum_hess_init_impl(expr *node) { expr *x = node->left; /* initialize child's hessian */ - x->wsum_hess_init(x); + wsum_hess_init(x); node->work->dwork = (double *) calloc(x->size, sizeof(double)); @@ -145,8 +145,8 @@ expr *new_trace(expr *child) { trace_expr *tnode = (trace_expr *) calloc(1, sizeof(trace_expr)); expr *node = &tnode->base; - init_expr(node, 1, 1, child->n_vars, forward, jacobian_init, eval_jacobian, - is_affine, wsum_hess_init, eval_wsum_hess, free_type_data); + init_expr(node, 1, 1, child->n_vars, forward, jacobian_init_impl, eval_jacobian, + is_affine, wsum_hess_init_impl, eval_wsum_hess, free_type_data); node->left = child; expr_retain(child); diff --git a/src/affine/transpose.c b/src/affine/transpose.c index 66e9036b..67e53339 100644 --- a/src/affine/transpose.c +++ b/src/affine/transpose.c @@ -40,10 +40,10 @@ static void forward(expr *node, const double *u) } } -static void jacobian_init(expr *node) +static void jacobian_init_impl(expr *node) { expr *child = node->left; - child->jacobian_init(child); + jacobian_init(child); CSR_Matrix *Jc = child->jacobian; node->jacobian = new_csr_matrix(node->size, node->n_vars, Jc->nnz); @@ -85,11 +85,11 @@ static void eval_jacobian(expr *node) } } -static void wsum_hess_init(expr *node) +static void wsum_hess_init_impl(expr *node) { /* initialize child */ expr *x = node->left; - x->wsum_hess_init(x); + wsum_hess_init(x); /* same sparsity pattern as child */ node->wsum_hess = new_csr_copy_sparsity(x->wsum_hess); @@ -127,8 +127,8 @@ static bool is_affine(const expr *node) expr *new_transpose(expr *child) { expr *node = (expr *) calloc(1, sizeof(expr)); - init_expr(node, child->d2, child->d1, child->n_vars, forward, jacobian_init, - eval_jacobian, is_affine, wsum_hess_init, eval_wsum_hess, NULL); + init_expr(node, child->d2, child->d1, child->n_vars, forward, jacobian_init_impl, + eval_jacobian, is_affine, wsum_hess_init_impl, eval_wsum_hess, NULL); node->left = child; expr_retain(child); diff --git a/src/affine/variable.c b/src/affine/variable.c index 1a6c7d0d..e1103543 100644 --- a/src/affine/variable.c +++ b/src/affine/variable.c @@ -24,7 +24,7 @@ static void forward(expr *node, const double *u) memcpy(node->value, u + node->var_id, node->d1 * node->d2 * sizeof(double)); } -static void jacobian_init(expr *node) +static void jacobian_init_impl(expr *node) { node->jacobian = new_csr_matrix(node->size, node->n_vars, node->size); for (int j = 0; j < node->size; j++) @@ -42,7 +42,7 @@ static void eval_jacobian(expr *node) (void) node; } -static void wsum_hess_init(expr *node) +static void wsum_hess_init_impl(expr *node) { /* Variables have zero Hessian */ node->wsum_hess = new_csr_matrix(node->n_vars, node->n_vars, 0); @@ -64,8 +64,8 @@ static bool is_affine(const expr *node) expr *new_variable(int d1, int d2, int var_id, int n_vars) { expr *node = (expr *) calloc(1, sizeof(expr)); - init_expr(node, d1, d2, n_vars, forward, jacobian_init, eval_jacobian, is_affine, - wsum_hess_init, wsum_hess_eval, NULL); + init_expr(node, d1, d2, n_vars, forward, jacobian_init_impl, eval_jacobian, is_affine, + wsum_hess_init_impl, wsum_hess_eval, NULL); node->var_id = var_id; return node; diff --git a/src/bivariate_full_dom/matmul.c b/src/bivariate_full_dom/matmul.c index 2e408d41..68939b4a 100644 --- a/src/bivariate_full_dom/matmul.c +++ b/src/bivariate_full_dom/matmul.c @@ -48,7 +48,7 @@ static bool is_affine(const expr *node) return false; } -static void jacobian_init(expr *node) +static void jacobian_init_impl(expr *node) { expr *x = node->left; expr *y = node->right; @@ -146,7 +146,7 @@ static void eval_jacobian(expr *node) } } -static void wsum_hess_init(expr *node) +static void wsum_hess_init_impl(expr *node) { expr *x = node->left; expr *y = node->right; @@ -330,8 +330,8 @@ expr *new_matmul(expr *x, expr *y) expr *node = (expr *) calloc(1, sizeof(expr)); /* Initialize with d1 = x->d1, d2 = y->d2 (result is m x n) */ - init_expr(node, x->d1, y->d2, x->n_vars, forward, jacobian_init, eval_jacobian, - is_affine, wsum_hess_init, eval_wsum_hess, NULL); + init_expr(node, x->d1, y->d2, x->n_vars, forward, jacobian_init_impl, eval_jacobian, + is_affine, wsum_hess_init_impl, eval_wsum_hess, NULL); /* Set children */ node->left = x; diff --git a/src/bivariate_full_dom/multiply.c b/src/bivariate_full_dom/multiply.c index a20ed5d9..4e38f87d 100644 --- a/src/bivariate_full_dom/multiply.c +++ b/src/bivariate_full_dom/multiply.c @@ -45,10 +45,10 @@ static void forward(expr *node, const double *u) } } -static void jacobian_init(expr *node) +static void jacobian_init_impl(expr *node) { - node->left->jacobian_init(node->left); - node->right->jacobian_init(node->right); + jacobian_init(node->left); + jacobian_init(node->right); node->work->dwork = (double *) malloc(2 * node->size * sizeof(double)); int nnz_max = node->left->jacobian->nnz + node->right->jacobian->nnz; node->jacobian = new_csr_matrix(node->size, node->n_vars, nnz_max); @@ -71,7 +71,7 @@ static void eval_jacobian(expr *node) y->value, x->value); } -static void wsum_hess_init(expr *node) +static void wsum_hess_init_impl(expr *node) { expr *x = node->left; expr *y = node->right; @@ -217,8 +217,8 @@ expr *new_elementwise_mult(expr *left, expr *right) (elementwise_mult_expr *) calloc(1, sizeof(elementwise_mult_expr)); expr *node = &mul_node->base; - init_expr(node, left->d1, left->d2, left->n_vars, forward, jacobian_init, - eval_jacobian, is_affine, wsum_hess_init, eval_wsum_hess, + init_expr(node, left->d1, left->d2, left->n_vars, forward, jacobian_init_impl, + eval_jacobian, is_affine, wsum_hess_init_impl, eval_wsum_hess, free_type_data); node->left = left; node->right = right; diff --git a/src/bivariate_restricted_dom/quad_over_lin.c b/src/bivariate_restricted_dom/quad_over_lin.c index 69868208..28b6e9ae 100644 --- a/src/bivariate_restricted_dom/quad_over_lin.c +++ b/src/bivariate_restricted_dom/quad_over_lin.c @@ -49,7 +49,7 @@ static void forward(expr *node, const double *u) node->value[0] /= y->value[0]; } -static void jacobian_init(expr *node) +static void jacobian_init_impl(expr *node) { expr *x = node->left; expr *y = node->right; @@ -169,7 +169,7 @@ static void eval_jacobian(expr *node) } } -static void wsum_hess_init(expr *node) +static void wsum_hess_init_impl(expr *node) { expr *x = node->left; expr *y = node->right; @@ -332,8 +332,8 @@ expr *new_quad_over_lin(expr *left, expr *right) } expr *node = (expr *) calloc(1, sizeof(expr)); - init_expr(node, 1, 1, left->n_vars, forward, jacobian_init, eval_jacobian, - is_affine, wsum_hess_init, eval_wsum_hess, NULL); + init_expr(node, 1, 1, left->n_vars, forward, jacobian_init_impl, eval_jacobian, + is_affine, wsum_hess_init_impl, eval_wsum_hess, NULL); node->left = left; node->right = right; expr_retain(left); diff --git a/src/elementwise_full_dom/common.c b/src/elementwise_full_dom/common.c index f676718c..59c43c5a 100644 --- a/src/elementwise_full_dom/common.c +++ b/src/elementwise_full_dom/common.c @@ -25,7 +25,7 @@ void jacobian_init_elementwise(expr *node) else { /* jacobian of h(x) = f(g(x)) is Jf @ Jg, and here Jf is diagonal */ - child->jacobian_init(child); + jacobian_init(child); CSR_Matrix *Jg = child->jacobian; node->jacobian = new_csr_copy_sparsity(Jg); node->work->dwork = (double *) malloc(node->size * sizeof(double)); @@ -95,7 +95,7 @@ void wsum_hess_init_elementwise(expr *node) node->work->hess_term1 = ATA_alloc(Jg); /* term2: child's Hessian */ - child->wsum_hess_init(child); + wsum_hess_init(child); CSR_Matrix *Hg = child->wsum_hess; node->work->hess_term2 = new_csr_copy_sparsity(Hg); diff --git a/src/expr.c b/src/expr.c index fbd3b60d..fccffebd 100644 --- a/src/expr.c +++ b/src/expr.c @@ -34,10 +34,10 @@ void init_expr(expr *node, int d1, int d2, int n_vars, forward_fn forward, node->value = (double *) calloc(d1 * d2, sizeof(double)); node->var_id = NOT_A_VARIABLE; node->forward = forward; - node->jacobian_init = jacobian_init; + node->jacobian_init_impl = jacobian_init; node->eval_jacobian = eval_jacobian; node->is_affine = is_affine; - node->wsum_hess_init = wsum_hess_init; + node->wsum_hess_init_impl = wsum_hess_init; node->eval_wsum_hess = eval_wsum_hess; node->free_type_data = free_type_data; node->work = (Expr_Work *) calloc(1, sizeof(Expr_Work)); @@ -91,6 +91,18 @@ void free_expr(expr *node) free(node); } +void jacobian_init(expr *node) +{ + if (node == NULL || node->jacobian != NULL) return; + node->jacobian_init_impl(node); +} + +void wsum_hess_init(expr *node) +{ + if (node == NULL || node->wsum_hess != NULL) return; + node->wsum_hess_init_impl(node); +} + void expr_retain(expr *node) { if (node == NULL) return; diff --git a/src/other/prod.c b/src/other/prod.c index 0dfbfbd9..31428af2 100644 --- a/src/other/prod.c +++ b/src/other/prod.c @@ -43,12 +43,12 @@ static void forward(expr *node, const double *u) pnode->prod_nonzero = prod_nonzero; } -static void jacobian_init(expr *node) +static void jacobian_init_impl(expr *node) { expr *x = node->left; /* initialize child's jacobian */ - x->jacobian_init(x); + jacobian_init(x); /* if x is a variable */ if (x->var_id != NOT_A_VARIABLE) @@ -103,7 +103,7 @@ static void eval_jacobian(expr *node) } } -static void wsum_hess_init(expr *node) +static void wsum_hess_init_impl(expr *node) { expr *x = node->left; @@ -197,8 +197,8 @@ expr *new_prod(expr *child) /* Output is scalar: 1 x 1 */ prod_expr *pnode = (prod_expr *) calloc(1, sizeof(prod_expr)); expr *node = &pnode->base; - init_expr(node, 1, 1, child->n_vars, forward, jacobian_init, eval_jacobian, - is_affine, wsum_hess_init, eval_wsum_hess, free_type_data); + init_expr(node, 1, 1, child->n_vars, forward, jacobian_init_impl, eval_jacobian, + is_affine, wsum_hess_init_impl, eval_wsum_hess, free_type_data); node->left = child; expr_retain(child); return node; diff --git a/src/other/prod_axis_one.c b/src/other/prod_axis_one.c index cd432299..03edaf88 100644 --- a/src/other/prod_axis_one.c +++ b/src/other/prod_axis_one.c @@ -53,12 +53,12 @@ static void forward(expr *node, const double *u) } } -static void jacobian_init(expr *node) +static void jacobian_init_impl(expr *node) { expr *x = node->left; /* initialize child's jacobian */ - x->jacobian_init(x); + jacobian_init(x); /* if x is a variable */ if (x->var_id != NOT_A_VARIABLE) @@ -133,7 +133,7 @@ static void eval_jacobian(expr *node) } } -static void wsum_hess_init(expr *node) +static void wsum_hess_init_impl(expr *node) { expr *x = node->left; @@ -382,8 +382,8 @@ expr *new_prod_axis_one(expr *child) expr *node = &pnode->base; /* output is always a row vector 1 x d1 (one product per row) */ - init_expr(node, 1, child->d1, child->n_vars, forward, jacobian_init, - eval_jacobian, is_affine, wsum_hess_init, eval_wsum_hess, + init_expr(node, 1, child->d1, child->n_vars, forward, jacobian_init_impl, + eval_jacobian, is_affine, wsum_hess_init_impl, eval_wsum_hess, free_type_data); /* allocate arrays to store per-row statistics */ diff --git a/src/other/prod_axis_zero.c b/src/other/prod_axis_zero.c index ad85b6ee..198bdba2 100644 --- a/src/other/prod_axis_zero.c +++ b/src/other/prod_axis_zero.c @@ -48,12 +48,12 @@ static void forward(expr *node, const double *u) } } -static void jacobian_init(expr *node) +static void jacobian_init_impl(expr *node) { expr *x = node->left; /* initialize child's jacobian */ - x->jacobian_init(x); + jacobian_init(x); /* if x is a variable */ if (x->var_id != NOT_A_VARIABLE) @@ -127,7 +127,7 @@ static void eval_jacobian(expr *node) } } -static void wsum_hess_init(expr *node) +static void wsum_hess_init_impl(expr *node) { expr *x = node->left; @@ -342,8 +342,8 @@ expr *new_prod_axis_zero(expr *child) expr *node = &pnode->base; /* output is always a row vector 1 x d2 - TODO: is that correct? */ - init_expr(node, 1, child->d2, child->n_vars, forward, jacobian_init, - eval_jacobian, is_affine, wsum_hess_init, eval_wsum_hess, + init_expr(node, 1, child->d2, child->n_vars, forward, jacobian_init_impl, + eval_jacobian, is_affine, wsum_hess_init_impl, eval_wsum_hess, free_type_data); /* allocate arrays to store per-column statistics */ diff --git a/src/other/quad_form.c b/src/other/quad_form.c index 9c26f693..509d5d8d 100644 --- a/src/other/quad_form.c +++ b/src/other/quad_form.c @@ -25,7 +25,7 @@ static void forward(expr *node, const double *u) } } -static void jacobian_init(expr *node) +static void jacobian_init_impl(expr *node) { assert(node->left->var_id != NOT_A_VARIABLE); @@ -55,7 +55,7 @@ static void eval_jacobian(expr *node) } } -static void wsum_hess_init(expr *node) +static void wsum_hess_init_impl(expr *node) { CSR_Matrix *Q = ((quad_form_expr *) node)->Q; expr *x = node->left; @@ -94,7 +94,7 @@ The following two functions are commented out. It supports the jacobian for quad_form(Ax, Q), but after reconsideration, I think we should treat this as quad_form(x, A.TQA) in the canonicalization so we don't need to support the chain rule here. -static void jacobian_init(expr *node) +static void jacobian_init_impl(expr *node) { expr *x = node->left; node->work->dwork = (double *) malloc(x->d1 * sizeof(double)); @@ -189,8 +189,8 @@ expr *new_quad_form(expr *left, CSR_Matrix *Q) quad_form_expr *qnode = (quad_form_expr *) calloc(1, sizeof(quad_form_expr)); expr *node = &qnode->base; - init_expr(node, 1, 1, left->n_vars, forward, jacobian_init, eval_jacobian, - is_affine, wsum_hess_init, eval_wsum_hess, free_type_data); + init_expr(node, 1, 1, left->n_vars, forward, jacobian_init_impl, eval_jacobian, + is_affine, wsum_hess_init_impl, eval_wsum_hess, free_type_data); node->left = left; expr_retain(left); diff --git a/src/problem.c b/src/problem.c index 6dbd1a62..406f7343 100644 --- a/src/problem.c +++ b/src/problem.c @@ -164,12 +164,12 @@ void problem_init_jacobian(problem *prob) // ------------------------------------------------------------------------------- // Jacobian structure // ------------------------------------------------------------------------------- - prob->objective->jacobian_init(prob->objective); + jacobian_init(prob->objective); int nnz = 0; for (int i = 0; i < prob->n_constraints; i++) { expr *c = prob->constraints[i]; - c->jacobian_init(c); + jacobian_init(c); nnz += c->jacobian->nnz; if (c->is_affine(c)) @@ -216,12 +216,12 @@ void problem_init_hessian(problem *prob) // ------------------------------------------------------------------------------- // Lagrange Hessian structure // ------------------------------------------------------------------------------- - prob->objective->wsum_hess_init(prob->objective); + wsum_hess_init(prob->objective); int nnz = prob->objective->wsum_hess->nnz; for (int i = 0; i < prob->n_constraints; i++) { - prob->constraints[i]->wsum_hess_init(prob->constraints[i]); + wsum_hess_init(prob->constraints[i]); nnz += prob->constraints[i]->wsum_hess->nnz; } diff --git a/tests/jacobian_tests/affine/test_broadcast.h b/tests/jacobian_tests/affine/test_broadcast.h index e6ffa4f5..a66e761b 100644 --- a/tests/jacobian_tests/affine/test_broadcast.h +++ b/tests/jacobian_tests/affine/test_broadcast.h @@ -29,7 +29,7 @@ const char *test_broadcast_row_jacobian(void) expr *var = new_variable(1, 3, 0, 3); expr *bcast = new_broadcast(var, 2, 3); bcast->forward(bcast, u); - bcast->jacobian_init(bcast); + jacobian_init(bcast); bcast->eval_jacobian(bcast); /* Each variable affects 2 elements (m times) */ @@ -74,7 +74,7 @@ const char *test_broadcast_col_jacobian(void) expr *var = new_variable(3, 1, 0, 3); expr *bcast = new_broadcast(var, 3, 2); bcast->forward(bcast, u); - bcast->jacobian_init(bcast); + jacobian_init(bcast); bcast->eval_jacobian(bcast); /* Each variable affects 2 elements (n times) */ @@ -115,7 +115,7 @@ const char *test_broadcast_scalar_to_matrix_jacobian(void) expr *var = new_variable(1, 1, 0, 1); expr *bcast = new_broadcast(var, 2, 3); bcast->forward(bcast, u); - bcast->jacobian_init(bcast); + jacobian_init(bcast); bcast->eval_jacobian(bcast); /* All 6 elements depend on the single input variable */ @@ -147,7 +147,7 @@ const char *test_double_broadcast(void) expr *sum = new_add(bcast_x, bcast_b); sum->forward(sum, x_vals); - sum->jacobian_init(sum); + jacobian_init(sum); sum->eval_jacobian(sum); /* All 6 elements depend on the single input variable */ diff --git a/tests/jacobian_tests/affine/test_const_scalar_mult.h b/tests/jacobian_tests/affine/test_const_scalar_mult.h index 879e9e36..b459e77c 100644 --- a/tests/jacobian_tests/affine/test_const_scalar_mult.h +++ b/tests/jacobian_tests/affine/test_const_scalar_mult.h @@ -26,7 +26,7 @@ const char *test_jacobian_const_scalar_mult_log_vector(void) y->forward(y, u_vals); /* Initialize and evaluate jacobian */ - y->jacobian_init(y); + jacobian_init(y); y->eval_jacobian(y); /* Expected jacobian: 2.5 * [1/1, 1/2, 1/4] = [2.5, 1.25, 0.625] */ @@ -62,7 +62,7 @@ const char *test_jacobian_const_scalar_mult_log_matrix(void) y->forward(y, u_vals); /* Initialize and evaluate jacobian */ - y->jacobian_init(y); + jacobian_init(y); y->eval_jacobian(y); /* Expected jacobian: 3.0 * [1/1, 1/2, 1/4, 1/8] = [3.0, 1.5, 0.75, 0.375] */ diff --git a/tests/jacobian_tests/affine/test_const_vector_mult.h b/tests/jacobian_tests/affine/test_const_vector_mult.h index 9b00dca2..45ca3fd4 100644 --- a/tests/jacobian_tests/affine/test_const_vector_mult.h +++ b/tests/jacobian_tests/affine/test_const_vector_mult.h @@ -26,7 +26,7 @@ const char *test_jacobian_const_vector_mult_log_vector(void) y->forward(y, u_vals); /* Initialize and evaluate jacobian */ - y->jacobian_init(y); + jacobian_init(y); y->eval_jacobian(y); /* Expected jacobian (row-wise scaling): @@ -66,7 +66,7 @@ const char *test_jacobian_const_vector_mult_log_matrix(void) y->forward(y, u_vals); /* Initialize and evaluate jacobian */ - y->jacobian_init(y); + jacobian_init(y); y->eval_jacobian(y); /* Expected jacobian (row-wise scaling): diff --git a/tests/jacobian_tests/affine/test_hstack.h b/tests/jacobian_tests/affine/test_hstack.h index b730cd5c..17bafe24 100644 --- a/tests/jacobian_tests/affine/test_hstack.h +++ b/tests/jacobian_tests/affine/test_hstack.h @@ -31,7 +31,7 @@ const char *test_jacobian_hstack_vectors(void) expr *stack = new_hstack(args, 3, 3); stack->forward(stack, u); - stack->jacobian_init(stack); + jacobian_init(stack); stack->eval_jacobian(stack); /* Expected jacobian: 9x3 with 9 nonzeros (diagonal blocks) */ @@ -73,7 +73,7 @@ const char *test_jacobian_hstack_matrix(void) expr *stack = new_hstack(args, 3, 6); stack->forward(stack, u); - stack->jacobian_init(stack); + jacobian_init(stack); stack->eval_jacobian(stack); /* Expected jacobian: 18x6 with 18 nonzeros (diagonal) */ diff --git a/tests/jacobian_tests/affine/test_index.h b/tests/jacobian_tests/affine/test_index.h index f1e7aa4d..943fd0a1 100644 --- a/tests/jacobian_tests/affine/test_index.h +++ b/tests/jacobian_tests/affine/test_index.h @@ -50,7 +50,7 @@ const char *test_index_jacobian_of_variable(void) expr *var = new_variable(3, 1, 0, 3); expr *idx = new_index(var, 1, 2, indices, 2); idx->forward(idx, u); - idx->jacobian_init(idx); + jacobian_init(idx); idx->eval_jacobian(idx); /* Jacobian is 2x3 with pattern: row 0 selects col 0, row 1 selects col 2 */ @@ -75,7 +75,7 @@ const char *test_index_jacobian_of_log(void) expr *log_node = new_log(var); expr *idx = new_index(log_node, 1, 2, indices, 2); idx->forward(idx, u); - idx->jacobian_init(idx); + jacobian_init(idx); idx->eval_jacobian(idx); /* d/dx log(x) = diag(1/x), then select rows 0 and 2 @@ -101,7 +101,7 @@ const char *test_index_jacobian_repeated(void) expr *var = new_variable(3, 1, 0, 3); expr *idx = new_index(var, 1, 2, indices, 2); idx->forward(idx, u); - idx->jacobian_init(idx); + jacobian_init(idx); idx->eval_jacobian(idx); /* Both rows select column 0 */ @@ -132,7 +132,7 @@ const char *test_sum_of_index(void) expr *s = new_sum(idx, -1); /* sum all */ s->forward(s, u); - s->jacobian_init(s); + jacobian_init(s); s->eval_jacobian(s); /* Gradient: [1, 0, 1] in sparse form */ diff --git a/tests/jacobian_tests/affine/test_left_matmul.h b/tests/jacobian_tests/affine/test_left_matmul.h index 5accf1ba..270a2be2 100644 --- a/tests/jacobian_tests/affine/test_left_matmul.h +++ b/tests/jacobian_tests/affine/test_left_matmul.h @@ -45,7 +45,7 @@ const char *test_jacobian_left_matmul_log(void) expr *A_log_x = new_left_matmul(log_x, A); A_log_x->forward(A_log_x, x_vals); - A_log_x->jacobian_init(A_log_x); + jacobian_init(A_log_x); A_log_x->eval_jacobian(A_log_x); /* Expected jacobian values: A @ diag(1/x) */ @@ -89,7 +89,7 @@ const char *test_jacobian_left_matmul_log_matrix(void) expr *A_log_x = new_left_matmul(log_x, A); A_log_x->forward(A_log_x, x_vals); - A_log_x->jacobian_init(A_log_x); + jacobian_init(A_log_x); A_log_x->eval_jacobian(A_log_x); /* Expected Jacobian: block-diagonal repeat of A scaled by diag(1./x) */ diff --git a/tests/jacobian_tests/affine/test_neg.h b/tests/jacobian_tests/affine/test_neg.h index f5377dce..1c0de551 100644 --- a/tests/jacobian_tests/affine/test_neg.h +++ b/tests/jacobian_tests/affine/test_neg.h @@ -11,7 +11,7 @@ const char *test_neg_jacobian(void) expr *var = new_variable(3, 1, 0, 3); expr *neg_node = new_neg(var); neg_node->forward(neg_node, u); - neg_node->jacobian_init(neg_node); + jacobian_init(neg_node); neg_node->eval_jacobian(neg_node); /* Jacobian of neg(x) is -I (diagonal with -1) */ @@ -42,7 +42,7 @@ const char *test_neg_chain(void) /* neg(neg(x)) should equal x */ mu_assert("neg chain forward failed", cmp_double_array(neg2->value, u, 3)); - neg2->jacobian_init(neg2); + jacobian_init(neg2); neg2->eval_jacobian(neg2); /* Jacobian of neg(neg(x)) is (-1)*(-1)*I = I */ diff --git a/tests/jacobian_tests/affine/test_promote.h b/tests/jacobian_tests/affine/test_promote.h index 978d31bc..30dc7552 100644 --- a/tests/jacobian_tests/affine/test_promote.h +++ b/tests/jacobian_tests/affine/test_promote.h @@ -14,7 +14,7 @@ const char *test_promote_scalar_jacobian(void) expr *var = new_variable(1, 1, 0, 1); expr *promote_node = new_promote(var, 3, 1); promote_node->forward(promote_node, u); - promote_node->jacobian_init(promote_node); + jacobian_init(promote_node); promote_node->eval_jacobian(promote_node); /* Jacobian is 3x1 with all 1s (each output depends on same input) */ @@ -46,7 +46,7 @@ const char *test_promote_scalar_to_matrix_jacobian(void) mu_assert("promote scalar->matrix forward failed", cmp_double_array(promote_node->value, expected_val, 6)); - promote_node->jacobian_init(promote_node); + jacobian_init(promote_node); promote_node->eval_jacobian(promote_node); /* Jacobian is 6x1 with all 1s (each output depends on same scalar input) */ diff --git a/tests/jacobian_tests/affine/test_right_matmul.h b/tests/jacobian_tests/affine/test_right_matmul.h index 7aed736b..e3af6655 100644 --- a/tests/jacobian_tests/affine/test_right_matmul.h +++ b/tests/jacobian_tests/affine/test_right_matmul.h @@ -30,7 +30,7 @@ const char *test_jacobian_right_matmul_log(void) expr *log_x_A = new_right_matmul(log_x, A); log_x_A->forward(log_x_A, x_vals); - log_x_A->jacobian_init(log_x_A); + jacobian_init(log_x_A); log_x_A->eval_jacobian(log_x_A); /* Expected jacobian values */ @@ -79,7 +79,7 @@ const char *test_jacobian_right_matmul_log_vector(void) expr *log_x_A = new_right_matmul(log_x, A); log_x_A->forward(log_x_A, x_vals); - log_x_A->jacobian_init(log_x_A); + jacobian_init(log_x_A); log_x_A->eval_jacobian(log_x_A); /* Expected jacobian values: A^T @ diag(1/x) */ diff --git a/tests/jacobian_tests/affine/test_sum.h b/tests/jacobian_tests/affine/test_sum.h index 90a289c8..607c874b 100644 --- a/tests/jacobian_tests/affine/test_sum.h +++ b/tests/jacobian_tests/affine/test_sum.h @@ -19,7 +19,7 @@ const char *test_jacobian_sum_log(void) expr *log_node = new_log(x); expr *sum_node = new_sum(log_node, -1); sum_node->forward(sum_node, u_vals); - sum_node->jacobian_init(sum_node); + jacobian_init(sum_node); sum_node->eval_jacobian(sum_node); double expected_Ax[3] = {1.0, 0.5, 1.0 / 3.0}; int expected_Ap[2] = {0, 3}; @@ -52,7 +52,7 @@ const char *test_jacobian_sum_mult(void) expr *sum_node = new_sum(mult_node, -1); sum_node->forward(sum_node, u_vals); - sum_node->jacobian_init(sum_node); + jacobian_init(sum_node); sum_node->eval_jacobian(sum_node); double expected_Ax[6] = {2, 3, 4, 1, 2, 3}; @@ -92,7 +92,7 @@ const char *test_jacobian_sum_log_axis_0(void) expr *log_node = new_log(x); expr *sum_node = new_sum(log_node, 0); sum_node->forward(sum_node, u_vals); - sum_node->jacobian_init(sum_node); + jacobian_init(sum_node); sum_node->eval_jacobian(sum_node); double expected_Ax[6] = {1.0, 1.0 / 3.0, 1.0 / 5.0, 0.5, 0.25, 1.0 / 6.0}; @@ -134,7 +134,7 @@ const char *test_jacobian_sum_add_log_axis_0(void) expr *sum_node = new_sum(add_node, 0); sum_node->forward(sum_node, u_vals); - sum_node->jacobian_init(sum_node); + jacobian_init(sum_node); sum_node->eval_jacobian(sum_node); /* Expected jacobian values for both rows */ @@ -181,7 +181,7 @@ const char *test_jacobian_sum_log_axis_1(void) expr *log_node = new_log(x); expr *sum_node = new_sum(log_node, 1); sum_node->forward(sum_node, u_vals); - sum_node->jacobian_init(sum_node); + jacobian_init(sum_node); sum_node->eval_jacobian(sum_node); double expected_Ax[6] = {1.0, 0.5, 1.0 / 3.0, 0.25, 1.0 / 5.0, 1.0 / 6.0}; diff --git a/tests/jacobian_tests/affine/test_trace.h b/tests/jacobian_tests/affine/test_trace.h index a985c22e..df0c53f8 100644 --- a/tests/jacobian_tests/affine/test_trace.h +++ b/tests/jacobian_tests/affine/test_trace.h @@ -32,7 +32,7 @@ const char *test_jacobian_trace_variable(void) expr *trace_node = new_trace(x); trace_node->forward(trace_node, u_vals); - trace_node->jacobian_init(trace_node); + jacobian_init(trace_node); trace_node->eval_jacobian(trace_node); double expected_Ax[3] = {1.0, 1.0, 1.0}; @@ -77,7 +77,7 @@ const char *test_jacobian_trace_composite(void) expr *add_node = new_add(log_node, exp_node); expr *trace_node = new_trace(add_node); - trace_node->jacobian_init(trace_node); + jacobian_init(trace_node); trace_node->forward(trace_node, u_vals); trace_node->eval_jacobian(trace_node); diff --git a/tests/jacobian_tests/affine/test_transpose.h b/tests/jacobian_tests/affine/test_transpose.h index 96ae6b27..4cf6e7e9 100644 --- a/tests/jacobian_tests/affine/test_transpose.h +++ b/tests/jacobian_tests/affine/test_transpose.h @@ -25,7 +25,7 @@ const char *test_jacobian_transpose(void) expr *transpose_AX = new_transpose(AX); double u[4] = {1, 3, 2, 4}; transpose_AX->forward(transpose_AX, u); - transpose_AX->jacobian_init(transpose_AX); + jacobian_init(transpose_AX); transpose_AX->eval_jacobian(transpose_AX); // Jacobian of transpose_AX diff --git a/tests/jacobian_tests/affine/test_vstack.h b/tests/jacobian_tests/affine/test_vstack.h index e126ff26..ca42d691 100644 --- a/tests/jacobian_tests/affine/test_vstack.h +++ b/tests/jacobian_tests/affine/test_vstack.h @@ -31,7 +31,7 @@ const char *test_jacobian_vstack_vectors(void) expr *stack = new_vstack(args, 2, 3); stack->forward(stack, u); - stack->jacobian_init(stack); + jacobian_init(stack); stack->eval_jacobian(stack); double expected_x[6] = {1.0, 0.5, 1.0 / 3.0, exp(1.0), exp(2.0), exp(3.0)}; @@ -80,7 +80,7 @@ const char *test_jacobian_vstack_matrix(void) expr *stack = new_vstack(args, 2, 9); stack->forward(stack, u); - stack->jacobian_init(stack); + jacobian_init(stack); stack->eval_jacobian(stack); double expected_x[9] = {1.0, 0.5, exp(7.0), 1.0 / 3.0, 0.25, diff --git a/tests/jacobian_tests/bivariate_full_dom/test_elementwise_mult.h b/tests/jacobian_tests/bivariate_full_dom/test_elementwise_mult.h index 631b99c7..ce66d013 100644 --- a/tests/jacobian_tests/bivariate_full_dom/test_elementwise_mult.h +++ b/tests/jacobian_tests/bivariate_full_dom/test_elementwise_mult.h @@ -16,7 +16,7 @@ const char *test_jacobian_elementwise_mult_1(void) expr *node = new_elementwise_mult(x, y); node->forward(node, u_vals); - node->jacobian_init(node); + jacobian_init(node); node->eval_jacobian(node); double vals[6] = {y->value[0], x->value[0], y->value[1], @@ -41,7 +41,7 @@ const char *test_jacobian_elementwise_mult_2(void) expr *node = new_elementwise_mult(x, y); node->forward(node, u_vals); - node->jacobian_init(node); + jacobian_init(node); node->eval_jacobian(node); double vals[6] = {x->value[0], y->value[0], x->value[1], @@ -96,7 +96,7 @@ const char *test_jacobian_elementwise_mult_3(void) expr *node = new_elementwise_mult(Ax, By); node->forward(node, u_vals); - node->jacobian_init(node); + jacobian_init(node); node->eval_jacobian(node); /* Correct answer: @@ -145,7 +145,7 @@ const char *test_jacobian_elementwise_mult_4(void) expr *node = new_elementwise_mult(Ax, Ax); node->forward(node, u_vals); - node->jacobian_init(node); + jacobian_init(node); node->eval_jacobian(node); /* Correct answer: 0 0 10 20 0 0 0 0 0 0 diff --git a/tests/jacobian_tests/bivariate_full_dom/test_matmul.h b/tests/jacobian_tests/bivariate_full_dom/test_matmul.h index ff0b8ca9..48babbdb 100644 --- a/tests/jacobian_tests/bivariate_full_dom/test_matmul.h +++ b/tests/jacobian_tests/bivariate_full_dom/test_matmul.h @@ -45,7 +45,7 @@ const char *test_jacobian_matmul(void) /* Forward pass and jacobian initialization */ Z->forward(Z, u_vals); - Z->jacobian_init(Z); + jacobian_init(Z); Z->eval_jacobian(Z); /* Verify sparsity pattern */ diff --git a/tests/jacobian_tests/bivariate_restricted_dom/test_quad_over_lin.h b/tests/jacobian_tests/bivariate_restricted_dom/test_quad_over_lin.h index c50ee500..1a05a7e4 100644 --- a/tests/jacobian_tests/bivariate_restricted_dom/test_quad_over_lin.h +++ b/tests/jacobian_tests/bivariate_restricted_dom/test_quad_over_lin.h @@ -18,7 +18,7 @@ const char *test_quad_over_lin1(void) expr *node = new_quad_over_lin(x, y); node->forward(node, u_vals); - node->jacobian_init(node); + jacobian_init(node); node->eval_jacobian(node); double expected_Ax[4] = {2.0 / 4.0, 4.0 / 4.0, 6.0 / 4.0, -14.0 / 16.0}; @@ -42,7 +42,7 @@ const char *test_quad_over_lin2(void) expr *node = new_quad_over_lin(x, y); node->forward(node, u_vals); - node->jacobian_init(node); + jacobian_init(node); node->eval_jacobian(node); double expected_Ax[4] = {-14.0 / 16.0, 2.0 / 4.0, 4.0 / 4.0, 6.0 / 4.0}; @@ -79,7 +79,7 @@ const char *test_quad_over_lin3(void) double u_vals[8] = {0, 0, 1.0, 2.0, 3.0, 0, 0, 4.0}; node->forward(node, u_vals); - node->jacobian_init(node); + jacobian_init(node); node->eval_jacobian(node); double expected_vals[4] = {71.0, 94.0, 117.0, -76.25}; @@ -119,7 +119,7 @@ const char *test_quad_over_lin4(void) double u_vals[8] = {0, 0, 4, 0, 0, 1.0, 2.0, 3.0}; node->forward(node, u_vals); - node->jacobian_init(node); + jacobian_init(node); node->eval_jacobian(node); double expected_vals[4] = {-76.25, 71.0, 94.0, 117.0}; @@ -159,7 +159,7 @@ const char *test_quad_over_lin5(void) double u_vals[8] = {1, 2, 4, 3, 2, 1.0, 2.0, 3.0}; node->forward(node, u_vals); - node->jacobian_init(node); + jacobian_init(node); node->eval_jacobian(node); double expected_vals[7] = {12, 36, -117, 36, 84, 114, 144}; diff --git a/tests/jacobian_tests/bivariate_restricted_dom/test_rel_entr.h b/tests/jacobian_tests/bivariate_restricted_dom/test_rel_entr.h index f11954c8..89726e98 100644 --- a/tests/jacobian_tests/bivariate_restricted_dom/test_rel_entr.h +++ b/tests/jacobian_tests/bivariate_restricted_dom/test_rel_entr.h @@ -16,7 +16,7 @@ const char *test_jacobian_rel_entr_vector_args_1(void) expr *node = new_rel_entr_vector_args(x, y); node->forward(node, u_vals); - node->jacobian_init(node); + jacobian_init(node); node->eval_jacobian(node); double a = log(1.0 / 4.0) + 1.0; @@ -47,7 +47,7 @@ const char *test_jacobian_rel_entr_vector_args_2(void) expr *node = new_rel_entr_vector_args(x, y); node->forward(node, u_vals); - node->jacobian_init(node); + jacobian_init(node); node->eval_jacobian(node); double a = log(1.0 / 4.0) + 1.0; @@ -81,7 +81,7 @@ const char *test_jacobian_rel_entr_matrix_args(void) expr *node = new_rel_entr_vector_args(x, y); node->forward(node, u_vals); - node->jacobian_init(node); + jacobian_init(node); node->eval_jacobian(node); double dx0 = log(1.0 / 6.0) + 1.0; diff --git a/tests/jacobian_tests/bivariate_restricted_dom/test_rel_entr_scalar_vector.h b/tests/jacobian_tests/bivariate_restricted_dom/test_rel_entr_scalar_vector.h index fd74fc17..0a6f734f 100644 --- a/tests/jacobian_tests/bivariate_restricted_dom/test_rel_entr_scalar_vector.h +++ b/tests/jacobian_tests/bivariate_restricted_dom/test_rel_entr_scalar_vector.h @@ -14,7 +14,7 @@ const char *test_jacobian_rel_entr_scalar_vector(void) expr *node = new_rel_entr_first_arg_scalar(x, y); node->forward(node, u_vals); - node->jacobian_init(node); + jacobian_init(node); node->eval_jacobian(node); double a = log(1.0 / 1.0) + 1.0; diff --git a/tests/jacobian_tests/bivariate_restricted_dom/test_rel_entr_vector_scalar.h b/tests/jacobian_tests/bivariate_restricted_dom/test_rel_entr_vector_scalar.h index 871208c1..02d19b4a 100644 --- a/tests/jacobian_tests/bivariate_restricted_dom/test_rel_entr_vector_scalar.h +++ b/tests/jacobian_tests/bivariate_restricted_dom/test_rel_entr_vector_scalar.h @@ -14,7 +14,7 @@ const char *test_jacobian_rel_entr_vector_scalar(void) expr *node = new_rel_entr_second_arg_scalar(x, y); node->forward(node, u_vals); - node->jacobian_init(node); + jacobian_init(node); node->eval_jacobian(node); double a = log(1.0 / 4.0) + 1.0; diff --git a/tests/jacobian_tests/composite/test_composite_exp.h b/tests/jacobian_tests/composite/test_composite_exp.h index 6161df3e..98cf2d9b 100644 --- a/tests/jacobian_tests/composite/test_composite_exp.h +++ b/tests/jacobian_tests/composite/test_composite_exp.h @@ -22,7 +22,7 @@ const char *test_jacobian_composite_exp(void) expr *u = new_variable(3, 1, 2, 6); expr *Au = new_linear(u, A, NULL); expr *exp_node = new_exp(Au); - exp_node->jacobian_init(exp_node); + jacobian_init(exp_node); exp_node->forward(exp_node, u_vals); exp_node->eval_jacobian(exp_node); diff --git a/tests/jacobian_tests/elementwise_restricted_dom/test_log.h b/tests/jacobian_tests/elementwise_restricted_dom/test_log.h index 1cae74bb..2378bbce 100644 --- a/tests/jacobian_tests/elementwise_restricted_dom/test_log.h +++ b/tests/jacobian_tests/elementwise_restricted_dom/test_log.h @@ -16,7 +16,7 @@ const char *test_jacobian_log(void) expr *u = new_variable(3, 1, 2, 5); expr *log_node = new_log(u); log_node->forward(log_node, u_vals); - log_node->jacobian_init(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, 3)); mu_assert("rows fail", cmp_int_array(log_node->jacobian->p, expected_Ap, 4)); @@ -34,7 +34,7 @@ const char *test_jacobian_log_matrix(void) 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); + 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)); diff --git a/tests/jacobian_tests/other/test_prod.h b/tests/jacobian_tests/other/test_prod.h index 95e8d86c..87900b02 100644 --- a/tests/jacobian_tests/other/test_prod.h +++ b/tests/jacobian_tests/other/test_prod.h @@ -18,7 +18,7 @@ const char *test_jacobian_prod_no_zero(void) expr *p = new_prod(x); p->forward(p, u_vals); - p->jacobian_init(p); + jacobian_init(p); p->eval_jacobian(p); double expected_Ax[4] = {24.0, 12.0, 8.0, 6.0}; @@ -43,7 +43,7 @@ const char *test_jacobian_prod_one_zero(void) expr *p = new_prod(x); p->forward(p, u_vals); - p->jacobian_init(p); + jacobian_init(p); p->eval_jacobian(p); double expected_Ax[4] = {0.0, 12.0, 0.0, 0.0}; @@ -66,7 +66,7 @@ const char *test_jacobian_prod_two_zeros(void) expr *p = new_prod(x); p->forward(p, u_vals); - p->jacobian_init(p); + jacobian_init(p); p->eval_jacobian(p); double expected_Ax[4] = {0.0, 0.0, 0.0, 0.0}; diff --git a/tests/jacobian_tests/other/test_prod_axis_one.h b/tests/jacobian_tests/other/test_prod_axis_one.h index 116e1100..564920af 100644 --- a/tests/jacobian_tests/other/test_prod_axis_one.h +++ b/tests/jacobian_tests/other/test_prod_axis_one.h @@ -34,7 +34,7 @@ const char *test_jacobian_prod_axis_one(void) expr *p = new_prod_axis_one(x); p->forward(p, u_vals); - p->jacobian_init(p); + jacobian_init(p); p->eval_jacobian(p); /* CSR format for 3x10 Jacobian with row-strided structure */ @@ -77,7 +77,7 @@ const char *test_jacobian_prod_axis_one_one_zero(void) expr *p = new_prod_axis_one(x); p->forward(p, u_vals); - p->jacobian_init(p); + jacobian_init(p); p->eval_jacobian(p); /* CSR format for 3x10 Jacobian with row-strided structure */ diff --git a/tests/jacobian_tests/other/test_prod_axis_zero.h b/tests/jacobian_tests/other/test_prod_axis_zero.h index f9a89582..952713b2 100644 --- a/tests/jacobian_tests/other/test_prod_axis_zero.h +++ b/tests/jacobian_tests/other/test_prod_axis_zero.h @@ -28,7 +28,7 @@ const char *test_jacobian_prod_axis_zero(void) expr *p = new_prod_axis_zero(x); p->forward(p, u_vals); - p->jacobian_init(p); + jacobian_init(p); p->eval_jacobian(p); /* CSR format for 3x8 Jacobian with block diagonal structure */ diff --git a/tests/jacobian_tests/other/test_quad_form.h b/tests/jacobian_tests/other/test_quad_form.h index 8f0e9d4a..b72c443e 100644 --- a/tests/jacobian_tests/other/test_quad_form.h +++ b/tests/jacobian_tests/other/test_quad_form.h @@ -23,7 +23,7 @@ const char *test_quad_form(void) memcpy(Q->p, Qp, 4 * sizeof(int)); expr *node = new_quad_form(x, Q); - node->jacobian_init(node); + jacobian_init(node); node->forward(node, u_vals); node->eval_jacobian(node); @@ -69,7 +69,7 @@ memcpy(A->p, Ap, 4 * sizeof(int)); expr *Au = new_linear(u, A, NULL); expr *node = new_quad_form(Au, Q); -node->jacobian_init(node); +jacobian_init(node); node->forward(node, u_vals); node->eval_jacobian(node); diff --git a/tests/numerical_diff.c b/tests/numerical_diff.c index 304918f7..e018998d 100644 --- a/tests/numerical_diff.c +++ b/tests/numerical_diff.c @@ -66,7 +66,7 @@ int check_jacobian(expr *node, const double *u, double h) int m = node->size; int n = node->n_vars; - node->jacobian_init(node); + jacobian_init(node); node->forward(node, u); node->eval_jacobian(node); @@ -117,7 +117,7 @@ double *numerical_wsum_hess(expr *node, const double *u, const double *w, double double inv_2h = 1.0 / (2.0 * h); /* Initialize jacobian sparsity once, then forward */ - node->jacobian_init(node); + jacobian_init(node); node->forward(node, u); double *H = calloc((size_t) n * n, sizeof(double)); @@ -165,7 +165,7 @@ int check_wsum_hess(expr *node, const double *u, const double *w, double h) double *H_num = numerical_wsum_hess(node, u, w, h); /* Now compute analytical (reuses jacobian from numerical) */ - node->wsum_hess_init(node); + wsum_hess_init(node); node->forward(node, u); node->eval_jacobian(node); node->eval_wsum_hess(node, w); diff --git a/tests/profiling/profile_left_matmul.h b/tests/profiling/profile_left_matmul.h index 331734b3..5ff98bef 100644 --- a/tests/profiling/profile_left_matmul.h +++ b/tests/profiling/profile_left_matmul.h @@ -45,7 +45,7 @@ const char *profile_left_matmul(void) clock_gettime(CLOCK_MONOTONIC, &timer.end); printf("left_matmul forward time: %8.3f seconds\n", GET_ELAPSED_SECONDS(timer)); clock_gettime(CLOCK_MONOTONIC, &timer.start); - AX->jacobian_init(AX); + jacobian_init(AX); clock_gettime(CLOCK_MONOTONIC, &timer.end); printf("left_matmul jacobian init time: %8.3f seconds\n", GET_ELAPSED_SECONDS(timer)); diff --git a/tests/wsum_hess/affine/test_broadcast.h b/tests/wsum_hess/affine/test_broadcast.h index 38c8b408..3b1a0bfa 100644 --- a/tests/wsum_hess/affine/test_broadcast.h +++ b/tests/wsum_hess/affine/test_broadcast.h @@ -31,8 +31,8 @@ const char *test_wsum_hess_broadcast_row(void) expr *bcast = new_broadcast(log_node, 2, 3); bcast->forward(bcast, x); - bcast->jacobian_init(bcast); - bcast->wsum_hess_init(bcast); + jacobian_init(bcast); + wsum_hess_init(bcast); /* Weights for the 2x3 output (columnwise): * w = [1.0, 0.5, 2.0, 1.0, 0.25, 0.125] @@ -86,8 +86,8 @@ const char *test_wsum_hess_broadcast_col(void) expr *bcast = new_broadcast(log_node, 3, 2); bcast->forward(bcast, x); - bcast->jacobian_init(bcast); - bcast->wsum_hess_init(bcast); + jacobian_init(bcast); + wsum_hess_init(bcast); /* Weights for the 3x2 output (columnwise): * w = [1.0, 0.5, 0.25, 2.0, 1.0, 0.5] @@ -140,8 +140,8 @@ const char *test_wsum_hess_broadcast_scalar_to_matrix(void) expr *bcast = new_broadcast(log_node, 2, 3); bcast->forward(bcast, x); - bcast->jacobian_init(bcast); - bcast->wsum_hess_init(bcast); + jacobian_init(bcast); + wsum_hess_init(bcast); /* Weights for the 2x3 output (columnwise): * w = [1.0, 0.5, 2.0, 1.0, 0.25, 0.125] diff --git a/tests/wsum_hess/affine/test_const_scalar_mult.h b/tests/wsum_hess/affine/test_const_scalar_mult.h index 3a110583..31fb6a6f 100644 --- a/tests/wsum_hess/affine/test_const_scalar_mult.h +++ b/tests/wsum_hess/affine/test_const_scalar_mult.h @@ -27,7 +27,7 @@ const char *test_wsum_hess_const_scalar_mult_log_vector(void) y->forward(y, u_vals); /* Initialize and evaluate weighted Hessian with w = [1.0, 0.5, 0.25] */ - y->wsum_hess_init(y); + wsum_hess_init(y); double w[3] = {1.0, 0.5, 0.25}; y->eval_wsum_hess(y, w); @@ -72,7 +72,7 @@ const char *test_wsum_hess_const_scalar_mult_log_matrix(void) y->forward(y, u_vals); /* Initialize and evaluate weighted Hessian with w = [1.0, 1.0, 1.0, 1.0] */ - y->wsum_hess_init(y); + wsum_hess_init(y); double w[4] = {1.0, 1.0, 1.0, 1.0}; y->eval_wsum_hess(y, w); diff --git a/tests/wsum_hess/affine/test_const_vector_mult.h b/tests/wsum_hess/affine/test_const_vector_mult.h index 9d389853..0e02a4f9 100644 --- a/tests/wsum_hess/affine/test_const_vector_mult.h +++ b/tests/wsum_hess/affine/test_const_vector_mult.h @@ -27,7 +27,7 @@ const char *test_wsum_hess_const_vector_mult_log_vector(void) y->forward(y, u_vals); /* Initialize and evaluate weighted Hessian with w = [1.0, 0.5, 0.25] */ - y->wsum_hess_init(y); + wsum_hess_init(y); double w[3] = {1.0, 0.5, 0.25}; y->eval_wsum_hess(y, w); @@ -70,7 +70,7 @@ const char *test_wsum_hess_const_vector_mult_log_matrix(void) y->forward(y, u_vals); /* Initialize and evaluate weighted Hessian with w = [1.0, 1.0, 1.0, 1.0] */ - y->wsum_hess_init(y); + wsum_hess_init(y); double w[4] = {1.0, 1.0, 1.0, 1.0}; y->eval_wsum_hess(y, w); diff --git a/tests/wsum_hess/affine/test_hstack.h b/tests/wsum_hess/affine/test_hstack.h index 229b720e..1ff662df 100644 --- a/tests/wsum_hess/affine/test_hstack.h +++ b/tests/wsum_hess/affine/test_hstack.h @@ -36,8 +36,8 @@ const char *test_wsum_hess_hstack(void) expr *hstack_node = new_hstack(args, 4, 9); hstack_node->forward(hstack_node, u_vals); - hstack_node->jacobian_init(hstack_node); - hstack_node->wsum_hess_init(hstack_node); + jacobian_init(hstack_node); + wsum_hess_init(hstack_node); hstack_node->eval_wsum_hess(hstack_node, w); /* Expected Hessian: @@ -135,7 +135,7 @@ const char *test_wsum_hess_hstack_matrix(void) expr *hstack_node = new_hstack(args, 4, 18); hstack_node->forward(hstack_node, u_vals); - hstack_node->wsum_hess_init(hstack_node); + wsum_hess_init(hstack_node); hstack_node->eval_wsum_hess(hstack_node, w); /* Expected Hessian (diagonal): diff --git a/tests/wsum_hess/affine/test_index.h b/tests/wsum_hess/affine/test_index.h index a292d80e..9423f12f 100644 --- a/tests/wsum_hess/affine/test_index.h +++ b/tests/wsum_hess/affine/test_index.h @@ -27,8 +27,8 @@ const char *test_wsum_hess_index_log(void) expr *idx = new_index(log_node, 1, 2, indices, 2); idx->forward(idx, u); - idx->jacobian_init(idx); - idx->wsum_hess_init(idx); + jacobian_init(idx); + wsum_hess_init(idx); idx->eval_wsum_hess(idx, w); /* Expected diagonal values: @@ -61,8 +61,8 @@ const char *test_wsum_hess_index_repeated(void) expr *idx = new_index(log_node, 1, 2, indices, 2); idx->forward(idx, u); - idx->jacobian_init(idx); - idx->wsum_hess_init(idx); + jacobian_init(idx); + wsum_hess_init(idx); idx->eval_wsum_hess(idx, w); /* Hessian of log at x=2 is -1/4 @@ -99,8 +99,8 @@ const char *test_wsum_hess_sum_index_log(void) expr *sum_node = new_sum(idx, -1); sum_node->forward(sum_node, u); - sum_node->jacobian_init(sum_node); - sum_node->wsum_hess_init(sum_node); + jacobian_init(sum_node); + wsum_hess_init(sum_node); sum_node->eval_wsum_hess(sum_node, &w); /* Expected diagonal values: diff --git a/tests/wsum_hess/affine/test_left_matmul.h b/tests/wsum_hess/affine/test_left_matmul.h index 39cf4655..3ccaff18 100644 --- a/tests/wsum_hess/affine/test_left_matmul.h +++ b/tests/wsum_hess/affine/test_left_matmul.h @@ -66,8 +66,8 @@ const char *test_wsum_hess_left_matmul(void) expr *A_log_x = new_left_matmul(log_x, A); A_log_x->forward(A_log_x, x_vals); - A_log_x->jacobian_init(A_log_x); - A_log_x->wsum_hess_init(A_log_x); + jacobian_init(A_log_x); + wsum_hess_init(A_log_x); A_log_x->eval_wsum_hess(A_log_x, w); /* Expected wsum_hess: diagonal matrix with all 3 entries @@ -173,8 +173,8 @@ const char *test_wsum_hess_left_matmul_matrix(void) expr *A_log_x = new_left_matmul(log_x, A); A_log_x->forward(A_log_x, x_vals); - A_log_x->jacobian_init(A_log_x); - A_log_x->wsum_hess_init(A_log_x); + jacobian_init(A_log_x); + wsum_hess_init(A_log_x); A_log_x->eval_wsum_hess(A_log_x, w); /* Expected wsum_hess: 6x6 diagonal matrix with all 6 entries */ diff --git a/tests/wsum_hess/affine/test_right_matmul.h b/tests/wsum_hess/affine/test_right_matmul.h index b560f13a..e697b588 100644 --- a/tests/wsum_hess/affine/test_right_matmul.h +++ b/tests/wsum_hess/affine/test_right_matmul.h @@ -36,8 +36,8 @@ const char *test_wsum_hess_right_matmul(void) expr *log_x_A = new_right_matmul(log_x, A); log_x_A->forward(log_x_A, x_vals); - log_x_A->jacobian_init(log_x_A); - log_x_A->wsum_hess_init(log_x_A); + jacobian_init(log_x_A); + wsum_hess_init(log_x_A); log_x_A->eval_wsum_hess(log_x_A, w); /* Expected wsum_hess: diagonal matrix with 4 entries */ @@ -86,8 +86,8 @@ const char *test_wsum_hess_right_matmul_vector(void) expr *log_x_A = new_right_matmul(log_x, A); log_x_A->forward(log_x_A, x_vals); - log_x_A->jacobian_init(log_x_A); - log_x_A->wsum_hess_init(log_x_A); + jacobian_init(log_x_A); + wsum_hess_init(log_x_A); log_x_A->eval_wsum_hess(log_x_A, w); /* Expected wsum_hess: diagonal matrix with 3 entries */ diff --git a/tests/wsum_hess/affine/test_sum.h b/tests/wsum_hess/affine/test_sum.h index fdc2de94..0ef1455c 100644 --- a/tests/wsum_hess/affine/test_sum.h +++ b/tests/wsum_hess/affine/test_sum.h @@ -52,8 +52,8 @@ const char *test_wsum_hess_sum_log_axis0(void) expr *sum_node = new_sum(log_node, 0); sum_node->forward(sum_node, x); - sum_node->jacobian_init(sum_node); - sum_node->wsum_hess_init(sum_node); + jacobian_init(sum_node); + wsum_hess_init(sum_node); sum_node->eval_wsum_hess(sum_node, w); /* Expected diagonal values */ @@ -90,8 +90,8 @@ const char *test_wsum_hess_sum_log_axis1(void) expr *sum_node = new_sum(log_node, 1); sum_node->forward(sum_node, x); - sum_node->jacobian_init(sum_node); - sum_node->wsum_hess_init(sum_node); + jacobian_init(sum_node); + wsum_hess_init(sum_node); sum_node->eval_wsum_hess(sum_node, w); /* Expected diagonal values */ diff --git a/tests/wsum_hess/affine/test_trace.h b/tests/wsum_hess/affine/test_trace.h index a71d30aa..ad0b693b 100644 --- a/tests/wsum_hess/affine/test_trace.h +++ b/tests/wsum_hess/affine/test_trace.h @@ -30,8 +30,8 @@ const char *test_wsum_hess_trace_variable(void) expr *trace_node = new_trace(x); trace_node->forward(trace_node, u_vals); - trace_node->jacobian_init(trace_node); - trace_node->wsum_hess_init(trace_node); + jacobian_init(trace_node); + wsum_hess_init(trace_node); trace_node->eval_wsum_hess(trace_node, &w); /* For a linear operation (variable), Hessian is zero */ @@ -62,8 +62,8 @@ const char *test_wsum_hess_trace_log_variable(void) expr *trace_node = new_trace(log_node); trace_node->forward(trace_node, u_vals); - trace_node->jacobian_init(trace_node); - trace_node->wsum_hess_init(trace_node); + jacobian_init(trace_node); + wsum_hess_init(trace_node); trace_node->eval_wsum_hess(trace_node, &w); double expected_Ax[9] = {-2.0, 0, 0, 0, -0.08, 0, 0, 0, -0.024691358024691357}; @@ -111,8 +111,8 @@ const char *test_wsum_hess_trace_composite(void) expr *trace_node = new_trace(add_node); trace_node->forward(trace_node, u_vals); - trace_node->jacobian_init(trace_node); - trace_node->wsum_hess_init(trace_node); + jacobian_init(trace_node); + wsum_hess_init(trace_node); trace_node->eval_wsum_hess(trace_node, &w); /* Expected diagonal Hessian values at indices [1,1], [5,5], [9,9] diff --git a/tests/wsum_hess/affine/test_transpose.h b/tests/wsum_hess/affine/test_transpose.h index 2ff2fc4e..8f518bf7 100644 --- a/tests/wsum_hess/affine/test_transpose.h +++ b/tests/wsum_hess/affine/test_transpose.h @@ -18,7 +18,7 @@ const char *test_wsum_hess_transpose(void) double u[8] = {1, 3, 2, 4, 5, 7, 6, 8}; XYT->forward(XYT, u); - XYT->wsum_hess_init(XYT); + wsum_hess_init(XYT); double w[4] = {1, 2, 3, 4}; XYT->eval_wsum_hess(XYT, w); diff --git a/tests/wsum_hess/affine/test_vstack.h b/tests/wsum_hess/affine/test_vstack.h index 7f034f12..bb99d852 100644 --- a/tests/wsum_hess/affine/test_vstack.h +++ b/tests/wsum_hess/affine/test_vstack.h @@ -30,8 +30,8 @@ const char *test_wsum_hess_vstack_vectors(void) expr *stack = new_vstack(args, 2, 3); stack->forward(stack, u); - stack->jacobian_init(stack); - stack->wsum_hess_init(stack); + jacobian_init(stack); + wsum_hess_init(stack); stack->eval_wsum_hess(stack, w); double expected_x[3] = {-1.0 + 4.0 * exp(1.0), -0.5 + 5.0 * exp(2.0), @@ -86,8 +86,8 @@ const char *test_wsum_hess_vstack_matrix(void) expr *stack = new_vstack(args, 2, 9); stack->forward(stack, u); - stack->jacobian_init(stack); - stack->wsum_hess_init(stack); + jacobian_init(stack); + wsum_hess_init(stack); stack->eval_wsum_hess(stack, w); double expected_x[9] = {-1.0, /* x0: w[0]*(-1/1) */ diff --git a/tests/wsum_hess/bivariate_full_dom/test_matmul.h b/tests/wsum_hess/bivariate_full_dom/test_matmul.h index d23cb953..c18396b9 100644 --- a/tests/wsum_hess/bivariate_full_dom/test_matmul.h +++ b/tests/wsum_hess/bivariate_full_dom/test_matmul.h @@ -44,7 +44,7 @@ const char *test_wsum_hess_matmul(void) /* Forward pass and Hessian initialization */ Z->forward(Z, u_vals); - Z->wsum_hess_init(Z); + wsum_hess_init(Z); Z->eval_wsum_hess(Z, w); /* Verify Hessian dimensions and sparsity */ @@ -144,7 +144,7 @@ const char *test_wsum_hess_matmul_yx(void) /* Forward pass and Hessian initialization */ Z->forward(Z, u_vals); - Z->wsum_hess_init(Z); + wsum_hess_init(Z); Z->eval_wsum_hess(Z, w); /* Verify Hessian dimensions and sparsity */ diff --git a/tests/wsum_hess/bivariate_full_dom/test_multiply.h b/tests/wsum_hess/bivariate_full_dom/test_multiply.h index 6aae97b4..4089502e 100644 --- a/tests/wsum_hess/bivariate_full_dom/test_multiply.h +++ b/tests/wsum_hess/bivariate_full_dom/test_multiply.h @@ -22,7 +22,7 @@ const char *test_wsum_hess_multiply_1(void) expr *node = new_elementwise_mult(x, y); node->forward(node, u_vals); - node->wsum_hess_init(node); + wsum_hess_init(node); node->eval_wsum_hess(node, w); int expected_p[13] = {0, 0, 0, 0, 1, 2, 3, 3, 3, 4, 5, 6, 6}; @@ -79,7 +79,7 @@ const char *test_wsum_hess_multiply_sparse_random(void) mult_node->forward(mult_node, u_vals); /* Initialize and evaluate Hessian */ - mult_node->wsum_hess_init(mult_node); + wsum_hess_init(mult_node); double w[5] = {0.50646339, 0.44756224, 0.67295241, 0.16424956, 0.03031469}; mult_node->eval_wsum_hess(mult_node, w); @@ -160,7 +160,7 @@ const char *test_wsum_hess_multiply_linear_ops(void) mult_node->forward(mult_node, u_vals); /* Initialize Hessian structure */ - mult_node->wsum_hess_init(mult_node); + wsum_hess_init(mult_node); /* Evaluate Hessian with weights */ double w[4] = {1.0, 2.0, 3.0, 4.0}; @@ -208,7 +208,7 @@ const char *test_wsum_hess_multiply_2(void) expr *node = new_elementwise_mult(x, y); node->forward(node, u_vals); - node->wsum_hess_init(node); + wsum_hess_init(node); node->eval_wsum_hess(node, w); int expected_p[13] = {0, 0, 0, 0, 1, 2, 3, 3, 3, 4, 5, 6, 6}; diff --git a/tests/wsum_hess/bivariate_restricted_dom/test_quad_over_lin.h b/tests/wsum_hess/bivariate_restricted_dom/test_quad_over_lin.h index e28a0a2d..04e39c99 100644 --- a/tests/wsum_hess/bivariate_restricted_dom/test_quad_over_lin.h +++ b/tests/wsum_hess/bivariate_restricted_dom/test_quad_over_lin.h @@ -17,7 +17,7 @@ const char *test_wsum_hess_quad_over_lin_xy(void) expr *node = new_quad_over_lin(x, y); node->forward(node, u_vals); - node->wsum_hess_init(node); + wsum_hess_init(node); node->eval_wsum_hess(node, &w); int expected_p[10] = {0, 0, 0, 2, 4, 6, 6, 6, 10, 10}; @@ -46,7 +46,7 @@ const char *test_wsum_hess_quad_over_lin_yx(void) expr *node = new_quad_over_lin(x, y); node->forward(node, u_vals); - node->wsum_hess_init(node); + wsum_hess_init(node); node->eval_wsum_hess(node, &w); int expected_p[10] = {0, 0, 0, 4, 4, 4, 6, 8, 10, 10}; diff --git a/tests/wsum_hess/bivariate_restricted_dom/test_rel_entr.h b/tests/wsum_hess/bivariate_restricted_dom/test_rel_entr.h index 4c7efeed..6a8a31f6 100644 --- a/tests/wsum_hess/bivariate_restricted_dom/test_rel_entr.h +++ b/tests/wsum_hess/bivariate_restricted_dom/test_rel_entr.h @@ -21,7 +21,7 @@ const char *test_wsum_hess_rel_entr_1(void) expr *node = new_rel_entr_vector_args(x, y); node->forward(node, u_vals); - node->wsum_hess_init(node); + wsum_hess_init(node); node->eval_wsum_hess(node, w); int expected_p[11] = {0, 0, 2, 4, 6, 6, 6, 8, 10, 12, 12}; @@ -52,7 +52,7 @@ const char *test_wsum_hess_rel_entr_2(void) expr *node = new_rel_entr_vector_args(x, y); node->forward(node, u_vals); - node->wsum_hess_init(node); + wsum_hess_init(node); node->eval_wsum_hess(node, w); int expected_p[11] = {0, 0, 2, 4, 6, 6, 6, 8, 10, 12, 12}; @@ -83,7 +83,7 @@ const char *test_wsum_hess_rel_entr_matrix(void) expr *node = new_rel_entr_vector_args(x, y); node->forward(node, u_vals); - node->wsum_hess_init(node); + wsum_hess_init(node); node->eval_wsum_hess(node, w); int expected_p[13] = {0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24}; diff --git a/tests/wsum_hess/bivariate_restricted_dom/test_rel_entr_scalar_vector.h b/tests/wsum_hess/bivariate_restricted_dom/test_rel_entr_scalar_vector.h index edf79bb0..2d0d59de 100644 --- a/tests/wsum_hess/bivariate_restricted_dom/test_rel_entr_scalar_vector.h +++ b/tests/wsum_hess/bivariate_restricted_dom/test_rel_entr_scalar_vector.h @@ -16,7 +16,7 @@ const char *test_wsum_hess_rel_entr_scalar_vector(void) expr *node = new_rel_entr_first_arg_scalar(x, y); node->forward(node, u_vals); - node->wsum_hess_init(node); + wsum_hess_init(node); node->eval_wsum_hess(node, w); int expected_p[5] = {0, 4, 6, 8, 10}; diff --git a/tests/wsum_hess/bivariate_restricted_dom/test_rel_entr_vector_scalar.h b/tests/wsum_hess/bivariate_restricted_dom/test_rel_entr_vector_scalar.h index b0583889..968e5d56 100644 --- a/tests/wsum_hess/bivariate_restricted_dom/test_rel_entr_vector_scalar.h +++ b/tests/wsum_hess/bivariate_restricted_dom/test_rel_entr_vector_scalar.h @@ -16,7 +16,7 @@ const char *test_wsum_hess_rel_entr_vector_scalar(void) expr *node = new_rel_entr_second_arg_scalar(x, y); node->forward(node, u_vals); - node->wsum_hess_init(node); + wsum_hess_init(node); node->eval_wsum_hess(node, w); int expected_p[5] = {0, 2, 4, 6, 10}; diff --git a/tests/wsum_hess/elementwise_full_dom/test_exp.h b/tests/wsum_hess/elementwise_full_dom/test_exp.h index 8dbc979c..848d7c04 100644 --- a/tests/wsum_hess/elementwise_full_dom/test_exp.h +++ b/tests/wsum_hess/elementwise_full_dom/test_exp.h @@ -18,7 +18,7 @@ const char *test_wsum_hess_exp(void) expr *x = new_variable(3, 1, 0, 3); expr *exp_node = new_exp(x); exp_node->forward(exp_node, u_vals); - exp_node->wsum_hess_init(exp_node); + wsum_hess_init(exp_node); exp_node->eval_wsum_hess(exp_node, w); /* Expected values on the diagonal: w_i * exp(x_i) */ diff --git a/tests/wsum_hess/elementwise_full_dom/test_hyperbolic.h b/tests/wsum_hess/elementwise_full_dom/test_hyperbolic.h index e9063d78..8a26ffc7 100644 --- a/tests/wsum_hess/elementwise_full_dom/test_hyperbolic.h +++ b/tests/wsum_hess/elementwise_full_dom/test_hyperbolic.h @@ -25,7 +25,7 @@ const char *test_wsum_hess_sinh(void) expr *x = new_variable(3, 1, 0, 3); expr *sinh_node = new_sinh(x); sinh_node->forward(sinh_node, u_vals); - sinh_node->wsum_hess_init(sinh_node); + wsum_hess_init(sinh_node); sinh_node->eval_wsum_hess(sinh_node, w); /* Expected values on the diagonal: w_i * sinh(x_i) */ @@ -60,7 +60,7 @@ const char *test_wsum_hess_tanh(void) expr *x = new_variable(3, 1, 0, 3); expr *tanh_node = new_tanh(x); tanh_node->forward(tanh_node, u_vals); - tanh_node->wsum_hess_init(tanh_node); + wsum_hess_init(tanh_node); tanh_node->eval_wsum_hess(tanh_node, w); /* Expected values on the diagonal: w_i * (-2*tanh(x_i)/cosh^2(x_i)) */ @@ -97,7 +97,7 @@ const char *test_wsum_hess_asinh(void) expr *x = new_variable(3, 1, 0, 3); expr *asinh_node = new_asinh(x); asinh_node->forward(asinh_node, u_vals); - asinh_node->wsum_hess_init(asinh_node); + wsum_hess_init(asinh_node); asinh_node->eval_wsum_hess(asinh_node, w); /* Expected values on the diagonal: w_i * (-x_i/(1+x_i^2)^(3/2)) */ @@ -135,7 +135,7 @@ const char *test_wsum_hess_atanh(void) expr *x = new_variable(3, 1, 0, 3); expr *atanh_node = new_atanh(x); atanh_node->forward(atanh_node, u_vals); - atanh_node->wsum_hess_init(atanh_node); + wsum_hess_init(atanh_node); atanh_node->eval_wsum_hess(atanh_node, w); /* Expected values on the diagonal: w_i * (2*x_i/(1-x_i^2)^2) */ diff --git a/tests/wsum_hess/elementwise_full_dom/test_logistic.h b/tests/wsum_hess/elementwise_full_dom/test_logistic.h index 8484ac57..67d2c8fc 100644 --- a/tests/wsum_hess/elementwise_full_dom/test_logistic.h +++ b/tests/wsum_hess/elementwise_full_dom/test_logistic.h @@ -26,9 +26,9 @@ const char *test_wsum_hess_logistic(void) expr *x = new_variable(3, 1, 0, 3); expr *logistic_node = new_logistic(x); logistic_node->forward(logistic_node, u_vals); - logistic_node->jacobian_init(logistic_node); + jacobian_init(logistic_node); logistic_node->eval_jacobian(logistic_node); - logistic_node->wsum_hess_init(logistic_node); + wsum_hess_init(logistic_node); logistic_node->eval_wsum_hess(logistic_node, w); /* Expected values on the diagonal: w_i * σ(x_i) * (1 - σ(x_i)) */ diff --git a/tests/wsum_hess/elementwise_full_dom/test_power.h b/tests/wsum_hess/elementwise_full_dom/test_power.h index 935ed97a..915c2246 100644 --- a/tests/wsum_hess/elementwise_full_dom/test_power.h +++ b/tests/wsum_hess/elementwise_full_dom/test_power.h @@ -18,7 +18,7 @@ const char *test_wsum_hess_power(void) expr *x = new_variable(3, 1, 0, 3); expr *power_node = new_power(x, 3.0); power_node->forward(power_node, u_vals); - power_node->wsum_hess_init(power_node); + wsum_hess_init(power_node); power_node->eval_wsum_hess(power_node, w); /* Expected values on the diagonal: w_i * 6 * x_i */ diff --git a/tests/wsum_hess/elementwise_full_dom/test_trig.h b/tests/wsum_hess/elementwise_full_dom/test_trig.h index aa239d55..3add1443 100644 --- a/tests/wsum_hess/elementwise_full_dom/test_trig.h +++ b/tests/wsum_hess/elementwise_full_dom/test_trig.h @@ -18,7 +18,7 @@ const char *test_wsum_hess_sin(void) expr *x = new_variable(3, 1, 0, 3); expr *sin_node = new_sin(x); sin_node->forward(sin_node, u_vals); - sin_node->wsum_hess_init(sin_node); + wsum_hess_init(sin_node); sin_node->eval_wsum_hess(sin_node, w); /* Expected values on the diagonal: -w_i * sin(x_i) */ @@ -46,7 +46,7 @@ const char *test_wsum_hess_cos(void) expr *x = new_variable(3, 1, 0, 3); expr *cos_node = new_cos(x); cos_node->forward(cos_node, u_vals); - cos_node->wsum_hess_init(cos_node); + wsum_hess_init(cos_node); cos_node->eval_wsum_hess(cos_node, w); /* Expected values on the diagonal: -w_i * cos(x_i) */ @@ -74,7 +74,7 @@ const char *test_wsum_hess_tan(void) expr *x = new_variable(3, 1, 0, 3); expr *tan_node = new_tan(x); tan_node->forward(tan_node, u_vals); - tan_node->wsum_hess_init(tan_node); + wsum_hess_init(tan_node); tan_node->eval_wsum_hess(tan_node, w); /* Expected values on the diagonal: w_i * 2 * sin(x_i) / cos^3(x_i) */ diff --git a/tests/wsum_hess/elementwise_full_dom/test_xexp.h b/tests/wsum_hess/elementwise_full_dom/test_xexp.h index 371d4660..4b6ad57a 100644 --- a/tests/wsum_hess/elementwise_full_dom/test_xexp.h +++ b/tests/wsum_hess/elementwise_full_dom/test_xexp.h @@ -18,7 +18,7 @@ const char *test_wsum_hess_xexp(void) expr *x = new_variable(3, 1, 0, 3); expr *xexp_node = new_xexp(x); xexp_node->forward(xexp_node, u_vals); - xexp_node->wsum_hess_init(xexp_node); + wsum_hess_init(xexp_node); xexp_node->eval_wsum_hess(xexp_node, w); /* Expected values on the diagonal: w_i * (2+x_i) * exp(x_i) */ diff --git a/tests/wsum_hess/elementwise_restricted_dom/test_entr.h b/tests/wsum_hess/elementwise_restricted_dom/test_entr.h index a6fc515b..75b92b91 100644 --- a/tests/wsum_hess/elementwise_restricted_dom/test_entr.h +++ b/tests/wsum_hess/elementwise_restricted_dom/test_entr.h @@ -18,7 +18,7 @@ const char *test_wsum_hess_entr(void) expr *x = new_variable(3, 1, 0, 3); expr *entr_node = new_entr(x); entr_node->forward(entr_node, u_vals); - entr_node->wsum_hess_init(entr_node); + wsum_hess_init(entr_node); entr_node->eval_wsum_hess(entr_node, w); /* Expected values on the diagonal: -w_i/x_i */ diff --git a/tests/wsum_hess/elementwise_restricted_dom/test_log.h b/tests/wsum_hess/elementwise_restricted_dom/test_log.h index caa5ed09..ef9c1e16 100644 --- a/tests/wsum_hess/elementwise_restricted_dom/test_log.h +++ b/tests/wsum_hess/elementwise_restricted_dom/test_log.h @@ -30,7 +30,7 @@ const char *test_wsum_hess_log(void) expr *x = new_variable(3, 1, 2, 7); expr *log_node = new_log(x); log_node->forward(log_node, u_vals); - log_node->wsum_hess_init(log_node); + wsum_hess_init(log_node); log_node->eval_wsum_hess(log_node, w); /* Expected values on the diagonal: -w_i/x_i^2 */ diff --git a/tests/wsum_hess/other/test_prod.h b/tests/wsum_hess/other/test_prod.h index 915edae7..6e8ff228 100644 --- a/tests/wsum_hess/other/test_prod.h +++ b/tests/wsum_hess/other/test_prod.h @@ -17,7 +17,7 @@ const char *test_wsum_hess_prod_no_zero(void) expr *p = new_prod(x); p->forward(p, u_vals); - p->wsum_hess_init(p); + wsum_hess_init(p); p->eval_wsum_hess(p, &w); /* Row-major over dense 4x4 block */ @@ -44,7 +44,7 @@ const char *test_wsum_hess_prod_one_zero(void) expr *p = new_prod(x); p->forward(p, u_vals); - p->wsum_hess_init(p); + wsum_hess_init(p); p->eval_wsum_hess(p, &w); double expected_x[16]; @@ -77,7 +77,7 @@ const char *test_wsum_hess_prod_two_zeros(void) expr *p = new_prod(x); p->forward(p, u_vals); - p->wsum_hess_init(p); + wsum_hess_init(p); p->eval_wsum_hess(p, &w); double expected_x[16]; @@ -105,7 +105,7 @@ const char *test_wsum_hess_prod_many_zeros(void) expr *p = new_prod(x); p->forward(p, u_vals); - p->wsum_hess_init(p); + wsum_hess_init(p); p->eval_wsum_hess(p, &w); double expected_x[16]; diff --git a/tests/wsum_hess/other/test_prod_axis_one.h b/tests/wsum_hess/other/test_prod_axis_one.h index eb94e79f..feb21347 100644 --- a/tests/wsum_hess/other/test_prod_axis_one.h +++ b/tests/wsum_hess/other/test_prod_axis_one.h @@ -30,7 +30,7 @@ const char *test_wsum_hess_prod_axis_one_no_zeros(void) expr *p = new_prod_axis_one(x); p->forward(p, u_vals); - p->wsum_hess_init(p); + wsum_hess_init(p); p->eval_wsum_hess(p, w_vals); double expected_x[12] = {/* Var 1 (row 0, col 0): [5, 3] (excludes col 0) */ @@ -97,7 +97,7 @@ const char *test_wsum_hess_prod_axis_one_one_zero(void) expr *p = new_prod_axis_one(x); p->forward(p, u_vals); - p->wsum_hess_init(p); + wsum_hess_init(p); p->eval_wsum_hess(p, w_vals); double expected_x[18]; @@ -200,7 +200,7 @@ const char *test_wsum_hess_prod_axis_one_mixed_zeros(void) expr *p = new_prod_axis_one(x); p->forward(p, u_vals); - p->wsum_hess_init(p); + wsum_hess_init(p); p->eval_wsum_hess(p, w_vals); double expected_x[30]; @@ -350,7 +350,7 @@ const char *test_wsum_hess_prod_axis_one_2x2(void) expr *p = new_prod_axis_one(x); p->forward(p, u_vals); - p->wsum_hess_init(p); + wsum_hess_init(p); p->eval_wsum_hess(p, w_vals); /* Expected sparse structure (nnz = 4, each row has 1 nnz) */ diff --git a/tests/wsum_hess/other/test_prod_axis_zero.h b/tests/wsum_hess/other/test_prod_axis_zero.h index 70eace12..3e6ccc5b 100644 --- a/tests/wsum_hess/other/test_prod_axis_zero.h +++ b/tests/wsum_hess/other/test_prod_axis_zero.h @@ -32,7 +32,7 @@ const char *test_wsum_hess_prod_axis_zero_no_zeros(void) expr *p = new_prod_axis_zero(x); p->forward(p, u_vals); - p->wsum_hess_init(p); + wsum_hess_init(p); p->eval_wsum_hess(p, w_vals); /* Block diagonal structure: 3 blocks of 2x2 = 6 nnz total @@ -107,7 +107,7 @@ const char *test_wsum_hess_prod_axis_zero_mixed_zeros(void) expr *p = new_prod_axis_zero(x); p->forward(p, u_vals); - p->wsum_hess_init(p); + wsum_hess_init(p); p->eval_wsum_hess(p, w_vals); /* Block 0: 5x5 all off-diagonal = 1.0, total = 25 entries (indices 0-24) @@ -209,7 +209,7 @@ const char *test_wsum_hess_prod_axis_zero_one_zero(void) expr *p = new_prod_axis_zero(x); p->forward(p, u_vals); - p->wsum_hess_init(p); + wsum_hess_init(p); p->eval_wsum_hess(p, w_vals); /* Block 0 (no zeros): w[0]*f[0] = 1 diff --git a/tests/wsum_hess/other/test_quad_form.h b/tests/wsum_hess/other/test_quad_form.h index 73426797..0f70792d 100644 --- a/tests/wsum_hess/other/test_quad_form.h +++ b/tests/wsum_hess/other/test_quad_form.h @@ -28,9 +28,9 @@ const char *test_wsum_hess_quad_form(void) expr *x = new_variable(4, 1, 3, 10); expr *node = new_quad_form(x, Q); - node->jacobian_init(node); + jacobian_init(node); node->forward(node, u_vals); - node->wsum_hess_init(node); + wsum_hess_init(node); node->eval_wsum_hess(node, &w); int expected_p[11] = {0, 0, 0, 0, 2, 5, 8, 10, 10, 10, 10}; From edd08d713bd82728a515d20c66045f69e6154cbb Mon Sep 17 00:00:00 2001 From: dance858 Date: Fri, 27 Mar 2026 08:28:18 -0700 Subject: [PATCH 5/5] run formatter --- src/affine/broadcast.c | 4 ++-- src/affine/constant.c | 4 ++-- src/affine/hstack.c | 5 +++-- src/affine/index.c | 5 +++-- src/affine/promote.c | 4 ++-- src/affine/reshape.c | 4 ++-- src/affine/variable.c | 4 ++-- src/bivariate_full_dom/matmul.c | 4 ++-- 8 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/affine/broadcast.c b/src/affine/broadcast.c index bec72989..cc7e6406 100644 --- a/src/affine/broadcast.c +++ b/src/affine/broadcast.c @@ -279,8 +279,8 @@ expr *new_broadcast(expr *child, int d1, int d2) // -------------------------------------------------------------------------- // initialize the rest of the expression // -------------------------------------------------------------------------- - init_expr(node, d1, d2, child->n_vars, forward, jacobian_init_impl, eval_jacobian, - is_affine, wsum_hess_init_impl, eval_wsum_hess, NULL); + init_expr(node, d1, d2, child->n_vars, forward, jacobian_init_impl, + eval_jacobian, is_affine, wsum_hess_init_impl, eval_wsum_hess, NULL); node->left = child; expr_retain(child); bcast->type = type; diff --git a/src/affine/constant.c b/src/affine/constant.c index 3e1c6b39..b2764f3a 100644 --- a/src/affine/constant.c +++ b/src/affine/constant.c @@ -61,8 +61,8 @@ static bool is_affine(const expr *node) expr *new_constant(int d1, int d2, int n_vars, const double *values) { expr *node = (expr *) calloc(1, sizeof(expr)); - init_expr(node, d1, d2, n_vars, forward, jacobian_init_impl, eval_jacobian, is_affine, - wsum_hess_init_impl, eval_wsum_hess, NULL); + init_expr(node, d1, d2, n_vars, forward, jacobian_init_impl, eval_jacobian, + is_affine, wsum_hess_init_impl, eval_wsum_hess, NULL); memcpy(node->value, values, node->size * sizeof(double)); return node; diff --git a/src/affine/hstack.c b/src/affine/hstack.c index 08c09546..86369690 100644 --- a/src/affine/hstack.c +++ b/src/affine/hstack.c @@ -187,8 +187,9 @@ expr *new_hstack(expr **args, int n_args, int n_vars) /* Allocate the type-specific struct */ hstack_expr *hnode = (hstack_expr *) calloc(1, sizeof(hstack_expr)); expr *node = &hnode->base; - init_expr(node, args[0]->d1, d2, n_vars, forward, jacobian_init_impl, eval_jacobian, - is_affine, wsum_hess_init_impl, wsum_hess_eval, free_type_data); + init_expr(node, args[0]->d1, d2, n_vars, forward, jacobian_init_impl, + eval_jacobian, is_affine, wsum_hess_init_impl, wsum_hess_eval, + free_type_data); /* Set type-specific fields (deep copy args array) */ hnode->args = (expr **) calloc(n_args, sizeof(expr *)); diff --git a/src/affine/index.c b/src/affine/index.c index c18154ec..70fd11da 100644 --- a/src/affine/index.c +++ b/src/affine/index.c @@ -166,8 +166,9 @@ expr *new_index(expr *child, int d1, int d2, const int *indices, int n_idxs) index_expr *idx = (index_expr *) calloc(1, sizeof(index_expr)); expr *node = &idx->base; - init_expr(node, d1, d2, child->n_vars, forward, jacobian_init_impl, eval_jacobian, - is_affine, wsum_hess_init_impl, eval_wsum_hess, free_type_data); + init_expr(node, d1, d2, child->n_vars, forward, jacobian_init_impl, + eval_jacobian, is_affine, wsum_hess_init_impl, eval_wsum_hess, + free_type_data); node->left = child; expr_retain(child); diff --git a/src/affine/promote.c b/src/affine/promote.c index 57c73c19..ddad1e79 100644 --- a/src/affine/promote.c +++ b/src/affine/promote.c @@ -107,8 +107,8 @@ expr *new_promote(expr *child, int d1, int d2) { assert(child->size == 1); expr *node = (expr *) calloc(1, sizeof(expr)); - init_expr(node, d1, d2, child->n_vars, forward, jacobian_init_impl, eval_jacobian, - is_affine, wsum_hess_init_impl, eval_wsum_hess, NULL); + init_expr(node, d1, d2, child->n_vars, forward, jacobian_init_impl, + eval_jacobian, is_affine, wsum_hess_init_impl, eval_wsum_hess, NULL); node->left = child; expr_retain(child); diff --git a/src/affine/reshape.c b/src/affine/reshape.c index deb72fc8..2fb5f600 100644 --- a/src/affine/reshape.c +++ b/src/affine/reshape.c @@ -68,8 +68,8 @@ expr *new_reshape(expr *child, int d1, int d2) { assert(d1 * d2 == child->size); expr *node = (expr *) calloc(1, sizeof(expr)); - init_expr(node, d1, d2, child->n_vars, forward, jacobian_init_impl, eval_jacobian, - is_affine, wsum_hess_init_impl, eval_wsum_hess, NULL); + init_expr(node, d1, d2, child->n_vars, forward, jacobian_init_impl, + eval_jacobian, is_affine, wsum_hess_init_impl, eval_wsum_hess, NULL); node->left = child; expr_retain(child); diff --git a/src/affine/variable.c b/src/affine/variable.c index e1103543..0fd944d3 100644 --- a/src/affine/variable.c +++ b/src/affine/variable.c @@ -64,8 +64,8 @@ static bool is_affine(const expr *node) expr *new_variable(int d1, int d2, int var_id, int n_vars) { expr *node = (expr *) calloc(1, sizeof(expr)); - init_expr(node, d1, d2, n_vars, forward, jacobian_init_impl, eval_jacobian, is_affine, - wsum_hess_init_impl, wsum_hess_eval, NULL); + init_expr(node, d1, d2, n_vars, forward, jacobian_init_impl, eval_jacobian, + is_affine, wsum_hess_init_impl, wsum_hess_eval, NULL); node->var_id = var_id; return node; diff --git a/src/bivariate_full_dom/matmul.c b/src/bivariate_full_dom/matmul.c index 68939b4a..97e6ba9a 100644 --- a/src/bivariate_full_dom/matmul.c +++ b/src/bivariate_full_dom/matmul.c @@ -330,8 +330,8 @@ expr *new_matmul(expr *x, expr *y) expr *node = (expr *) calloc(1, sizeof(expr)); /* Initialize with d1 = x->d1, d2 = y->d2 (result is m x n) */ - init_expr(node, x->d1, y->d2, x->n_vars, forward, jacobian_init_impl, eval_jacobian, - is_affine, wsum_hess_init_impl, eval_wsum_hess, NULL); + init_expr(node, x->d1, y->d2, x->n_vars, forward, jacobian_init_impl, + eval_jacobian, is_affine, wsum_hess_init_impl, eval_wsum_hess, NULL); /* Set children */ node->left = x;