From 71912e99b3e22463d6b9aecc523094b0c724be6a Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 6 Jan 2026 00:12:20 -0800 Subject: [PATCH 1/3] hessian for quad form --- src/other/quad_form.c | 92 ++++++++++++++++++++++++--- tests/all_tests.c | 5 +- tests/jacobian_tests/test_quad_form.h | 84 ++++++++++++------------ tests/wsum_hess/test_quad_form.h | 48 ++++++++++++++ 4 files changed, 177 insertions(+), 52 deletions(-) create mode 100644 tests/wsum_hess/test_quad_form.h diff --git a/src/other/quad_form.c b/src/other/quad_form.c index 9eb74a3..cb6200b 100644 --- a/src/other/quad_form.c +++ b/src/other/quad_form.c @@ -4,6 +4,7 @@ #include #include #include +#include static void forward(expr *node, const double *u) { @@ -25,10 +26,78 @@ static void forward(expr *node, const double *u) static void jacobian_init(expr *node) { + assert(node->left->var_id != NOT_A_VARIABLE); + assert(node->left->d2 == 1); expr *x = node->left; node->dwork = (double *) malloc(x->d1 * sizeof(double)); + node->jacobian = new_csr_matrix(1, node->n_vars, x->d1); + node->jacobian->p[0] = 0; + node->jacobian->p[1] = x->d1; - /* if x is a variable */ + for (int j = 0; j < x->d1; j++) + { + node->jacobian->i[j] = x->var_id + j; + } +} + +static void eval_jacobian(expr *node) +{ + expr *x = node->left; + CSR_Matrix *Q = ((quad_form_expr *) node)->Q; + + // jacobian = 2 * Q * x + csr_matvec(Q, x->value, node->jacobian->x, 0); + + for (int j = 0; j < x->d1; j++) + { + node->jacobian->x[j] *= 2.0; + } +} + +static void wsum_hess_init(expr *node) +{ + expr *x = node->left; + CSR_Matrix *Q = ((quad_form_expr *) node)->Q; + CSR_Matrix *H = new_csr_matrix(node->n_vars, node->n_vars, Q->nnz); + + /* set global row pointers */ + memcpy(H->p + x->var_id, Q->p, (x->d1 + 1) * sizeof(int)); + for (int i = x->var_id + x->d1 + 1; i <= node->n_vars; i++) + { + H->p[i] = Q->nnz; + } + + /* set global column indices */ + for (int i = 0; i < Q->nnz; i++) + { + H->i[i] = Q->i[i] + x->var_id; + } + + node->wsum_hess = H; +} + +static void eval_wsum_hess(expr *node, const double *w) +{ + CSR_Matrix *Q = ((quad_form_expr *) node)->Q; + double *H = node->wsum_hess->x; + double two_w = 2.0 * w[0]; + for (int i = 0; i < Q->nnz; i++) + { + H[i] = two_w * Q->x[i]; + } +} + +/* +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) +{ + expr *x = node->left; + node->dwork = (double *) malloc(x->d1 * sizeof(double)); + + // if x is a variable if (x->var_id != NOT_A_VARIABLE) { node->jacobian = new_csr_matrix(1, node->n_vars, x->d1); @@ -40,14 +109,14 @@ static void jacobian_init(expr *node) node->jacobian->i[j] = x->var_id + j; } } - else /* x is not a variable */ + else // x is not a variable { - /* compute required allocation and allocate jacobian */ + // compute required allocation and allocate jacobian bool *col_nz = (bool *) calloc(node->n_vars, sizeof(bool)); int nonzero_cols = count_nonzero_cols(x->jacobian, col_nz); node->jacobian = new_csr_matrix(1, node->n_vars, nonzero_cols + 1); - /* precompute column indices */ + // precompute column indices node->jacobian->nnz = 0; for (int j = 0; j < node->n_vars; j++) { @@ -65,12 +134,13 @@ static void jacobian_init(expr *node) } } -static void eval_jacobian(expr *node) + +static void eval_jacobian_old(expr *node) { expr *x = node->left; CSR_Matrix *Q = ((quad_form_expr *) node)->Q; - /* if x is a variable */ + // if x is a variable if (x->var_id != NOT_A_VARIABLE) { csr_matvec(Q, x->value, node->jacobian->x, 0); @@ -80,11 +150,11 @@ static void eval_jacobian(expr *node) node->jacobian->x[j] *= 2.0; } } - else /* x is not a variable */ + else // x is not a variable { linear_op_expr *lin_x = (linear_op_expr *) x; - /* local jacobian */ + // local jacobian csr_matvec(Q, x->value, node->dwork, 0); for (int j = 0; j < x->d1; j++) @@ -92,10 +162,11 @@ static void eval_jacobian(expr *node) node->dwork[j] *= 2.0; } - /* chain rule using CSC format */ + // chain rule using CSC format csc_matvec_fill_values(lin_x->A_csc, node->dwork, node->jacobian); } } +*/ expr *new_quad_form(expr *left, CSR_Matrix *Q) { @@ -113,6 +184,7 @@ expr *new_quad_form(expr *left, CSR_Matrix *Q) /* Set type-specific field */ qnode->Q = Q; - + node->wsum_hess_init = wsum_hess_init; + node->eval_wsum_hess = eval_wsum_hess; return node; } diff --git a/tests/all_tests.c b/tests/all_tests.c index 071d5bf..14e871e 100644 --- a/tests/all_tests.c +++ b/tests/all_tests.c @@ -31,6 +31,7 @@ #include "wsum_hess/elementwise/test_xexp.h" #include "wsum_hess/test_hstack.h" #include "wsum_hess/test_multiply.h" +#include "wsum_hess/test_quad_form.h" #include "wsum_hess/test_rel_entr.h" #include "wsum_hess/test_sum.h" @@ -71,7 +72,8 @@ int main(void) mu_run_test(test_quad_over_lin4, tests_run); mu_run_test(test_quad_over_lin5, tests_run); mu_run_test(test_quad_form, tests_run); - mu_run_test(test_quad_form2, tests_run); + /* commented out - see test_quad_form.h */ + // mu_run_test(test_quad_form2, tests_run); mu_run_test(test_jacobian_sum_log, tests_run); mu_run_test(test_jacobian_sum_mult, tests_run); mu_run_test(test_jacobian_sum_log_axis_0, tests_run); @@ -104,6 +106,7 @@ int main(void) mu_run_test(test_wsum_hess_rel_entr_2, tests_run); mu_run_test(test_wsum_hess_hstack, tests_run); mu_run_test(test_wsum_hess_hstack_matrix, tests_run); + mu_run_test(test_wsum_hess_quad_form, tests_run); mu_run_test(test_wsum_hess_multiply_linear_ops, tests_run); mu_run_test(test_wsum_hess_multiply_sparse_random, tests_run); diff --git a/tests/jacobian_tests/test_quad_form.h b/tests/jacobian_tests/test_quad_form.h index 0469ea6..d44713d 100644 --- a/tests/jacobian_tests/test_quad_form.h +++ b/tests/jacobian_tests/test_quad_form.h @@ -41,50 +41,52 @@ const char *test_quad_form() return 0; } -const char *test_quad_form2() +/* This test is commented out, see the function eval_jabobian_old in +src/other/quad_form.c. const char *test_quad_form2() { - /* (Au)^T Q (Au) where u is 6 x 1, - Q = [1 2 0; - 2 3 0; - 0 0 4] - A = [1 0 1 2 3 0; - 0 0 4 5 6 0; - 1 0 0 2 0 1] */ - double u_vals[6] = {1, 2, 3, 4, 5, 6}; - expr *u = new_variable(6, 1, 0, 6); - CSR_Matrix *Q = new_csr_matrix(3, 3, 5); - double Qx[5] = {1.0, 2.0, 2.0, 3.0, 4.0}; - int Qi[5] = {0, 1, 0, 1, 2}; - int Qp[4] = {0, 2, 4, 5}; - memcpy(Q->x, Qx, 5 * sizeof(double)); - memcpy(Q->i, Qi, 5 * sizeof(int)); - memcpy(Q->p, Qp, 4 * sizeof(int)); + // (Au)^T Q (Au) where u is 6 x 1, + // Q = [1 2 0; + // 2 3 0; + // 0 0 4] + // A = [1 0 1 2 3 0; + // 0 0 4 5 6 0; + // 1 0 0 2 0 1] +double u_vals[6] = {1, 2, 3, 4, 5, 6}; +expr *u = new_variable(6, 1, 0, 6); +CSR_Matrix *Q = new_csr_matrix(3, 3, 5); +double Qx[5] = {1.0, 2.0, 2.0, 3.0, 4.0}; +int Qi[5] = {0, 1, 0, 1, 2}; +int Qp[4] = {0, 2, 4, 5}; +memcpy(Q->x, Qx, 5 * sizeof(double)); +memcpy(Q->i, Qi, 5 * sizeof(int)); +memcpy(Q->p, Qp, 4 * sizeof(int)); - CSR_Matrix *A = new_csr_matrix(3, 6, 10); - double Ax[10] = {1.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6, 1.0, 2.0, 1.0}; - int Ai[10] = {0, 2, 3, 4, 2, 3, 4, 0, 3, 5}; - int Ap[4] = {0, 4, 7, 10}; - memcpy(A->x, Ax, 10 * sizeof(double)); - memcpy(A->i, Ai, 10 * sizeof(int)); - memcpy(A->p, Ap, 4 * sizeof(int)); - expr *Au = new_linear(u, A); - expr *node = new_quad_form(Au, Q); +CSR_Matrix *A = new_csr_matrix(3, 6, 10); +double Ax[10] = {1.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6, 1.0, 2.0, 1.0}; +int Ai[10] = {0, 2, 3, 4, 2, 3, 4, 0, 3, 5}; +int Ap[4] = {0, 4, 7, 10}; +memcpy(A->x, Ax, 10 * sizeof(double)); +memcpy(A->i, Ai, 10 * sizeof(int)); +memcpy(A->p, Ap, 4 * sizeof(int)); +expr *Au = new_linear(u, A); +expr *node = new_quad_form(Au, Q); - node->jacobian_init(node); - node->forward(node, u_vals); - node->eval_jacobian(node); +node->jacobian_init(node); +node->forward(node, u_vals); +node->eval_jacobian(node); - double expected_Ax[5] = {422, 2222, 3244, 3786, 120}; - int expected_Ap[2] = {0, 5}; - int expected_Ai[5] = {0, 2, 3, 4, 5}; +double expected_Ax[5] = {422, 2222, 3244, 3786, 120}; +int expected_Ap[2] = {0, 5}; +int expected_Ai[5] = {0, 2, 3, 4, 5}; - mu_assert("vals fail", cmp_double_array(node->jacobian->x, expected_Ax, 5)); - mu_assert("rows fail", cmp_int_array(node->jacobian->p, expected_Ap, 2)); - mu_assert("cols fail", cmp_int_array(node->jacobian->i, expected_Ai, 5)); - free_expr(node); - free_expr(Au); - free_expr(u); - free_csr_matrix(Q); - free_csr_matrix(A); - return 0; +mu_assert("vals fail", cmp_double_array(node->jacobian->x, expected_Ax, 5)); +mu_assert("rows fail", cmp_int_array(node->jacobian->p, expected_Ap, 2)); +mu_assert("cols fail", cmp_int_array(node->jacobian->i, expected_Ai, 5)); +free_expr(node); +free_expr(Au); +free_expr(u); +free_csr_matrix(Q); +free_csr_matrix(A); +return 0; } +*/ diff --git a/tests/wsum_hess/test_quad_form.h b/tests/wsum_hess/test_quad_form.h new file mode 100644 index 0000000..140c9da --- /dev/null +++ b/tests/wsum_hess/test_quad_form.h @@ -0,0 +1,48 @@ +#include "affine.h" +#include "expr.h" +#include "minunit.h" +#include "other.h" +#include "test_helpers.h" +#include + +const char *test_wsum_hess_quad_form() +{ + // x has var_id = 3, dimension 4, total variables = 10 + double u_vals[10] = {0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 4.0, 0.0, 0.0, 0.0}; + double w = 2.0; + + /* Symmetric 4x4 Q: + * [1 2 0 0] + * [2 5 3 0] + * [0 3 4 1] + * [0 0 1 6] + */ + CSR_Matrix *Q = new_csr_matrix(4, 4, 10); + double Qx[10] = {1.0, 2.0, 2.0, 5.0, 3.0, 3.0, 4.0, 1.0, 1.0, 6.0}; + int Qi[10] = {0, 1, 0, 1, 2, 1, 2, 3, 2, 3}; + int Qp[5] = {0, 2, 5, 8, 10}; + memcpy(Q->x, Qx, 10 * sizeof(double)); + memcpy(Q->i, Qi, 10 * sizeof(int)); + memcpy(Q->p, Qp, 5 * sizeof(int)); + + expr *x = new_variable(4, 1, 3, 10); + expr *node = new_quad_form(x, Q); + + node->jacobian_init(node); + node->forward(node, u_vals); + 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}; + int expected_i[10] = {3, 4, 3, 4, 5, 4, 5, 6, 5, 6}; + double expected_x[10] = {4.0, 8.0, 8.0, 20.0, 12.0, 12.0, 16.0, 4.0, 4.0, 24.0}; + + mu_assert("p array fails", cmp_int_array(node->wsum_hess->p, expected_p, 11)); + mu_assert("i array fails", cmp_int_array(node->wsum_hess->i, expected_i, 10)); + mu_assert("x array fails", cmp_double_array(node->wsum_hess->x, expected_x, 10)); + + free_expr(node); + free_expr(x); + free_csr_matrix(Q); + return 0; +} From 101156da755d62a0098d9322a9a6fc0feb964cea Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 6 Jan 2026 02:15:03 -0800 Subject: [PATCH 2/3] quad over lin hessian when both arguments are variabels --- src/bivariate/quad_over_lin.c | 147 ++++++++++++++++++++++++++- tests/all_tests.c | 3 + tests/wsum_hess/test_quad_over_lin.h | 67 ++++++++++++ 3 files changed, 215 insertions(+), 2 deletions(-) create mode 100644 tests/wsum_hess/test_quad_over_lin.h diff --git a/src/bivariate/quad_over_lin.c b/src/bivariate/quad_over_lin.c index 20be94f..adc4a2b 100644 --- a/src/bivariate/quad_over_lin.c +++ b/src/bivariate/quad_over_lin.c @@ -144,12 +144,153 @@ static void eval_jacobian(expr *node) csc_matvec_fill_values(A_csc, node->dwork, node->jacobian); /* insert derivative wrt y at right place (for correctness this assumes - that y does not appear in the denominator, but this will always be - the case since y is a new variable for the numerator) */ + that y does not appear in the numerator, but this will always be + the case since y is a new variable for the denominator */ node->jacobian->x[node->iwork[0]] = -node->value[0] / y->value[0]; } } +static void wsum_hess_init(expr *node) +{ + expr *x = node->left; + expr *y = node->right; + int var_id_x = x->var_id; + int var_id_y = y->var_id; + + /* if left node is a variable */ + if (x->var_id != NOT_A_VARIABLE) + { + node->wsum_hess = new_csr_matrix(node->n_vars, node->n_vars, 3 * x->d1 + 1); + CSR_Matrix *H = node->wsum_hess; + + /* if x has lower idx than y*/ + if (var_id_x < var_id_y) + { + /* x rows: each row has 2 entries (diagonal element + element for y) */ + for (int i = 0; i < x->d1; i++) + { + H->p[var_id_x + i] = 2 * i; + H->i[2 * i] = var_id_x + i; + H->i[2 * i + 1] = var_id_y; + } + + /* rows between x and y are empty, all point to same offset */ + int offset = 2 * x->d1; + for (int i = var_id_x + x->d1; i <= var_id_y; i++) + { + H->p[i] = offset; + } + + /* y row has d1 + 1 entries */ + H->p[var_id_y + 1] = offset + x->d1 + 1; + for (int i = 0; i < x->d1; i++) + { + H->i[offset + i] = var_id_x + i; + } + H->i[offset + x->d1] = var_id_y; + + /* remaining rows are empty */ + for (int i = var_id_y + 1; i <= node->n_vars; i++) + { + H->p[i] = 3 * x->d1 + 1; + } + } + else /* y has lower idx than x */ + { + /* y row has d1 + 1 entries */ + H->p[var_id_y + 1] = x->d1 + 1; + H->i[0] = var_id_y; + for (int i = 0; i < x->d1; i++) + { + H->i[i + 1] = var_id_x + i; + } + + /* rows between y and x are empty, all point to same offset */ + int offset = x->d1 + 1; + for (int i = var_id_y + 1; i <= var_id_x; i++) + { + H->p[i] = offset; + } + + /* x rows: each row has 2 entries */ + for (int i = 0; i < x->d1; i++) + { + H->p[var_id_x + i] = offset + 2 * i; + H->i[offset + 2 * i] = var_id_y; + H->i[offset + 2 * i + 1] = var_id_x + i; + } + + /* remaining rows are empty */ + for (int i = var_id_x + x->d1; i <= node->n_vars; i++) + { + H->p[i] = 3 * x->d1 + 1; + } + } + } + else + { + /* TODO: implement */ + assert(false && "not implemented"); + } +} + +static void eval_wsum_hess(expr *node, const double *w) +{ + double *x = node->left->value; + double y = node->right->value[0]; + double *H = node->wsum_hess->x; + int var_id_x = node->left->var_id; + int var_id_y = node->right->var_id; + int x_d1 = node->left->d1; + double a = (2.0 * w[0]) / y; + double b = -(2.0 * w[0]) / (y * y); + + /* if left node is a variable */ + if (var_id_x != NOT_A_VARIABLE) + { + /* if x has lower idx than y*/ + if (var_id_x < var_id_y) + { + /* x rows*/ + for (int i = 0; i < x_d1; i++) + { + H[2 * i] = a; + H[2 * i + 1] = b * x[i]; + } + + /* y row */ + int offset = 2 * x_d1; + for (int i = 0; i < x_d1; i++) + { + H[offset + i] = b * x[i]; + } + H[offset + x_d1] = -b * node->value[0]; + } + else /* y has lower idx than x */ + { + /* y row */ + H[0] = -b * node->value[0]; + for (int i = 0; i < x_d1; i++) + { + H[i + 1] = b * x[i]; + } + + /* x rows*/ + int offset = x_d1 + 1; + for (int i = 0; i < x_d1; i++) + { + H[offset + 2 * i] = b * x[i]; + H[offset + 2 * i + 1] = a; + } + } + } + else + { + /* TODO: implement */ + assert(false && "not implemented"); + } +} + expr *new_quad_over_lin(expr *left, expr *right) { expr *node = new_expr(left->d1, 1, left->n_vars); @@ -160,5 +301,7 @@ expr *new_quad_over_lin(expr *left, expr *right) node->forward = forward; node->jacobian_init = jacobian_init; node->eval_jacobian = eval_jacobian; + node->wsum_hess_init = wsum_hess_init; + node->eval_wsum_hess = eval_wsum_hess; return node; } diff --git a/tests/all_tests.c b/tests/all_tests.c index 14e871e..16bb1ec 100644 --- a/tests/all_tests.c +++ b/tests/all_tests.c @@ -32,6 +32,7 @@ #include "wsum_hess/test_hstack.h" #include "wsum_hess/test_multiply.h" #include "wsum_hess/test_quad_form.h" +#include "wsum_hess/test_quad_over_lin.h" #include "wsum_hess/test_rel_entr.h" #include "wsum_hess/test_sum.h" @@ -106,6 +107,8 @@ int main(void) mu_run_test(test_wsum_hess_rel_entr_2, tests_run); mu_run_test(test_wsum_hess_hstack, tests_run); mu_run_test(test_wsum_hess_hstack_matrix, tests_run); + mu_run_test(test_wsum_hess_quad_over_lin_xy, tests_run); + mu_run_test(test_wsum_hess_quad_over_lin_yx, tests_run); mu_run_test(test_wsum_hess_quad_form, tests_run); mu_run_test(test_wsum_hess_multiply_linear_ops, tests_run); mu_run_test(test_wsum_hess_multiply_sparse_random, tests_run); diff --git a/tests/wsum_hess/test_quad_over_lin.h b/tests/wsum_hess/test_quad_over_lin.h new file mode 100644 index 0000000..0d5dd62 --- /dev/null +++ b/tests/wsum_hess/test_quad_over_lin.h @@ -0,0 +1,67 @@ +#include "affine.h" +#include "bivariate.h" +#include "expr.h" +#include "minunit.h" +#include "test_helpers.h" + +const char *test_wsum_hess_quad_over_lin_xy() +{ + /* x^T x / y with x var_id=2 (3 vars), y var_id=7, total n_vars=9 + * x = [1, 2, 3], y = 4, w = 2 + */ + double u_vals[9] = {0.0, 0.0, 1.0, 2.0, 3.0, 0.0, 0.0, 4.0, 0.0}; + double w = 2.0; + + expr *x = new_variable(3, 1, 2, 9); + expr *y = new_variable(1, 1, 7, 9); + expr *node = new_quad_over_lin(x, y); + + node->forward(node, u_vals); + 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}; + int expected_i[10] = {2, 7, 3, 7, 4, 7, 2, 3, 4, 7}; + double expected_x[10] = {1.0, -0.25, 1.0, -0.5, 1.0, + -0.75, -0.25, -0.5, -0.75, 0.875}; + + mu_assert("p array fails", cmp_int_array(node->wsum_hess->p, expected_p, 10)); + mu_assert("i array fails", cmp_int_array(node->wsum_hess->i, expected_i, 10)); + mu_assert("x array fails", cmp_double_array(node->wsum_hess->x, expected_x, 10)); + + free_expr(node); + free_expr(x); + free_expr(y); + return 0; +} + +const char *test_wsum_hess_quad_over_lin_yx() +{ + /* x^T x / y with y var_id=2, x var_id=5 (3 vars), total n_vars=9 + * x = [1, 2, 3], y = 4, w = 2 + */ + double u_vals[9] = {0.0, 0.0, 4.0, 0.0, 0.0, 1.0, 2.0, 3.0, 0.0}; + double w = 2.0; + + expr *y = new_variable(1, 1, 2, 9); + expr *x = new_variable(3, 1, 5, 9); + expr *node = new_quad_over_lin(x, y); + + node->forward(node, u_vals); + 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}; + int expected_i[10] = {2, 5, 6, 7, 2, 5, 2, 6, 2, 7}; + double expected_x[10] = {0.875, -0.25, -0.5, -0.75, -0.25, + 1.0, -0.5, 1.0, -0.75, 1.0}; + + mu_assert("p array fails", cmp_int_array(node->wsum_hess->p, expected_p, 10)); + mu_assert("i array fails", cmp_int_array(node->wsum_hess->i, expected_i, 10)); + mu_assert("x array fails", cmp_double_array(node->wsum_hess->x, expected_x, 10)); + + free_expr(node); + free_expr(x); + free_expr(y); + return 0; +} From eb78814f0d6efc8a2722a0caeed67afd55b59a1c Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 6 Jan 2026 02:47:12 -0800 Subject: [PATCH 3/3] simpler memory management --- src/expr.c | 2 +- tests/forward_pass/affine/test_add.h | 2 -- tests/forward_pass/affine/test_hstack.h | 8 -------- tests/forward_pass/affine/test_linear_op.h | 1 - tests/forward_pass/affine/test_sum.h | 6 ------ tests/forward_pass/composite/test_composite.h | 4 ---- tests/forward_pass/elementwise/test_exp.h | 1 - tests/forward_pass/elementwise/test_log.h | 1 - tests/jacobian_tests/test_composite.h | 8 -------- tests/jacobian_tests/test_elementwise_mult.h | 12 ------------ tests/jacobian_tests/test_hstack.h | 8 -------- tests/jacobian_tests/test_log.h | 2 -- tests/jacobian_tests/test_quad_form.h | 2 -- tests/jacobian_tests/test_quad_over_lin.h | 13 ------------- tests/jacobian_tests/test_rel_entr.h | 4 ---- tests/jacobian_tests/test_sum.h | 14 -------------- tests/wsum_hess/elementwise/test_entr.h | 1 - tests/wsum_hess/elementwise/test_exp.h | 1 - tests/wsum_hess/elementwise/test_hyperbolic.h | 4 ---- tests/wsum_hess/elementwise/test_log.h | 3 --- tests/wsum_hess/elementwise/test_logistic.h | 1 - tests/wsum_hess/elementwise/test_power.h | 1 - tests/wsum_hess/elementwise/test_trig.h | 3 --- tests/wsum_hess/elementwise/test_xexp.h | 1 - tests/wsum_hess/test_hstack.h | 16 ++-------------- tests/wsum_hess/test_multiply.h | 10 ---------- tests/wsum_hess/test_quad_form.h | 1 - tests/wsum_hess/test_quad_over_lin.h | 4 ---- tests/wsum_hess/test_rel_entr.h | 4 ---- tests/wsum_hess/test_sum.h | 7 ------- 30 files changed, 3 insertions(+), 142 deletions(-) diff --git a/src/expr.c b/src/expr.c index 0815825..fe6d1ac 100644 --- a/src/expr.c +++ b/src/expr.c @@ -11,7 +11,7 @@ void init_expr(expr *node, int d1, int d2, int n_vars, forward_fn forward, node->d2 = d2; node->size = d1 * d2; node->n_vars = n_vars; - node->refcount = 1; + node->refcount = 0; node->value = (double *) calloc(d1 * d2, sizeof(double)); node->var_id = NOT_A_VARIABLE; node->forward = forward; diff --git a/tests/forward_pass/affine/test_add.h b/tests/forward_pass/affine/test_add.h index bf74537..7ce859c 100644 --- a/tests/forward_pass/affine/test_add.h +++ b/tests/forward_pass/affine/test_add.h @@ -18,7 +18,5 @@ const char *test_addition() double expected[2] = {4.0, 6.0}; mu_assert("Addition test failed", cmp_double_array(sum->value, expected, 2)); free_expr(sum); - free_expr(var); - free_expr(const_node); return 0; } diff --git a/tests/forward_pass/affine/test_hstack.h b/tests/forward_pass/affine/test_hstack.h index 20e8597..df76ba7 100644 --- a/tests/forward_pass/affine/test_hstack.h +++ b/tests/forward_pass/affine/test_hstack.h @@ -30,10 +30,6 @@ const char *test_hstack_forward_vectors() mu_assert("hstack forward failed", cmp_double_array(stack->value, expected, 9)); free_expr(stack); - free_expr(sin_x); - free_expr(exp_x); - free_expr(log_x); - free_expr(x); return 0; } @@ -63,9 +59,5 @@ const char *test_hstack_forward_matrix() cmp_double_array(stack->value, expected, 18)); free_expr(stack); - free_expr(sin_x); - free_expr(exp_x); - free_expr(log_x); - free_expr(x); return 0; } diff --git a/tests/forward_pass/affine/test_linear_op.h b/tests/forward_pass/affine/test_linear_op.h index 5a8df7f..72e06d4 100644 --- a/tests/forward_pass/affine/test_linear_op.h +++ b/tests/forward_pass/affine/test_linear_op.h @@ -31,7 +31,6 @@ const char *test_linear_op() double expected[3] = {8, 7, 26}; mu_assert("fail", cmp_double_array(linear_node->value, expected, 3)); free_expr(linear_node); - free_expr(var); free_csr_matrix(A); return 0; } diff --git a/tests/forward_pass/affine/test_sum.h b/tests/forward_pass/affine/test_sum.h index 78edc5d..2e3d6ab 100644 --- a/tests/forward_pass/affine/test_sum.h +++ b/tests/forward_pass/affine/test_sum.h @@ -30,8 +30,6 @@ const char *test_sum_axis_neg1() fabs(sum_node->value[0] - expected) < 1e-10); free_expr(sum_node); - free_expr(log_node); - free_expr(const_node); return 0; } @@ -59,8 +57,6 @@ const char *test_sum_axis_0() cmp_double_array(sum_node->value, expected, 2)); free_expr(sum_node); - free_expr(log_node); - free_expr(const_node); return 0; } @@ -90,7 +86,5 @@ const char *test_sum_axis_1() cmp_double_array(sum_node->value, expected, 3)); free_expr(sum_node); - free_expr(log_node); - free_expr(const_node); return 0; } diff --git a/tests/forward_pass/composite/test_composite.h b/tests/forward_pass/composite/test_composite.h index 791c20a..92074a0 100644 --- a/tests/forward_pass/composite/test_composite.h +++ b/tests/forward_pass/composite/test_composite.h @@ -26,9 +26,5 @@ const char *test_composite() mu_assert("failed", cmp_double_array(log_node->value, correct, 2)); free_expr(log_node); - free_expr(sum); - free_expr(exp_node); - free_expr(const_node); - free_expr(var); return 0; } diff --git a/tests/forward_pass/elementwise/test_exp.h b/tests/forward_pass/elementwise/test_exp.h index 68d8e21..a153889 100644 --- a/tests/forward_pass/elementwise/test_exp.h +++ b/tests/forward_pass/elementwise/test_exp.h @@ -17,6 +17,5 @@ const char *test_exp() double correct[2] = {exp(0.0), exp(1.0)}; mu_assert("fail", cmp_double_array(exp_node->value, correct, 2)); free_expr(exp_node); - free_expr(var); return 0; } diff --git a/tests/forward_pass/elementwise/test_log.h b/tests/forward_pass/elementwise/test_log.h index d7aa393..d21dbf0 100644 --- a/tests/forward_pass/elementwise/test_log.h +++ b/tests/forward_pass/elementwise/test_log.h @@ -17,6 +17,5 @@ const char *test_log() double correct[2] = {log(1.0), log(2.718281828)}; mu_assert("fail", cmp_double_array(log_node->value, correct, 2)); free_expr(log_node); - free_expr(var); return 0; } diff --git a/tests/jacobian_tests/test_composite.h b/tests/jacobian_tests/test_composite.h index edb7c6e..b35923a 100644 --- a/tests/jacobian_tests/test_composite.h +++ b/tests/jacobian_tests/test_composite.h @@ -30,8 +30,6 @@ const char *test_jacobian_composite_log() mu_assert("rows fail", cmp_int_array(log_node->jacobian->p, rows, 3)); mu_assert("cols fail", cmp_int_array(log_node->jacobian->i, cols, 6)); free_expr(log_node); - free_expr(Au); - free_expr(u); free_csr_matrix(A); return 0; } @@ -91,12 +89,6 @@ const char *test_jacobian_composite_log_add() mu_assert("rows fail", cmp_int_array(sum->jacobian->p, rows, 4)); mu_assert("cols fail", cmp_int_array(sum->jacobian->i, cols, 15)); free_expr(sum); - free_expr(log_Ax); - free_expr(log_By); - free_expr(Ax_expr); - free_expr(By_expr); - free_expr(x); - free_expr(y); free_csr_matrix(A); free_csr_matrix(B); return 0; diff --git a/tests/jacobian_tests/test_elementwise_mult.h b/tests/jacobian_tests/test_elementwise_mult.h index 9679af1..3c5644e 100644 --- a/tests/jacobian_tests/test_elementwise_mult.h +++ b/tests/jacobian_tests/test_elementwise_mult.h @@ -28,8 +28,6 @@ const char *test_jacobian_elementwise_mult_1() mu_assert("rows fail", cmp_int_array(node->jacobian->p, rows, 4)); mu_assert("cols fail", cmp_int_array(node->jacobian->i, cols, 6)); free_expr(node); - free_expr(x); - free_expr(y); return 0; } @@ -55,8 +53,6 @@ const char *test_jacobian_elementwise_mult_2() mu_assert("rows fail", cmp_int_array(node->jacobian->p, rows, 4)); mu_assert("cols fail", cmp_int_array(node->jacobian->i, cols, 6)); free_expr(node); - free_expr(x); - free_expr(y); return 0; } @@ -120,10 +116,6 @@ const char *test_jacobian_elementwise_mult_3() mu_assert("rows fail", cmp_int_array(node->jacobian->p, rows, 4)); mu_assert("cols fail", cmp_int_array(node->jacobian->i, cols, 16)); free_expr(node); - free_expr(Ax); - free_expr(By); - free_expr(x); - free_expr(y); free_csr_matrix(A); free_csr_matrix(B); return 0; @@ -149,7 +141,6 @@ const char *test_jacobian_elementwise_mult_4() double u_vals[10] = {0, 0, 1.0, 2.0, 3.0, 0, 0, 4.0, 5.0, 6.0}; expr *x = new_variable(3, 1, 2, 10); - expr *y = new_variable(3, 1, 7, 10); expr *Ax = new_linear(x, A); expr *node = new_elementwise_mult(Ax, Ax); @@ -170,9 +161,6 @@ const char *test_jacobian_elementwise_mult_4() mu_assert("rows fail", cmp_int_array(node->jacobian->p, rows, 4)); mu_assert("cols fail", cmp_int_array(node->jacobian->i, cols, 8)); free_expr(node); - free_expr(Ax); - free_expr(x); - free_expr(y); free_csr_matrix(A); return 0; } diff --git a/tests/jacobian_tests/test_hstack.h b/tests/jacobian_tests/test_hstack.h index 970c228..67ed85e 100644 --- a/tests/jacobian_tests/test_hstack.h +++ b/tests/jacobian_tests/test_hstack.h @@ -46,10 +46,6 @@ const char *test_jacobian_hstack_vectors() mu_assert("rows fail", cmp_int_array(stack->jacobian->p, expected_Ap, 10)); free_expr(stack); - free_expr(sin_x); - free_expr(exp_x); - free_expr(log_x); - free_expr(x); return 0; } @@ -94,9 +90,5 @@ const char *test_jacobian_hstack_matrix() mu_assert("rows fail", cmp_int_array(stack->jacobian->p, expected_Ap, 19)); free_expr(stack); - free_expr(sin_x); - free_expr(exp_x); - free_expr(log_x); - free_expr(x); return 0; } diff --git a/tests/jacobian_tests/test_log.h b/tests/jacobian_tests/test_log.h index 2708d84..f17c290 100644 --- a/tests/jacobian_tests/test_log.h +++ b/tests/jacobian_tests/test_log.h @@ -21,7 +21,6 @@ const char *test_jacobian_log() mu_assert("rows fail", cmp_int_array(log_node->jacobian->p, expected_Ap, 4)); mu_assert("cols fail", cmp_int_array(log_node->jacobian->i, expected_Ai, 3)); free_expr(log_node); - free_expr(u); return 0; } @@ -40,6 +39,5 @@ const char *test_jacobian_log_matrix() mu_assert("rows fail", cmp_int_array(log_node->jacobian->p, expected_Ap, 5)); mu_assert("cols fail", cmp_int_array(log_node->jacobian->i, expected_Ai, 4)); free_expr(log_node); - free_expr(u); return 0; } diff --git a/tests/jacobian_tests/test_quad_form.h b/tests/jacobian_tests/test_quad_form.h index d44713d..cea6176 100644 --- a/tests/jacobian_tests/test_quad_form.h +++ b/tests/jacobian_tests/test_quad_form.h @@ -36,7 +36,6 @@ const char *test_quad_form() mu_assert("rows fail", cmp_int_array(node->jacobian->p, expected_Ap, 2)); mu_assert("cols fail", cmp_int_array(node->jacobian->i, expected_Ai, 3)); free_expr(node); - free_expr(x); free_csr_matrix(Q); return 0; } @@ -84,7 +83,6 @@ mu_assert("rows fail", cmp_int_array(node->jacobian->p, expected_Ap, 2)); mu_assert("cols fail", cmp_int_array(node->jacobian->i, expected_Ai, 5)); free_expr(node); free_expr(Au); -free_expr(u); free_csr_matrix(Q); free_csr_matrix(A); return 0; diff --git a/tests/jacobian_tests/test_quad_over_lin.h b/tests/jacobian_tests/test_quad_over_lin.h index b7c5e2a..3360846 100644 --- a/tests/jacobian_tests/test_quad_over_lin.h +++ b/tests/jacobian_tests/test_quad_over_lin.h @@ -29,8 +29,6 @@ const char *test_quad_over_lin1() mu_assert("rows fail", cmp_int_array(node->jacobian->p, expected_Ap, 2)); mu_assert("cols fail", cmp_int_array(node->jacobian->i, expected_Ai, 4)); free_expr(node); - free_expr(x); - free_expr(y); return 0; } @@ -55,8 +53,6 @@ const char *test_quad_over_lin2() mu_assert("rows fail", cmp_int_array(node->jacobian->p, expected_Ap, 2)); mu_assert("cols fail", cmp_int_array(node->jacobian->i, expected_Ai, 4)); free_expr(node); - free_expr(x); - free_expr(y); return 0; } @@ -96,9 +92,6 @@ const char *test_quad_over_lin3() free_csr_matrix(A); free_expr(node); - free_expr(Ax_expr); - free_expr(x); - free_expr(y); return 0; } @@ -139,9 +132,6 @@ const char *test_quad_over_lin4() free_csr_matrix(A); free_expr(node); - free_expr(Ax_expr); - free_expr(x); - free_expr(y); return 0; } @@ -182,8 +172,5 @@ const char *test_quad_over_lin5() free_csr_matrix(A); free_expr(node); - free_expr(Ax_expr); - free_expr(u); - free_expr(y); return 0; } diff --git a/tests/jacobian_tests/test_rel_entr.h b/tests/jacobian_tests/test_rel_entr.h index 3b9763d..1e4b089 100644 --- a/tests/jacobian_tests/test_rel_entr.h +++ b/tests/jacobian_tests/test_rel_entr.h @@ -34,8 +34,6 @@ const char *test_jacobian_rel_entr_vector_args_1() mu_assert("rows fail", cmp_int_array(node->jacobian->p, expected_Ap, 4)); mu_assert("cols fail", cmp_int_array(node->jacobian->i, expected_Ai, 6)); free_expr(node); - free_expr(x); - free_expr(y); return 0; } @@ -67,7 +65,5 @@ const char *test_jacobian_rel_entr_vector_args_2() mu_assert("rows fail", cmp_int_array(node->jacobian->p, expected_Ap, 4)); mu_assert("cols fail", cmp_int_array(node->jacobian->i, expected_Ai, 6)); free_expr(node); - free_expr(x); - free_expr(y); return 0; } diff --git a/tests/jacobian_tests/test_sum.h b/tests/jacobian_tests/test_sum.h index 11b0ea5..d7636c5 100644 --- a/tests/jacobian_tests/test_sum.h +++ b/tests/jacobian_tests/test_sum.h @@ -29,8 +29,6 @@ const char *test_jacobian_sum_log() mu_assert("cols fail", cmp_int_array(sum_node->jacobian->i, expected_Ai, 3)); free_expr(sum_node); - free_expr(log_node); - free_expr(x); return 0; } @@ -65,9 +63,6 @@ const char *test_jacobian_sum_mult() mu_assert("cols fail", cmp_int_array(sum_node->jacobian->i, expected_Ai, 6)); free_expr(sum_node); - free_expr(mult_node); - free_expr(x); - free_expr(y); return 0; } @@ -108,8 +103,6 @@ const char *test_jacobian_sum_log_axis_0() mu_assert("cols fail", cmp_int_array(sum_node->jacobian->i, expected_Ai, 6)); free_expr(sum_node); - free_expr(log_node); - free_expr(x); return 0; } const char *test_jacobian_sum_add_log_axis_0() @@ -157,11 +150,6 @@ const char *test_jacobian_sum_add_log_axis_0() mu_assert("cols fail", cmp_int_array(sum_node->jacobian->i, expected_Ai, 12)); free_expr(sum_node); - free_expr(add_node); - free_expr(log_x); - free_expr(log_y); - free_expr(x); - free_expr(y); return 0; } const char *test_jacobian_sum_log_axis_1() @@ -204,7 +192,5 @@ const char *test_jacobian_sum_log_axis_1() mu_assert("cols fail", cmp_int_array(sum_node->jacobian->i, expected_Ai, 6)); free_expr(sum_node); - free_expr(log_node); - free_expr(x); return 0; } diff --git a/tests/wsum_hess/elementwise/test_entr.h b/tests/wsum_hess/elementwise/test_entr.h index 8350840..6aa818c 100644 --- a/tests/wsum_hess/elementwise/test_entr.h +++ b/tests/wsum_hess/elementwise/test_entr.h @@ -33,7 +33,6 @@ const char *test_wsum_hess_entr() cmp_int_array(entr_node->wsum_hess->i, expected_i, 3)); free_expr(entr_node); - free_expr(x); return 0; } diff --git a/tests/wsum_hess/elementwise/test_exp.h b/tests/wsum_hess/elementwise/test_exp.h index 2e55616..9ed6323 100644 --- a/tests/wsum_hess/elementwise/test_exp.h +++ b/tests/wsum_hess/elementwise/test_exp.h @@ -33,7 +33,6 @@ const char *test_wsum_hess_exp() cmp_int_array(exp_node->wsum_hess->i, expected_i, 3)); free_expr(exp_node); - free_expr(x); return 0; } diff --git a/tests/wsum_hess/elementwise/test_hyperbolic.h b/tests/wsum_hess/elementwise/test_hyperbolic.h index 9318d57..7af436a 100644 --- a/tests/wsum_hess/elementwise/test_hyperbolic.h +++ b/tests/wsum_hess/elementwise/test_hyperbolic.h @@ -40,7 +40,6 @@ const char *test_wsum_hess_sinh() cmp_int_array(sinh_node->wsum_hess->i, expected_i, 3)); free_expr(sinh_node); - free_expr(x); return 0; } @@ -78,7 +77,6 @@ const char *test_wsum_hess_tanh() cmp_int_array(tanh_node->wsum_hess->i, expected_i, 3)); free_expr(tanh_node); - free_expr(x); return 0; } @@ -116,7 +114,6 @@ const char *test_wsum_hess_asinh() cmp_int_array(asinh_node->wsum_hess->i, expected_i, 3)); free_expr(asinh_node); - free_expr(x); return 0; } @@ -155,7 +152,6 @@ const char *test_wsum_hess_atanh() cmp_int_array(atanh_node->wsum_hess->i, expected_i, 3)); free_expr(atanh_node); - free_expr(x); return 0; } diff --git a/tests/wsum_hess/elementwise/test_log.h b/tests/wsum_hess/elementwise/test_log.h index 755622c..61b78c4 100644 --- a/tests/wsum_hess/elementwise/test_log.h +++ b/tests/wsum_hess/elementwise/test_log.h @@ -44,7 +44,6 @@ const char *test_wsum_hess_log() cmp_int_array(log_node->wsum_hess->i, expected_i, 3)); free_expr(log_node); - free_expr(x); return 0; } @@ -87,9 +86,7 @@ const char *test_wsum_hess_log_composite() mu_assert("cols incorrect", cmp_int_array(log_node->wsum_hess->i, expected_i, 25)); free_csr_matrix(A_csr); - free_expr(Ax_node); free_expr(log_node); - free_expr(x); return 0; } diff --git a/tests/wsum_hess/elementwise/test_logistic.h b/tests/wsum_hess/elementwise/test_logistic.h index 2d2f37d..714fe40 100644 --- a/tests/wsum_hess/elementwise/test_logistic.h +++ b/tests/wsum_hess/elementwise/test_logistic.h @@ -48,7 +48,6 @@ const char *test_wsum_hess_logistic() cmp_int_array(logistic_node->wsum_hess->i, expected_i, 3)); free_expr(logistic_node); - free_expr(x); return 0; } diff --git a/tests/wsum_hess/elementwise/test_power.h b/tests/wsum_hess/elementwise/test_power.h index f201e8c..d830a9d 100644 --- a/tests/wsum_hess/elementwise/test_power.h +++ b/tests/wsum_hess/elementwise/test_power.h @@ -33,7 +33,6 @@ const char *test_wsum_hess_power() cmp_int_array(power_node->wsum_hess->i, expected_i, 3)); free_expr(power_node); - free_expr(x); return 0; } diff --git a/tests/wsum_hess/elementwise/test_trig.h b/tests/wsum_hess/elementwise/test_trig.h index 2a6099d..fd84dc4 100644 --- a/tests/wsum_hess/elementwise/test_trig.h +++ b/tests/wsum_hess/elementwise/test_trig.h @@ -33,7 +33,6 @@ const char *test_wsum_hess_sin() cmp_int_array(sin_node->wsum_hess->i, expected_i, 3)); free_expr(sin_node); - free_expr(x); return 0; } @@ -62,7 +61,6 @@ const char *test_wsum_hess_cos() cmp_int_array(cos_node->wsum_hess->i, expected_i, 3)); free_expr(cos_node); - free_expr(x); return 0; } @@ -93,7 +91,6 @@ const char *test_wsum_hess_tan() cmp_int_array(tan_node->wsum_hess->i, expected_i, 3)); free_expr(tan_node); - free_expr(x); return 0; } diff --git a/tests/wsum_hess/elementwise/test_xexp.h b/tests/wsum_hess/elementwise/test_xexp.h index ef93bc1..0550571 100644 --- a/tests/wsum_hess/elementwise/test_xexp.h +++ b/tests/wsum_hess/elementwise/test_xexp.h @@ -34,7 +34,6 @@ const char *test_wsum_hess_xexp() cmp_int_array(xexp_node->wsum_hess->i, expected_i, 3)); free_expr(xexp_node); - free_expr(x); return 0; } diff --git a/tests/wsum_hess/test_hstack.h b/tests/wsum_hess/test_hstack.h index b819fef..2866e06 100644 --- a/tests/wsum_hess/test_hstack.h +++ b/tests/wsum_hess/test_hstack.h @@ -96,13 +96,7 @@ const char *test_wsum_hess_hstack() cmp_int_array(hstack_node->wsum_hess->i, expected_i, 9)); free_expr(hstack_node); - free_expr(sin_y); - free_expr(exp_x); - free_expr(log_z); - free_expr(log_x); - free_expr(y); - free_expr(z); - free_expr(x); + return 0; return 0; } @@ -213,13 +207,7 @@ const char *test_wsum_hess_hstack_matrix() cmp_int_array(hstack_node->wsum_hess->i, expected_i, 18)); free_expr(hstack_node); - free_expr(sin_y); - free_expr(exp_x); - free_expr(log_z); - free_expr(log_x); - free_expr(y); - free_expr(z); - free_expr(x); + return 0; return 0; } diff --git a/tests/wsum_hess/test_multiply.h b/tests/wsum_hess/test_multiply.h index 05e075f..b74c426 100644 --- a/tests/wsum_hess/test_multiply.h +++ b/tests/wsum_hess/test_multiply.h @@ -34,8 +34,6 @@ const char *test_wsum_hess_multiply_1() mu_assert("x array fails", cmp_double_array(node->wsum_hess->x, expected_x, 6)); free_expr(node); - free_expr(x); - free_expr(y); return 0; } @@ -105,9 +103,6 @@ const char *test_wsum_hess_multiply_sparse_random() /* Cleanup */ free_expr(mult_node); - free_expr(Ax_node); - free_expr(Bx_node); - free_expr(x); free_csr_matrix(A); free_csr_matrix(B); @@ -190,9 +185,6 @@ const char *test_wsum_hess_multiply_linear_ops() /* Cleanup */ free_expr(mult_node); - free_expr(Ax_node); - free_expr(Bx_node); - free_expr(x); free_csr_matrix(A); free_csr_matrix(B); @@ -228,7 +220,5 @@ const char *test_wsum_hess_multiply_2() mu_assert("x array fails", cmp_double_array(node->wsum_hess->x, expected_x, 6)); free_expr(node); - free_expr(x); - free_expr(y); return 0; } diff --git a/tests/wsum_hess/test_quad_form.h b/tests/wsum_hess/test_quad_form.h index 140c9da..e02233c 100644 --- a/tests/wsum_hess/test_quad_form.h +++ b/tests/wsum_hess/test_quad_form.h @@ -42,7 +42,6 @@ const char *test_wsum_hess_quad_form() mu_assert("x array fails", cmp_double_array(node->wsum_hess->x, expected_x, 10)); free_expr(node); - free_expr(x); free_csr_matrix(Q); return 0; } diff --git a/tests/wsum_hess/test_quad_over_lin.h b/tests/wsum_hess/test_quad_over_lin.h index 0d5dd62..94d5a6a 100644 --- a/tests/wsum_hess/test_quad_over_lin.h +++ b/tests/wsum_hess/test_quad_over_lin.h @@ -30,8 +30,6 @@ const char *test_wsum_hess_quad_over_lin_xy() mu_assert("x array fails", cmp_double_array(node->wsum_hess->x, expected_x, 10)); free_expr(node); - free_expr(x); - free_expr(y); return 0; } @@ -61,7 +59,5 @@ const char *test_wsum_hess_quad_over_lin_yx() mu_assert("x array fails", cmp_double_array(node->wsum_hess->x, expected_x, 10)); free_expr(node); - free_expr(x); - free_expr(y); return 0; } diff --git a/tests/wsum_hess/test_rel_entr.h b/tests/wsum_hess/test_rel_entr.h index 4934806..9bfafa4 100644 --- a/tests/wsum_hess/test_rel_entr.h +++ b/tests/wsum_hess/test_rel_entr.h @@ -40,8 +40,6 @@ const char *test_wsum_hess_rel_entr_1() mu_assert("x array fails", cmp_double_array(node->wsum_hess->x, expected_x, 12)); free_expr(node); - free_expr(x); - free_expr(y); return 0; } @@ -79,7 +77,5 @@ const char *test_wsum_hess_rel_entr_2() mu_assert("x array fails", cmp_double_array(node->wsum_hess->x, expected_x, 12)); free_expr(node); - free_expr(x); - free_expr(y); return 0; } diff --git a/tests/wsum_hess/test_sum.h b/tests/wsum_hess/test_sum.h index ee474ca..20387c6 100644 --- a/tests/wsum_hess/test_sum.h +++ b/tests/wsum_hess/test_sum.h @@ -45,10 +45,7 @@ const char *test_wsum_hess_sum_log_linear() cmp_int_array(sum_node->wsum_hess->i, expected_i, 4)); free_expr(sum_node); - free_expr(log_node); - free_expr(Ax_node); free_csr_matrix(A); - free_expr(x); return 0; } @@ -87,8 +84,6 @@ const char *test_wsum_hess_sum_log_axis0() cmp_int_array(sum_node->wsum_hess->i, expected_i, 6)); free_expr(sum_node); - free_expr(log_node); - free_expr(x_node); return 0; } @@ -127,8 +122,6 @@ const char *test_wsum_hess_sum_log_axis1() cmp_int_array(sum_node->wsum_hess->i, expected_i, 6)); free_expr(sum_node); - free_expr(log_node); - free_expr(x_node); return 0; }