From 03a3ce1fd28e21947e7698416ab3260908f815cb Mon Sep 17 00:00:00 2001 From: dance858 Date: Tue, 31 Mar 2026 06:38:45 -0700 Subject: [PATCH 1/2] move old code into old-code-folder --- include/affine.h | 2 - include/old-code/old_CSR.h | 29 ++ include/old-code/old_CSR_sum.h | 44 +++ include/old-code/old_affine.h | 9 + include/utils/CSC_Matrix.h | 4 +- include/utils/CSR_Matrix.h | 33 +-- include/utils/CSR_sum.h | 122 +++------ include/utils/mini_numpy.h | 27 +- src/affine/sum.c | 16 +- src/affine/trace.c | 8 +- src/bivariate_full_dom/matmul.c | 12 +- src/bivariate_full_dom/multiply.c | 11 +- src/elementwise_full_dom/common.c | 2 +- src/{affine => old-code}/linear_op.c | 5 +- src/old-code/old_CSR.c | 171 ++++++++++++ src/old-code/old_CSR_sum.c | 332 +++++++++++++++++++++++ src/other/quad_form.c | 4 +- src/problem.c | 4 +- src/utils/CSR_Matrix.c | 165 +----------- src/utils/CSR_sum.c | 383 ++------------------------- tests/all_tests.c | 1 + tests/utils/test_csr_matrix.h | 4 +- 22 files changed, 695 insertions(+), 693 deletions(-) create mode 100644 include/old-code/old_CSR.h create mode 100644 include/old-code/old_CSR_sum.h create mode 100644 include/old-code/old_affine.h rename src/{affine => old-code}/linear_op.c (96%) create mode 100644 src/old-code/old_CSR.c create mode 100644 src/old-code/old_CSR_sum.c diff --git a/include/affine.h b/include/affine.h index 379c1cc0..c51bc64f 100644 --- a/include/affine.h +++ b/include/affine.h @@ -22,8 +22,6 @@ #include "subexpr.h" #include "utils/CSR_Matrix.h" -expr *new_linear(expr *u, const CSR_Matrix *A, const double *b); - expr *new_add(expr *left, expr *right); expr *new_neg(expr *child); diff --git a/include/old-code/old_CSR.h b/include/old-code/old_CSR.h new file mode 100644 index 00000000..5ec1ad69 --- /dev/null +++ b/include/old-code/old_CSR.h @@ -0,0 +1,29 @@ +#ifndef OLD_CSR_H +#define OLD_CSR_H + +#include "utils/CSR_Matrix.h" + +/* Build (I_p kron A) = blkdiag(A, A, ..., A) of size (p*A->m) x (p*A->n) */ +CSR_Matrix *block_diag_repeat_csr(const CSR_Matrix *A, int p); + +/* Build (A kron I_p) of size (A->m * p) x (A->n * p) with nnz = A->nnz * p. */ +CSR_Matrix *kron_identity_csr(const CSR_Matrix *A, int p); + +/* Computes values of the row matrix C = z^T A (column indices must have been + pre-computed) and transposed matrix AT must be provided) */ +void Ax_csr_fill_values(const CSR_Matrix *AT, const double *z, CSR_Matrix *C); + +/* Insert value into CSR matrix A with just one row at col_idx. Assumes that A +has enough space and that A does not have an element at col_idx. It does update +nnz. */ +void csr_insert_value(CSR_Matrix *A, int col_idx, double value); + +/* Compute C = diag(d) * A where d is an array and A, C are CSR matrices + * d must have length m + * C must be pre-allocated with same dimensions as A */ +void diag_csr_mult(const double *d, const CSR_Matrix *A, CSR_Matrix *C); + +/* y = Ax, where y is returned as dense (no column offset) */ +void Ax_csr_wo_offset(const CSR_Matrix *A, const double *x, double *y); + +#endif /* OLD_CSR_H */ diff --git a/include/old-code/old_CSR_sum.h b/include/old-code/old_CSR_sum.h new file mode 100644 index 00000000..bae27d60 --- /dev/null +++ b/include/old-code/old_CSR_sum.h @@ -0,0 +1,44 @@ +#ifndef OLD_CSR_SUM_H +#define OLD_CSR_SUM_H + +#include "utils/CSR_Matrix.h" + +/* Compute C = A + B where A, B, C are CSR matrices + * A and B must have same dimensions + * C must be pre-allocated with sufficient nnz capacity. + * C must be different from A and B */ +void sum_csr_matrices(const CSR_Matrix *A, const CSR_Matrix *B, CSR_Matrix *C); + +/* Compute C = diag(d1) * A + diag(d2) * B where A, B, C are CSR matrices */ +void sum_scaled_csr_matrices(const CSR_Matrix *A, const CSR_Matrix *B, CSR_Matrix *C, + const double *d1, const double *d2); + +/* forward declaration */ +struct int_double_pair; + +/* Sum all rows of A into a single row matrix C */ +void sum_all_rows_csr(const CSR_Matrix *A, CSR_Matrix *C, + struct int_double_pair *pairs); + +/* Sum blocks of rows of A into a matrix C */ +void sum_block_of_rows_csr(const CSR_Matrix *A, CSR_Matrix *C, + struct int_double_pair *pairs, int row_block_size); + +/* Sum evenly spaced rows of A into a matrix C */ +void sum_evenly_spaced_rows_csr(const CSR_Matrix *A, CSR_Matrix *C, + struct int_double_pair *pairs, int row_spacing); + +/* Sum evenly spaced rows of A starting at offset into a row matrix C */ +void sum_spaced_rows_into_row_csr(const CSR_Matrix *A, CSR_Matrix *C, + struct int_double_pair *pairs, int offset, + int spacing); + +/* Fill values of summed rows using precomputed idx_map and sparsity of C */ +void sum_all_rows_csr_fill_values(const CSR_Matrix *A, CSR_Matrix *C, + const int *idx_map); + +/* Fill values of summed block rows using precomputed idx_map */ +void sum_block_of_rows_csr_fill_values(const CSR_Matrix *A, CSR_Matrix *C, + const int *idx_map); + +#endif /* OLD_CSR_SUM_H */ diff --git a/include/old-code/old_affine.h b/include/old-code/old_affine.h new file mode 100644 index 00000000..1ffa3669 --- /dev/null +++ b/include/old-code/old_affine.h @@ -0,0 +1,9 @@ +#ifndef OLD_AFFINE_H +#define OLD_AFFINE_H + +#include "expr.h" +#include "utils/CSR_Matrix.h" + +expr *new_linear(expr *u, const CSR_Matrix *A, const double *b); + +#endif /* OLD_AFFINE_H */ diff --git a/include/utils/CSC_Matrix.h b/include/utils/CSC_Matrix.h index 951b088d..82701204 100644 --- a/include/utils/CSC_Matrix.h +++ b/include/utils/CSC_Matrix.h @@ -23,10 +23,8 @@ typedef struct CSC_Matrix int nnz; } CSC_Matrix; -/* Allocate a new CSC matrix with given dimensions and nnz */ +/* constructor and destructor */ CSC_Matrix *new_csc_matrix(int m, int n, int nnz); - -/* Free a CSC matrix */ void free_csc_matrix(CSC_Matrix *matrix); /* Fill sparsity of C = A^T D A for diagonal D */ diff --git a/include/utils/CSR_Matrix.h b/include/utils/CSR_Matrix.h index df81839a..a6758c80 100644 --- a/include/utils/CSR_Matrix.h +++ b/include/utils/CSR_Matrix.h @@ -2,9 +2,6 @@ #define CSR_MATRIX_H #include -/* forward declaration */ -struct int_double_pair; - /* CSR (Compressed Sparse Row) Matrix Format * * For an m x n matrix with nnz nonzeros: @@ -37,37 +34,19 @@ CSR_Matrix *transpose(const CSR_Matrix *A, int *iwork); CSR_Matrix *AT_alloc(const CSR_Matrix *A, int *iwork); void AT_fill_values(const CSR_Matrix *A, CSR_Matrix *AT, int *iwork); -/* Build (I_p kron A) = blkdiag(A, A, ..., A) of size (p*A->m) x (p*A->n) */ -CSR_Matrix *block_diag_repeat_csr(const CSR_Matrix *A, int p); - -/* Build (A kron I_p) of size (A->m * p) x (A->n * p) with nnz = A->nnz * p. */ -CSR_Matrix *kron_identity_csr(const CSR_Matrix *A, int p); - -/* y = Ax, where y is returned as dense */ -void csr_matvec(const CSR_Matrix *A, const double *x, double *y, int col_offset); -void csr_matvec_wo_offset(const CSR_Matrix *A, const double *x, double *y); - -/* Computes values of the row matrix C = z^T A (column indices must have been - pre-computed) and transposed matrix AT must be provided) */ -void csr_matvec_fill_values(const CSR_Matrix *AT, const double *z, CSR_Matrix *C); - -/* Insert value into CSR matrix A with just one row at col_idx. Assumes that A -has enough space and that A does not have an element at col_idx. It does update -nnz. */ -void csr_insert_value(CSR_Matrix *A, int col_idx, double value); +/* computes dense y = Ax */ +void Ax_csr(const CSR_Matrix *A, const double *x, double *y, int col_offset); -/* Compute C = diag(d) * A where d is an array and A, C are CSR matrices - * d must have length m - * C must be pre-allocated with same dimensions as A */ -void diag_csr_mult(const double *d, const CSR_Matrix *A, CSR_Matrix *C); -void diag_csr_mult_fill_values(const double *d, const CSR_Matrix *A, CSR_Matrix *C); +/* fills values of C = diag(d) @ A */ +void DA_fill_values(const double *d, const CSR_Matrix *A, CSR_Matrix *C); -/* Count number of columns with nonzero entries */ +/* Count number of columns with nonzero entries in A and marks them in col_nz */ int count_nonzero_cols(const CSR_Matrix *A, bool *col_nz); /* inserts 'idx' into array 'arr' in sorted order, and moves the other elements */ void insert_idx(int idx, int *arr, int len); +/* get value at position (row, col) in A */ double csr_get_value(const CSR_Matrix *A, int row, int col); /* Expand symmetric CSR matrix A to full matrix C. A is assumed to store diff --git a/include/utils/CSR_sum.h b/include/utils/CSR_sum.h index 063b0247..85fd334b 100644 --- a/include/utils/CSR_sum.h +++ b/include/utils/CSR_sum.h @@ -6,93 +6,55 @@ /* forward declaration */ struct int_double_pair; -/* Compute C = A + B where A, B, C are CSR matrices - * A and B must have same dimensions - * C must be pre-allocated with sufficient nnz capacity. - * C must be different from A and B */ -void sum_csr_matrices(const CSR_Matrix *A, const CSR_Matrix *B, CSR_Matrix *C); - -/* Compute sparsity pattern of A + B where A, B, C are CSR matrices. - * Fills C->p, C->i, and C->nnz; does not touch C->x. */ +/* Compute sparsity pattern of C = A + B (and sets C->nnz) */ void sum_csr_alloc(const CSR_Matrix *A, const CSR_Matrix *B, CSR_Matrix *C); -/* Fill only the values of C = A + B, assuming C's sparsity pattern (p and i) - * is already filled and matches the union of A and B per row. Does not modify - * C->p, C->i, or C->nnz. */ +/* Fills values of C = A + B (assuming C's sparsity pattern is set) */ void sum_csr_fill_values(const CSR_Matrix *A, const CSR_Matrix *B, CSR_Matrix *C); -/* Compute C = diag(d1) * A + diag(d2) * B where A, B, C are CSR matrices */ -void sum_scaled_csr_matrices(const CSR_Matrix *A, const CSR_Matrix *B, CSR_Matrix *C, - const double *d1, const double *d2); - -/* Fill only the values of C = diag(d1) * A + diag(d2) * B, assuming C's sparsity - * pattern (p and i) is already filled and matches the union of A and B per row. - * Does not modify C->p, C->i, or C->nnz. */ +/* Fills values of C = diag(d1) * A + diag(d2) * B (assuming C's sparsity is set)*/ void sum_scaled_csr_matrices_fill_values(const CSR_Matrix *A, const CSR_Matrix *B, CSR_Matrix *C, const double *d1, const double *d2); -/* Sum all rows of A into a single row matrix C */ -void sum_all_rows_csr(const CSR_Matrix *A, CSR_Matrix *C, - struct int_double_pair *pairs); - -/* iwork must have size max(C->n, A->nnz), and idx_map must have size A->nnz. */ -void sum_all_rows_csr_fill_sparsity_and_idx_map(const CSR_Matrix *A, CSR_Matrix *C, - int *iwork, int *idx_map); - -/* Fill values of summed rows using precomputed idx_map and sparsity of C */ -// void sum_all_rows_csr_fill_values(const CSR_Matrix *A, CSR_Matrix *C, -// const int *idx_map); - -/* Fill accumulator for summing rows using precomputed idx_map for each nnz of A. - Must memset accumulator to zero before calling. */ -void idx_map_accumulator(const CSR_Matrix *A, const int *idx_map, - double *accumulator); -void idx_map_accumulator_with_spacing(const CSR_Matrix *A, const int *idx_map, - double *accumulator, int spacing); - -/* Sum blocks of rows of A into a matrix C */ -void sum_block_of_rows_csr(const CSR_Matrix *A, CSR_Matrix *C, - struct int_double_pair *pairs, int row_block_size); - -/* Build sparsity and index map for summing blocks of rows. - * iwork must have size max(A->n, A->nnz), and idx_map must have size A->nnz. */ -void sum_block_of_rows_csr_fill_sparsity_and_idx_map(const CSR_Matrix *A, - CSR_Matrix *C, - int row_block_size, int *iwork, - int *idx_map); - -/* Sum evenly spaced rows of A into a matrix C */ -void sum_evenly_spaced_rows_csr(const CSR_Matrix *A, CSR_Matrix *C, - struct int_double_pair *pairs, int row_spacing); - -/* Build sparsity and index map for summing evenly spaced rows. - * iwork must have size max(A->n, A->nnz), and idx_map must have size A->nnz. */ -void sum_evenly_spaced_rows_csr_fill_sparsity_and_idx_map(const CSR_Matrix *A, - CSR_Matrix *C, - int row_spacing, - int *iwork, int *idx_map); - -/* Sum evenly spaced rows of A starting at offset into a row matrix C */ -void sum_spaced_rows_into_row_csr(const CSR_Matrix *A, CSR_Matrix *C, - struct int_double_pair *pairs, int offset, - int spacing); - -/* Fills the sparsity and index map for summing spaced rows into a row matrix */ -void sum_spaced_rows_into_row_csr_fill_sparsity_and_idx_map(const CSR_Matrix *A, - CSR_Matrix *C, - int spacing, int *iwork, - int *idx_map); - -/* 4-way sorted merge of CSR matrices A, B, C, D (same dimensions). - * Allocates and returns the output CSR with the union sparsity pattern. - * Allocates and fills idx_maps[0..3] (one per input, size input->nnz - * each) mapping each input entry to its position in the output. - * Caller owns the returned CSR and all 4 idx_map arrays. */ -CSR_Matrix *sum_4_csr_fill_sparsity_and_idx_maps(const CSR_Matrix *A, - const CSR_Matrix *B, - const CSR_Matrix *C, - const CSR_Matrix *D, - int *idx_maps[4]); +/* The following five functions are used for summing either more than two CSR + matrices or rows of CSR matrices. To implement the filling of values efficiently, + we compute an idx_map when we fill the sparsity pattern of the output matrix, + which maps each nonzero entry in the input matrix to its position in the output + matrix. This allows us to fill the values with a single pass of the output matrix + through the input matrices, without needing to search for the position of each + entry in the output matrix. So each idx_map should have size equal to the number + of nonzeros in the corresponding input matrix, and idx_map[j] should give the + index in the output matrix of the entry (in the value array of the output matrix) + corresponding to the j-th nonzero in the input matrix. + + Output matrix C, input matrix A, iwork->size = max(A->n, A->nnz) for the first + four functions. The last function allocates the output matrix and returns it. */ +// ------------------------------------------------------------------------------------ +void sum_all_rows_csr_alloc(const CSR_Matrix *A, CSR_Matrix *C, int *iwork, + int *idx_map); + +void sum_block_of_rows_csr_alloc(const CSR_Matrix *A, CSR_Matrix *C, + int row_block_size, int *iwork, int *idx_map); + +void sum_evenly_spaced_rows_csr_alloc(const CSR_Matrix *A, CSR_Matrix *C, + int row_spacing, int *iwork, int *idx_map); + +void sum_spaced_rows_into_row_csr_alloc(const CSR_Matrix *A, CSR_Matrix *C, + int spacing, int *iwork, int *idx_map); + +/* Compute sparsity pattern of out = A + B + C + D */ +CSR_Matrix *sum_4_csr_alloc(const CSR_Matrix *A, const CSR_Matrix *B, + const CSR_Matrix *C, const CSR_Matrix *D, + int *idx_maps[4]); +// ------------------------------------------------------------------------------------ + +/* Accumulates values from A according to map. Must memset to zero before calling. */ +void accumulator(const CSR_Matrix *A, const int *idx_map, double *out); + +/* Accumulates values from A according to map with spacing. Must memset to zero + * before calling. */ +void accumulator_with_spacing(const CSR_Matrix *A, const int *idx_map, double *out, + int spacing); #endif /* CSR_SUM_H */ diff --git a/include/utils/mini_numpy.h b/include/utils/mini_numpy.h index 931f5163..1ac1f0b4 100644 --- a/include/utils/mini_numpy.h +++ b/include/utils/mini_numpy.h @@ -1,36 +1,27 @@ #ifndef MINI_NUMPY_H #define MINI_NUMPY_H -/* Repeat each element of array 'a' 'repeats' times - * Example: a = [1, 2], len = 2, repeats = 3 - * result = [1, 1, 1, 2, 2, 2] - */ +/* Example: a = [1, 2], len = 2, repeats = 3, result = [1, 1, 1, 2, 2, 2] */ void repeat(double *result, const double *a, int len, int repeats); -/* Tile array 'a' 'tiles' times - * Example: a = [1, 2], len = 2, tiles = 3 - * result = [1, 2, 1, 2, 1, 2] - */ +/* Example: a = [1, 2], len = 2, tiles = 3, result = [1, 2, 1, 2, 1, 2] */ void tile_double(double *result, const double *a, int len, int tiles); void tile_int(int *result, const int *a, int len, int tiles); -/* Fill array with 'size' copies of 'value' - * Example: size = 5, value = 3.0 - * result = [3.0, 3.0, 3.0, 3.0, 3.0] - */ +/* Example: size = 5, value = 3.0, result = [3.0, 3.0, 3.0, 3.0, 3.0] */ void scaled_ones(double *result, int size, double value); /* Naive implementation of Z = X @ Y, X is m x k, Y is k x n, Z is m x n */ void mat_mat_mult(const double *X, const double *Y, double *Z, int m, int k, int n); -/* Compute v = (Y kron I_m) @ w where Y is k x n (col-major), w has - length m*n, and v has length m*k. Equivalently, reshape w as the - m x n matrix W (col-major) and compute v = vec(W @ Y^T). */ +/* Compute v = (Y kron I_m) @ w where Y is k x n (col-major), len(w) = m * n, and + len(v) = m * k. Equivalently, reshape w as the m x n matrix W (col-major) and + compute v = vec(W @ Y^T). */ void Y_kron_I_vec(int m, int k, int n, const double *Y, const double *w, double *v); -/* Compute v = (I_n kron X^T) @ w where X is m x k (col-major), w has - length m*n, and v has length k*n. Equivalently, reshape w as the - m x n matrix W (col-major) and compute v = vec(X^T @ W). */ +/* Compute v = (I_n kron X^T) @ w where X is m x k (col-major), len(w) = m * n, and + len(v) = k * n. Equivalently, reshape w as the m x n matrix W (col-major) and + compute v = vec(X^T @ W). */ void I_kron_XT_vec(int m, int k, int n, const double *X, const double *w, double *v); #endif /* MINI_NUMPY_H */ diff --git a/src/affine/sum.c b/src/affine/sum.c index 346075e3..288b0a18 100644 --- a/src/affine/sum.c +++ b/src/affine/sum.c @@ -99,19 +99,18 @@ static void jacobian_init_impl(expr *node) if (axis == -1) { - sum_all_rows_csr_fill_sparsity_and_idx_map( - x->jacobian, node->jacobian, node->work->iwork, snode->idx_map); + sum_all_rows_csr_alloc(x->jacobian, node->jacobian, node->work->iwork, + snode->idx_map); } else if (axis == 0) { - sum_block_of_rows_csr_fill_sparsity_and_idx_map( - x->jacobian, node->jacobian, x->d1, node->work->iwork, snode->idx_map); + sum_block_of_rows_csr_alloc(x->jacobian, node->jacobian, x->d1, + node->work->iwork, snode->idx_map); } else if (axis == 1) { - sum_evenly_spaced_rows_csr_fill_sparsity_and_idx_map( - x->jacobian, node->jacobian, node->size, node->work->iwork, - snode->idx_map); + sum_evenly_spaced_rows_csr_alloc(x->jacobian, node->jacobian, node->size, + node->work->iwork, snode->idx_map); } } @@ -125,8 +124,7 @@ static void eval_jacobian(expr *node) /* we have precomputed an idx map between the nonzeros of the child's jacobian and this node's jacobian, so we just accumulate accordingly */ memset(node->jacobian->x, 0, node->jacobian->nnz * sizeof(double)); - idx_map_accumulator(x->jacobian, ((sum_expr *) node)->idx_map, - node->jacobian->x); + accumulator(x->jacobian, ((sum_expr *) node)->idx_map, node->jacobian->x); } static void wsum_hess_init_impl(expr *node) diff --git a/src/affine/trace.c b/src/affine/trace.c index f68bc480..ab644760 100644 --- a/src/affine/trace.c +++ b/src/affine/trace.c @@ -77,8 +77,8 @@ static void jacobian_init_impl(expr *node) rows), idx_map[j] gives the position in C->x where the value from A->x[j] should be accumulated. */ tnode->idx_map = malloc(x->jacobian->nnz * sizeof(int)); - sum_spaced_rows_into_row_csr_fill_sparsity_and_idx_map( - A, node->jacobian, row_spacing, node->work->iwork, tnode->idx_map); + sum_spaced_rows_into_row_csr_alloc(A, node->jacobian, row_spacing, + node->work->iwork, tnode->idx_map); } static void eval_jacobian(expr *node) @@ -91,8 +91,8 @@ static void eval_jacobian(expr *node) /* local jacobian */ memset(node->jacobian->x, 0, node->jacobian->nnz * sizeof(double)); - idx_map_accumulator_with_spacing(x->jacobian, tnode->idx_map, node->jacobian->x, - x->d1 + 1); + accumulator_with_spacing(x->jacobian, tnode->idx_map, node->jacobian->x, + x->d1 + 1); } /* Placeholders for Hessian-related functions */ diff --git a/src/bivariate_full_dom/matmul.c b/src/bivariate_full_dom/matmul.c index 64b6d0bd..50450cda 100644 --- a/src/bivariate_full_dom/matmul.c +++ b/src/bivariate_full_dom/matmul.c @@ -434,8 +434,8 @@ static void wsum_hess_init_chain_rule(expr *node) /* sum the four terms and fill idx maps */ int *maps[4]; - node->wsum_hess = sum_4_csr_fill_sparsity_and_idx_maps( - mnode->C, mnode->CT, f->wsum_hess, g->wsum_hess, maps); + node->wsum_hess = + sum_4_csr_alloc(mnode->C, mnode->CT, f->wsum_hess, g->wsum_hess, maps); mnode->idx_map_C = maps[0]; mnode->idx_map_CT = maps[1]; mnode->idx_map_Hf = maps[2]; @@ -507,10 +507,10 @@ static void eval_wsum_hess_chain_rule(expr *node, const double *w) /* accumulate H = C + C^T + H_f + H_g */ memset(node->wsum_hess->x, 0, node->wsum_hess->nnz * sizeof(double)); - idx_map_accumulator(mnode->C, mnode->idx_map_C, node->wsum_hess->x); - idx_map_accumulator(mnode->CT, mnode->idx_map_CT, node->wsum_hess->x); - idx_map_accumulator(f->wsum_hess, mnode->idx_map_Hf, node->wsum_hess->x); - idx_map_accumulator(g->wsum_hess, mnode->idx_map_Hg, node->wsum_hess->x); + accumulator(mnode->C, mnode->idx_map_C, node->wsum_hess->x); + accumulator(mnode->CT, mnode->idx_map_CT, node->wsum_hess->x); + accumulator(f->wsum_hess, mnode->idx_map_Hf, node->wsum_hess->x); + accumulator(g->wsum_hess, mnode->idx_map_Hg, node->wsum_hess->x); } expr *new_matmul(expr *x, expr *y) diff --git a/src/bivariate_full_dom/multiply.c b/src/bivariate_full_dom/multiply.c index a77a88ca..289cd755 100644 --- a/src/bivariate_full_dom/multiply.c +++ b/src/bivariate_full_dom/multiply.c @@ -167,8 +167,7 @@ static void wsum_hess_init_impl(expr *node) fill index maps telling us where to accumulate each element of each matrix in the sum) */ int *maps[4]; - node->wsum_hess = sum_4_csr_fill_sparsity_and_idx_maps(C, CT, x->wsum_hess, - y->wsum_hess, maps); + node->wsum_hess = sum_4_csr_alloc(C, CT, x->wsum_hess, y->wsum_hess, maps); mul_node->idx_map_C = maps[0]; mul_node->idx_map_CT = maps[1]; mul_node->idx_map_Hx = maps[2]; @@ -257,10 +256,10 @@ static void eval_wsum_hess(expr *node, const double *w) // compute H = C + C^T + term2 + term3 // --------------------------------------------------------------- memset(node->wsum_hess->x, 0, node->wsum_hess->nnz * sizeof(double)); - idx_map_accumulator(C, mul_node->idx_map_C, node->wsum_hess->x); - idx_map_accumulator(CT, mul_node->idx_map_CT, node->wsum_hess->x); - idx_map_accumulator(x->wsum_hess, mul_node->idx_map_Hx, node->wsum_hess->x); - idx_map_accumulator(y->wsum_hess, mul_node->idx_map_Hy, node->wsum_hess->x); + accumulator(C, mul_node->idx_map_C, node->wsum_hess->x); + accumulator(CT, mul_node->idx_map_CT, node->wsum_hess->x); + accumulator(x->wsum_hess, mul_node->idx_map_Hx, node->wsum_hess->x); + accumulator(y->wsum_hess, mul_node->idx_map_Hy, node->wsum_hess->x); } } diff --git a/src/elementwise_full_dom/common.c b/src/elementwise_full_dom/common.c index 74280f90..73de379c 100644 --- a/src/elementwise_full_dom/common.c +++ b/src/elementwise_full_dom/common.c @@ -49,7 +49,7 @@ void eval_jacobian_elementwise(expr *node) node->local_jacobian(node, node->work->local_jac_diag); memcpy(node->work->dwork, node->work->local_jac_diag, node->size * sizeof(double)); - diag_csr_mult_fill_values(node->work->dwork, Jg, node->jacobian); + DA_fill_values(node->work->dwork, Jg, node->jacobian); } } diff --git a/src/affine/linear_op.c b/src/old-code/linear_op.c similarity index 96% rename from src/affine/linear_op.c rename to src/old-code/linear_op.c index f2bc846b..c1dfc12d 100644 --- a/src/affine/linear_op.c +++ b/src/old-code/linear_op.c @@ -15,7 +15,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "affine.h" +#include "old-code/old_affine.h" +#include "subexpr.h" #include "utils/CSR_Matrix.h" #include #include @@ -30,7 +31,7 @@ static void forward(expr *node, const double *u) node->left->forward(node->left, u); /* y = A * x (A is stored as node->jacobian) */ - csr_matvec(node->jacobian, x->value, node->value, x->var_id); + Ax_csr(node->jacobian, x->value, node->value, x->var_id); /* y += b (if offset exists) */ if (lin_node->b != NULL) diff --git a/src/old-code/old_CSR.c b/src/old-code/old_CSR.c new file mode 100644 index 00000000..3876fa66 --- /dev/null +++ b/src/old-code/old_CSR.c @@ -0,0 +1,171 @@ +/* + * Copyright 2026 Daniel Cederberg and William Zhang + * + * This file is part of the DNLP-differentiation-engine project. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "old-code/old_CSR.h" +#include "utils/CSR_Matrix.h" +#include +#include + +CSR_Matrix *block_diag_repeat_csr(const CSR_Matrix *A, int p) +{ + assert(p > 0); + + int m = A->m; + int n = A->n; + int nnz = A->nnz; + + CSR_Matrix *A_kron = new_csr_matrix(m * p, n * p, nnz * p); + + int nnz_cursor = 0; + for (int block = 0; block < p; block++) + { + int row_offset = block * m; + int col_offset = block * n; + + for (int row = 0; row < m; row++) + { + int dest_row = row_offset + row; + A_kron->p[dest_row] = nnz_cursor; + + for (int j = A->p[row]; j < A->p[row + 1]; j++) + { + A_kron->i[nnz_cursor] = A->i[j] + col_offset; + A_kron->x[nnz_cursor] = A->x[j]; + nnz_cursor++; + } + + A_kron->p[dest_row + 1] = nnz_cursor; + } + } + + return A_kron; +} + +CSR_Matrix *kron_identity_csr(const CSR_Matrix *A, int p) +{ + assert(p > 0); + + int m = A->m; + int n = A->n; + int nnz = A->nnz; + + CSR_Matrix *A_kron = new_csr_matrix(m * p, n * p, nnz * p); + + int nnz_cursor = 0; + for (int row_block = 0; row_block < m; row_block++) + { + for (int diag_idx = 0; diag_idx < p; diag_idx++) + { + int dest_row = row_block * p + diag_idx; + A_kron->p[dest_row] = nnz_cursor; + + /* Copy entries from row_block of A, adjusting column indices */ + for (int j = A->p[row_block]; j < A->p[row_block + 1]; j++) + { + int col_block = A->i[j]; + /* Column in result: col_block * p + diag_idx */ + A_kron->i[nnz_cursor] = col_block * p + diag_idx; + A_kron->x[nnz_cursor] = A->x[j]; + nnz_cursor++; + } + + A_kron->p[dest_row + 1] = nnz_cursor; + } + } + + return A_kron; +} + +void Ax_csr_fill_values(const CSR_Matrix *AT, const double *z, CSR_Matrix *C) +{ + int A_ncols = AT->m; + + for (int i = 0; i < A_ncols; i++) + { + double val = 0; + for (int j = AT->p[i]; j < AT->p[i + 1]; j++) + { + val += z[AT->i[j]] * AT->x[j]; + } + + if (AT->p[i + 1] - AT->p[i] == 0) continue; + + // find position in C + for (int k = 0; k < C->nnz; k++) + { + if (C->i[k] == i) + { + C->x[k] = val; + break; + } + } + } +} + +void csr_insert_value(CSR_Matrix *A, int col_idx, double value) +{ + assert(A->m == 1); + + for (int j = 0; j < A->nnz; j++) + { + assert(col_idx != A->i[j]); + + if (col_idx < A->i[j]) + { + /* move the rest of the elements */ + memmove(A->i + (j + 1), A->i + j, (A->nnz - j) * sizeof(int)); + memmove(A->x + (j + 1), A->x + j, (A->nnz - j) * sizeof(double)); + + /* insert new value */ + A->i[j] = col_idx; + A->x[j] = value; + A->nnz++; + return; + } + } + + /* if we get here it should be inserted in the end */ + A->i[A->nnz] = col_idx; + A->x[A->nnz] = value; + A->nnz++; +} + +void Ax_csr_wo_offset(const CSR_Matrix *A, const double *x, double *y) +{ + for (int row = 0; row < A->m; row++) + { + double sum = 0.0; + for (int j = A->p[row]; j < A->p[row + 1]; j++) + { + sum += A->x[j] * x[A->i[j]]; + } + y[row] = sum; + } +} + +void diag_csr_mult(const double *d, const CSR_Matrix *A, CSR_Matrix *C) +{ + copy_csr_matrix(A, C); + + for (int row = 0; row < C->m; row++) + { + for (int j = C->p[row]; j < C->p[row + 1]; j++) + { + C->x[j] *= d[row]; + } + } +} diff --git a/src/old-code/old_CSR_sum.c b/src/old-code/old_CSR_sum.c new file mode 100644 index 00000000..466907ac --- /dev/null +++ b/src/old-code/old_CSR_sum.c @@ -0,0 +1,332 @@ +/* + * Copyright 2026 Daniel Cederberg and William Zhang + * + * This file is part of the DNLP-differentiation-engine project. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "old-code/old_CSR_sum.h" +#include "utils/CSR_Matrix.h" +#include "utils/int_double_pair.h" +#include +#include +#include + +void sum_csr_matrices(const CSR_Matrix *A, const CSR_Matrix *B, CSR_Matrix *C) +{ + /* A and B must be different from C */ + assert(A != C && B != C); + + C->nnz = 0; + + for (int row = 0; row < A->m; row++) + { + int a_ptr = A->p[row]; + int a_end = A->p[row + 1]; + int b_ptr = B->p[row]; + int b_end = B->p[row + 1]; + C->p[row] = C->nnz; + + /* Merge while both have elements */ + while (a_ptr < a_end && b_ptr < b_end) + { + if (A->i[a_ptr] < B->i[b_ptr]) + { + C->i[C->nnz] = A->i[a_ptr]; + C->x[C->nnz] = A->x[a_ptr]; + a_ptr++; + } + else if (B->i[b_ptr] < A->i[a_ptr]) + { + C->i[C->nnz] = B->i[b_ptr]; + C->x[C->nnz] = B->x[b_ptr]; + b_ptr++; + } + else + { + C->i[C->nnz] = A->i[a_ptr]; + C->x[C->nnz] = A->x[a_ptr] + B->x[b_ptr]; + a_ptr++; + b_ptr++; + } + C->nnz++; + } + + /* Copy remaining elements from A */ + if (a_ptr < a_end) + { + int a_remaining = a_end - a_ptr; + memcpy(C->i + C->nnz, A->i + a_ptr, a_remaining * sizeof(int)); + memcpy(C->x + C->nnz, A->x + a_ptr, a_remaining * sizeof(double)); + C->nnz += a_remaining; + } + + /* Copy remaining elements from B */ + if (b_ptr < b_end) + { + int b_remaining = b_end - b_ptr; + memcpy(C->i + C->nnz, B->i + b_ptr, b_remaining * sizeof(int)); + memcpy(C->x + C->nnz, B->x + b_ptr, b_remaining * sizeof(double)); + C->nnz += b_remaining; + } + } + + C->p[A->m] = C->nnz; +} + +void sum_scaled_csr_matrices(const CSR_Matrix *A, const CSR_Matrix *B, CSR_Matrix *C, + const double *d1, const double *d2) +{ + C->nnz = 0; + + for (int row = 0; row < A->m; row++) + { + int a_ptr = A->p[row]; + int a_end = A->p[row + 1]; + int b_ptr = B->p[row]; + int b_end = B->p[row + 1]; + C->p[row] = C->nnz; + + /* Merge while both have elements */ + while (a_ptr < a_end && b_ptr < b_end) + { + if (A->i[a_ptr] < B->i[b_ptr]) + { + C->i[C->nnz] = A->i[a_ptr]; + C->x[C->nnz] = d1[row] * A->x[a_ptr]; + a_ptr++; + } + else if (B->i[b_ptr] < A->i[a_ptr]) + { + C->i[C->nnz] = B->i[b_ptr]; + C->x[C->nnz] = d2[row] * B->x[b_ptr]; + b_ptr++; + } + else + { + C->i[C->nnz] = A->i[a_ptr]; + C->x[C->nnz] = d1[row] * A->x[a_ptr] + d2[row] * B->x[b_ptr]; + a_ptr++; + b_ptr++; + } + C->nnz++; + } + + /* Copy remaining elements from A */ + if (a_ptr < a_end) + { + int a_remaining = a_end - a_ptr; + for (int j = 0; j < a_remaining; j++) + { + C->i[C->nnz + j] = A->i[a_ptr + j]; + C->x[C->nnz + j] = d1[row] * A->x[a_ptr + j]; + } + C->nnz += a_remaining; + } + + /* Copy remaining elements from B */ + if (b_ptr < b_end) + { + int b_remaining = b_end - b_ptr; + for (int j = 0; j < b_remaining; j++) + { + C->i[C->nnz + j] = B->i[b_ptr + j]; + C->x[C->nnz + j] = d2[row] * B->x[b_ptr + j]; + } + C->nnz += b_remaining; + } + } + + C->p[A->m] = C->nnz; +} + +void sum_all_rows_csr(const CSR_Matrix *A, CSR_Matrix *C, int_double_pair *pairs) +{ + assert(C->m == 1); + C->n = A->n; + C->p[0] = 0; + + /* copy A's values and column indices into pairs */ + set_int_double_pair_array(pairs, A->i, A->x, A->nnz); + + /* sort so columns are in order */ + sort_int_double_pair_array(pairs, A->nnz); + + /* merge entries with same columns and insert result in C */ + C->nnz = 0; + for (int j = 0; j < A->nnz;) + { + int current_col = pairs[j].col; + double sum_val = 0.0; + + /* sum all values with the same column */ + while (j < A->nnz && pairs[j].col == current_col) + { + sum_val += pairs[j].val; + j++; + } + + /* insert into C */ + C->i[C->nnz] = current_col; + C->x[C->nnz] = sum_val; + C->nnz++; + } + + C->p[1] = C->nnz; +} + +void sum_block_of_rows_csr(const CSR_Matrix *A, CSR_Matrix *C, + int_double_pair *pairs, int row_block_size) +{ + assert(A->m % row_block_size == 0); + int n_blocks = A->m / row_block_size; + assert(C->m == n_blocks); + C->n = A->n; + C->p[0] = 0; + + C->nnz = 0; + for (int block = 0; block < n_blocks; block++) + { + int start_row = block * row_block_size; + int end_row = start_row + row_block_size; + + /* copy block rows' values and column indices into pairs */ + int pair_idx = 0; + for (int row = start_row; row < end_row; row++) + { + for (int j = A->p[row]; j < A->p[row + 1]; j++) + { + pairs[pair_idx].col = A->i[j]; + pairs[pair_idx].val = A->x[j]; + pair_idx++; + } + } + + /* sort so columns are in order */ + sort_int_double_pair_array(pairs, pair_idx); + + /* merge entries with same columns and insert result in C */ + for (int j = 0; j < pair_idx;) + { + int current_col = pairs[j].col; + double sum_val = 0.0; + + /* sum all values with the same column */ + while (j < pair_idx && pairs[j].col == current_col) + { + sum_val += pairs[j].val; + j++; + } + + /* insert into C */ + C->i[C->nnz] = current_col; + C->x[C->nnz] = sum_val; + C->nnz++; + } + + C->p[block + 1] = C->nnz; + } +} + +void sum_evenly_spaced_rows_csr(const CSR_Matrix *A, CSR_Matrix *C, + int_double_pair *pairs, int row_spacing) +{ + assert(C->m == row_spacing); + C->n = A->n; + C->p[0] = 0; + C->nnz = 0; + + for (int C_row = 0; C_row < C->m; C_row++) + { + /* copy evenly spaced rows into pairs */ + int pair_idx = 0; + for (int row = C_row; row < A->m; row += row_spacing) + { + for (int j = A->p[row]; j < A->p[row + 1]; j++) + { + pairs[pair_idx].col = A->i[j]; + pairs[pair_idx].val = A->x[j]; + pair_idx++; + } + } + + /* sort so columns are in order */ + sort_int_double_pair_array(pairs, pair_idx); + + /* merge entries with same columns and insert result in C */ + for (int j = 0; j < pair_idx;) + { + int current_col = pairs[j].col; + double sum_val = 0.0; + + /* sum all values with the same column */ + while (j < pair_idx && pairs[j].col == current_col) + { + sum_val += pairs[j].val; + j++; + } + + /* insert into C */ + C->i[C->nnz] = current_col; + C->x[C->nnz] = sum_val; + C->nnz++; + } + + C->p[C_row + 1] = C->nnz; + } +} + +void sum_spaced_rows_into_row_csr(const CSR_Matrix *A, CSR_Matrix *C, + int_double_pair *pairs, int offset, int spacing) +{ + assert(C->m == 1); + C->n = A->n; + C->p[0] = 0; + C->nnz = 0; + + /* copy evenly spaced rows starting at offset into pairs */ + int pair_idx = 0; + for (int row = offset; row < A->m; row += spacing) + { + for (int j = A->p[row]; j < A->p[row + 1]; j++) + { + pairs[pair_idx].col = A->i[j]; + pairs[pair_idx].val = A->x[j]; + pair_idx++; + } + } + + /* sort so columns are in order */ + sort_int_double_pair_array(pairs, pair_idx); + + /* merge entries with same columns and insert result in C */ + for (int j = 0; j < pair_idx;) + { + int current_col = pairs[j].col; + double sum_val = 0.0; + + /* sum all values with the same column */ + while (j < pair_idx && pairs[j].col == current_col) + { + sum_val += pairs[j].val; + j++; + } + + /* insert into C */ + C->i[C->nnz] = current_col; + C->x[C->nnz] = sum_val; + C->nnz++; + } + + C->p[1] = C->nnz; +} diff --git a/src/other/quad_form.c b/src/other/quad_form.c index 78bd4368..03f91939 100644 --- a/src/other/quad_form.c +++ b/src/other/quad_form.c @@ -18,7 +18,7 @@ static void forward(expr *node, const double *u) /* local forward pass */ CSR_Matrix *Q = ((quad_form_expr *) node)->Q; - csr_matvec(Q, x->value, node->work->dwork, 0); + Ax_csr(Q, x->value, node->work->dwork, 0); node->value[0] = 0.0; for (int i = 0; i < x->size; i++) @@ -78,7 +78,7 @@ static void eval_jacobian(expr *node) if (x->var_id != NOT_A_VARIABLE) { /* jacobian = 2 * (Q @ x)^T */ - csr_matvec(Q, x->value, node->jacobian->x, 0); + Ax_csr(Q, x->value, node->jacobian->x, 0); cblas_dscal(x->size, 2.0, node->jacobian->x, 1); } else diff --git a/src/problem.c b/src/problem.c index c29ca89d..99b6fd17 100644 --- a/src/problem.c +++ b/src/problem.c @@ -455,13 +455,13 @@ void problem_hessian(problem *prob, double obj_w, const double *w) memset(H->x, 0, H->nnz * sizeof(double)); /* accumulate objective function */ - idx_map_accumulator(obj->wsum_hess, idx_map, H->x); + accumulator(obj->wsum_hess, idx_map, H->x); offset = obj->wsum_hess->nnz; /* accumulate constraint functions */ for (int i = 0; i < prob->n_constraints; i++) { - idx_map_accumulator(constrs[i]->wsum_hess, idx_map + offset, H->x); + accumulator(constrs[i]->wsum_hess, idx_map + offset, H->x); offset += constrs[i]->wsum_hess->nnz; } diff --git a/src/utils/CSR_Matrix.c b/src/utils/CSR_Matrix.c index b175ea12..5fa8eb21 100644 --- a/src/utils/CSR_Matrix.c +++ b/src/utils/CSR_Matrix.c @@ -74,77 +74,7 @@ void copy_csr_matrix(const CSR_Matrix *A, CSR_Matrix *C) memcpy(C->x, A->x, A->nnz * sizeof(double)); } -CSR_Matrix *block_diag_repeat_csr(const CSR_Matrix *A, int p) -{ - assert(p > 0); - - int m = A->m; - int n = A->n; - int nnz = A->nnz; - - CSR_Matrix *A_kron = new_csr_matrix(m * p, n * p, nnz * p); - - int nnz_cursor = 0; - for (int block = 0; block < p; block++) - { - int row_offset = block * m; - int col_offset = block * n; - - for (int row = 0; row < m; row++) - { - int dest_row = row_offset + row; - A_kron->p[dest_row] = nnz_cursor; - - for (int j = A->p[row]; j < A->p[row + 1]; j++) - { - A_kron->i[nnz_cursor] = A->i[j] + col_offset; - A_kron->x[nnz_cursor] = A->x[j]; - nnz_cursor++; - } - - A_kron->p[dest_row + 1] = nnz_cursor; - } - } - - return A_kron; -} - -CSR_Matrix *kron_identity_csr(const CSR_Matrix *A, int p) -{ - assert(p > 0); - - int m = A->m; - int n = A->n; - int nnz = A->nnz; - - CSR_Matrix *A_kron = new_csr_matrix(m * p, n * p, nnz * p); - - int nnz_cursor = 0; - for (int row_block = 0; row_block < m; row_block++) - { - for (int diag_idx = 0; diag_idx < p; diag_idx++) - { - int dest_row = row_block * p + diag_idx; - A_kron->p[dest_row] = nnz_cursor; - - /* Copy entries from row_block of A, adjusting column indices */ - for (int j = A->p[row_block]; j < A->p[row_block + 1]; j++) - { - int col_block = A->i[j]; - /* Column in result: col_block * p + diag_idx */ - A_kron->i[nnz_cursor] = col_block * p + diag_idx; - A_kron->x[nnz_cursor] = A->x[j]; - nnz_cursor++; - } - - A_kron->p[dest_row + 1] = nnz_cursor; - } - } - - return A_kron; -} - -void csr_matvec(const CSR_Matrix *A, const double *x, double *y, int col_offset) +void Ax_csr(const CSR_Matrix *A, const double *x, double *y, int col_offset) { for (int row = 0; row < A->m; row++) { @@ -157,19 +87,6 @@ void csr_matvec(const CSR_Matrix *A, const double *x, double *y, int col_offset) } } -void csr_matvec_wo_offset(const CSR_Matrix *A, const double *x, double *y) -{ - for (int row = 0; row < A->m; row++) - { - double sum = 0.0; - for (int j = A->p[row]; j < A->p[row + 1]; j++) - { - sum += A->x[j] * x[A->i[j]]; - } - y[row] = sum; - } -} - int count_nonzero_cols(const CSR_Matrix *A, bool *col_nz) { for (int row = 0; row < A->m; row++) @@ -202,20 +119,7 @@ void insert_idx(int idx, int *arr, int len) arr[j] = idx; } -void diag_csr_mult(const double *d, const CSR_Matrix *A, CSR_Matrix *C) -{ - copy_csr_matrix(A, C); - - for (int row = 0; row < C->m; row++) - { - for (int j = C->p[row]; j < C->p[row + 1]; j++) - { - C->x[j] *= d[row]; - } - } -} - -void diag_csr_mult_fill_values(const double *d, const CSR_Matrix *A, CSR_Matrix *C) +void DA_fill_values(const double *d, const CSR_Matrix *A, CSR_Matrix *C) { memcpy(C->x, A->x, A->nnz * sizeof(double)); @@ -228,34 +132,6 @@ void diag_csr_mult_fill_values(const double *d, const CSR_Matrix *A, CSR_Matrix } } -void csr_insert_value(CSR_Matrix *A, int col_idx, double value) -{ - assert(A->m == 1); - - for (int j = 0; j < A->nnz; j++) - { - assert(col_idx != A->i[j]); - - if (col_idx < A->i[j]) - { - /* move the rest of the elements */ - memmove(A->i + (j + 1), A->i + j, (A->nnz - j) * sizeof(int)); - memmove(A->x + (j + 1), A->x + j, (A->nnz - j) * sizeof(double)); - - /* insert new value */ - A->i[j] = col_idx; - A->x[j] = value; - A->nnz++; - return; - } - } - - /* if we get here it should be inserted in the end */ - A->i[A->nnz] = col_idx; - A->x[A->nnz] = value; - A->nnz++; -} - CSR_Matrix *transpose(const CSR_Matrix *A, int *iwork) { CSR_Matrix *AT = new_csr_matrix(A->n, A->m, A->nnz); @@ -364,43 +240,6 @@ void AT_fill_values(const CSR_Matrix *A, CSR_Matrix *AT, int *iwork) } } -/**/ -void csr_matvec_fill_values(const CSR_Matrix *AT, const double *z, CSR_Matrix *C) -{ - int A_ncols = AT->m; - - for (int i = 0; i < A_ncols; i++) - { - double val = 0; - for (int j = AT->p[i]; j < AT->p[i + 1]; j++) - { - val += z[AT->i[j]] * AT->x[j]; - } - - if (AT->p[i + 1] - AT->p[i] == 0) continue; - - // find position in C - for (int k = 0; k < C->nnz; k++) - { - if (C->i[k] == i) - { - C->x[k] = val; - break; - } - } - } -} - -// void csr_vecmat_sparse(const double *x, const CSR_Matrix *A, CSR_Matrix *C) -//{ -// memset(C->x, 0, C->nnz * sizeof(double)); -// C->nnz = 0; -// for (int j = 0; j < A->nnz; j++) -// { -// C->x[] -// } -// } - double csr_get_value(const CSR_Matrix *A, int row, int col) { for (int j = A->p[row]; j < A->p[row + 1]; j++) diff --git a/src/utils/CSR_sum.c b/src/utils/CSR_sum.c index 1f309067..8c3e5f6f 100644 --- a/src/utils/CSR_sum.c +++ b/src/utils/CSR_sum.c @@ -23,68 +23,6 @@ #include #include -void sum_csr_matrices(const CSR_Matrix *A, const CSR_Matrix *B, CSR_Matrix *C) -{ - /* A and B must be different from C */ - assert(A != C && B != C); - - C->nnz = 0; - - for (int row = 0; row < A->m; row++) - { - int a_ptr = A->p[row]; - int a_end = A->p[row + 1]; - int b_ptr = B->p[row]; - int b_end = B->p[row + 1]; - C->p[row] = C->nnz; - - /* Merge while both have elements */ - while (a_ptr < a_end && b_ptr < b_end) - { - if (A->i[a_ptr] < B->i[b_ptr]) - { - C->i[C->nnz] = A->i[a_ptr]; - C->x[C->nnz] = A->x[a_ptr]; - a_ptr++; - } - else if (B->i[b_ptr] < A->i[a_ptr]) - { - C->i[C->nnz] = B->i[b_ptr]; - C->x[C->nnz] = B->x[b_ptr]; - b_ptr++; - } - else - { - C->i[C->nnz] = A->i[a_ptr]; - C->x[C->nnz] = A->x[a_ptr] + B->x[b_ptr]; - a_ptr++; - b_ptr++; - } - C->nnz++; - } - - /* Copy remaining elements from A */ - if (a_ptr < a_end) - { - int a_remaining = a_end - a_ptr; - memcpy(C->i + C->nnz, A->i + a_ptr, a_remaining * sizeof(int)); - memcpy(C->x + C->nnz, A->x + a_ptr, a_remaining * sizeof(double)); - C->nnz += a_remaining; - } - - /* Copy remaining elements from B */ - if (b_ptr < b_end) - { - int b_remaining = b_end - b_ptr; - memcpy(C->i + C->nnz, B->i + b_ptr, b_remaining * sizeof(int)); - memcpy(C->x + C->nnz, B->x + b_ptr, b_remaining * sizeof(double)); - C->nnz += b_remaining; - } - } - - C->p[A->m] = C->nnz; -} - void sum_csr_alloc(const CSR_Matrix *A, const CSR_Matrix *B, CSR_Matrix *C) { /* A and B must be different from C */ @@ -208,165 +146,9 @@ void sum_scaled_csr_matrices_fill_values(const CSR_Matrix *A, const CSR_Matrix * } } -void sum_scaled_csr_matrices(const CSR_Matrix *A, const CSR_Matrix *B, CSR_Matrix *C, - const double *d1, const double *d2) -{ - C->nnz = 0; - - for (int row = 0; row < A->m; row++) - { - int a_ptr = A->p[row]; - int a_end = A->p[row + 1]; - int b_ptr = B->p[row]; - int b_end = B->p[row + 1]; - C->p[row] = C->nnz; - - /* Merge while both have elements */ - while (a_ptr < a_end && b_ptr < b_end) - { - if (A->i[a_ptr] < B->i[b_ptr]) - { - C->i[C->nnz] = A->i[a_ptr]; - C->x[C->nnz] = d1[row] * A->x[a_ptr]; - a_ptr++; - } - else if (B->i[b_ptr] < A->i[a_ptr]) - { - C->i[C->nnz] = B->i[b_ptr]; - C->x[C->nnz] = d2[row] * B->x[b_ptr]; - b_ptr++; - } - else - { - C->i[C->nnz] = A->i[a_ptr]; - C->x[C->nnz] = d1[row] * A->x[a_ptr] + d2[row] * B->x[b_ptr]; - a_ptr++; - b_ptr++; - } - C->nnz++; - } - - /* Copy remaining elements from A */ - if (a_ptr < a_end) - { - int a_remaining = a_end - a_ptr; - for (int j = 0; j < a_remaining; j++) - { - C->i[C->nnz + j] = A->i[a_ptr + j]; - C->x[C->nnz + j] = d1[row] * A->x[a_ptr + j]; - } - C->nnz += a_remaining; - } - - /* Copy remaining elements from B */ - if (b_ptr < b_end) - { - int b_remaining = b_end - b_ptr; - for (int j = 0; j < b_remaining; j++) - { - C->i[C->nnz + j] = B->i[b_ptr + j]; - C->x[C->nnz + j] = d2[row] * B->x[b_ptr + j]; - } - C->nnz += b_remaining; - } - } - - C->p[A->m] = C->nnz; -} - -void sum_all_rows_csr(const CSR_Matrix *A, CSR_Matrix *C, int_double_pair *pairs) -{ - assert(C->m == 1); - C->n = A->n; - C->p[0] = 0; - - /* copy A's values and column indices into pairs */ - set_int_double_pair_array(pairs, A->i, A->x, A->nnz); - - /* sort so columns are in order */ - sort_int_double_pair_array(pairs, A->nnz); - - /* merge entries with same columns and insert result in C */ - C->nnz = 0; - for (int j = 0; j < A->nnz;) - { - int current_col = pairs[j].col; - double sum_val = 0.0; - - /* sum all values with the same column */ - while (j < A->nnz && pairs[j].col == current_col) - { - sum_val += pairs[j].val; - j++; - } - - /* insert into C */ - C->i[C->nnz] = current_col; - C->x[C->nnz] = sum_val; - C->nnz++; - } - - C->p[1] = C->nnz; -} - -void sum_block_of_rows_csr(const CSR_Matrix *A, CSR_Matrix *C, - int_double_pair *pairs, int row_block_size) -{ - assert(A->m % row_block_size == 0); - int n_blocks = A->m / row_block_size; - assert(C->m == n_blocks); - C->n = A->n; - C->p[0] = 0; - - C->nnz = 0; - for (int block = 0; block < n_blocks; block++) - { - int start_row = block * row_block_size; - int end_row = start_row + row_block_size; - - /* copy block rows' values and column indices into pairs */ - int pair_idx = 0; - for (int row = start_row; row < end_row; row++) - { - for (int j = A->p[row]; j < A->p[row + 1]; j++) - { - pairs[pair_idx].col = A->i[j]; - pairs[pair_idx].val = A->x[j]; - pair_idx++; - } - } - - /* sort so columns are in order */ - sort_int_double_pair_array(pairs, pair_idx); - - /* merge entries with same columns and insert result in C */ - for (int j = 0; j < pair_idx;) - { - int current_col = pairs[j].col; - double sum_val = 0.0; - - /* sum all values with the same column */ - while (j < pair_idx && pairs[j].col == current_col) - { - sum_val += pairs[j].val; - j++; - } - - /* insert into C */ - C->i[C->nnz] = current_col; - C->x[C->nnz] = sum_val; - C->nnz++; - } - - C->p[block + 1] = C->nnz; - } -} - /* iwork must have size max(A->n, A->nnz), and idx_map must have size A->nnz */ -void sum_block_of_rows_csr_fill_sparsity_and_idx_map(const CSR_Matrix *A, - CSR_Matrix *C, - int row_block_size, int *iwork, - int *idx_map) +void sum_block_of_rows_csr_alloc(const CSR_Matrix *A, CSR_Matrix *C, + int row_block_size, int *iwork, int *idx_map) { assert(A->m % row_block_size == 0); int n_blocks = A->m / row_block_size; @@ -436,75 +218,9 @@ void sum_block_of_rows_csr_fill_sparsity_and_idx_map(const CSR_Matrix *A, } } -/* -void sum_block_of_rows_csr_fill_values(const CSR_Matrix *A, CSR_Matrix *C, - const int *idx_map) -{ - memset(C->x, 0, C->nnz * sizeof(double)); - - for (int row = 0; row < A->m; row++) - { - for (int j = A->p[row]; j < A->p[row + 1]; j++) - { - C->x[idx_map[j]] += A->x[j]; - } - } -} -*/ - -void sum_evenly_spaced_rows_csr(const CSR_Matrix *A, CSR_Matrix *C, - struct int_double_pair *pairs, int row_spacing) -{ - assert(C->m == row_spacing); - C->n = A->n; - C->p[0] = 0; - C->nnz = 0; - - for (int C_row = 0; C_row < C->m; C_row++) - { - /* copy evenly spaced rows into pairs */ - int pair_idx = 0; - for (int row = C_row; row < A->m; row += row_spacing) - { - for (int j = A->p[row]; j < A->p[row + 1]; j++) - { - pairs[pair_idx].col = A->i[j]; - pairs[pair_idx].val = A->x[j]; - pair_idx++; - } - } - - /* sort so columns are in order */ - sort_int_double_pair_array(pairs, pair_idx); - - /* merge entries with same columns and insert result in C */ - for (int j = 0; j < pair_idx;) - { - int current_col = pairs[j].col; - double sum_val = 0.0; - - /* sum all values with the same column */ - while (j < pair_idx && pairs[j].col == current_col) - { - sum_val += pairs[j].val; - j++; - } - - /* insert into C */ - C->i[C->nnz] = current_col; - C->x[C->nnz] = sum_val; - C->nnz++; - } - - C->p[C_row + 1] = C->nnz; - } -} - /* iwork must have size max(A->n, A->nnz), and idx_map must have size A->nnz */ -void sum_evenly_spaced_rows_csr_fill_sparsity_and_idx_map(const CSR_Matrix *A, - CSR_Matrix *C, - int row_spacing, - int *iwork, int *idx_map) +void sum_evenly_spaced_rows_csr_alloc(const CSR_Matrix *A, CSR_Matrix *C, + int row_spacing, int *iwork, int *idx_map) { assert(C->m == row_spacing); C->n = A->n; @@ -568,77 +284,30 @@ void sum_evenly_spaced_rows_csr_fill_sparsity_and_idx_map(const CSR_Matrix *A, } } -void idx_map_accumulator(const CSR_Matrix *A, const int *idx_map, - double *accumulator) +void accumulator(const CSR_Matrix *A, const int *idx_map, double *out) { /* don't forget to initialize accumulator to 0 before calling this */ for (int j = 0; j < A->nnz; j++) { - accumulator[idx_map[j]] += A->x[j]; + out[idx_map[j]] += A->x[j]; } } -void idx_map_accumulator_with_spacing(const CSR_Matrix *A, const int *idx_map, - double *accumulator, int spacing) +void accumulator_with_spacing(const CSR_Matrix *A, const int *idx_map, double *out, + int spacing) { /* don't forget to initialze accumulator to 0 before calling this */ for (int row = 0; row < A->m; row += spacing) { for (int j = A->p[row]; j < A->p[row + 1]; j++) { - accumulator[idx_map[j]] += A->x[j]; - } - } -} - -void sum_spaced_rows_into_row_csr(const CSR_Matrix *A, CSR_Matrix *C, - struct int_double_pair *pairs, int offset, - int spacing) -{ - assert(C->m == 1); - C->n = A->n; - C->p[0] = 0; - C->nnz = 0; - - /* copy evenly spaced rows starting at offset into pairs */ - int pair_idx = 0; - for (int row = offset; row < A->m; row += spacing) - { - for (int j = A->p[row]; j < A->p[row + 1]; j++) - { - pairs[pair_idx].col = A->i[j]; - pairs[pair_idx].val = A->x[j]; - pair_idx++; + out[idx_map[j]] += A->x[j]; } } - - /* sort so columns are in order */ - sort_int_double_pair_array(pairs, pair_idx); - - /* merge entries with same columns and insert result in C */ - for (int j = 0; j < pair_idx;) - { - int current_col = pairs[j].col; - double sum_val = 0.0; - - /* sum all values with the same column */ - while (j < pair_idx && pairs[j].col == current_col) - { - sum_val += pairs[j].val; - j++; - } - - /* insert into C */ - C->i[C->nnz] = current_col; - C->x[C->nnz] = sum_val; - C->nnz++; - } - - C->p[1] = C->nnz; } -void sum_all_rows_csr_fill_sparsity_and_idx_map(const CSR_Matrix *A, CSR_Matrix *C, - int *iwork, int *idx_map) +void sum_all_rows_csr_alloc(const CSR_Matrix *A, CSR_Matrix *C, int *iwork, + int *idx_map) { // ------------------------------------------------------------------- // Build sparsity pattern of the summed row @@ -682,22 +351,6 @@ void sum_all_rows_csr_fill_sparsity_and_idx_map(const CSR_Matrix *A, CSR_Matrix } } -/* -void sum_all_rows_csr_fill_values(const CSR_Matrix *A, CSR_Matrix *C, - const int *idx_map) -{ - memset(C->x, 0, C->nnz * sizeof(double)); - - for (int row = 0; row < A->m; row++) - { - for (int j = A->p[row]; j < A->p[row + 1]; j++) - { - C->x[idx_map[j]] += A->x[j]; - } - } -} -*/ - /* * Sums evenly spaced rows from A into a single row in C and fills an index map. * A: input CSR matrix @@ -706,11 +359,9 @@ void sum_all_rows_csr_fill_values(const CSR_Matrix *A, CSR_Matrix *C, * iwork: workspace of size at least max(A->n, A->nnz) * idx_map: output index map, size at least A->nnz */ -CSR_Matrix *sum_4_csr_fill_sparsity_and_idx_maps(const CSR_Matrix *A, - const CSR_Matrix *B, - const CSR_Matrix *C, - const CSR_Matrix *D, - int *idx_maps[4]) +CSR_Matrix *sum_4_csr_alloc(const CSR_Matrix *A, const CSR_Matrix *B, + const CSR_Matrix *C, const CSR_Matrix *D, + int *idx_maps[4]) { const CSR_Matrix *inputs[4] = {A, B, C, D}; int m = A->m; @@ -778,10 +429,8 @@ CSR_Matrix *sum_4_csr_fill_sparsity_and_idx_maps(const CSR_Matrix *A, return out; } -void sum_spaced_rows_into_row_csr_fill_sparsity_and_idx_map(const CSR_Matrix *A, - CSR_Matrix *C, - int spacing, int *iwork, - int *idx_map) +void sum_spaced_rows_into_row_csr_alloc(const CSR_Matrix *A, CSR_Matrix *C, + int spacing, int *iwork, int *idx_map) { assert(C->m == 1); C->n = A->n; diff --git a/tests/all_tests.c b/tests/all_tests.c index c0042267..2bce8f3c 100644 --- a/tests/all_tests.c +++ b/tests/all_tests.c @@ -1,6 +1,7 @@ #include #include "minunit.h" +#include "old-code/old_affine.h" /* Include all test headers */ #ifndef PROFILE_ONLY diff --git a/tests/utils/test_csr_matrix.h b/tests/utils/test_csr_matrix.h index f6c95362..68e0128c 100644 --- a/tests/utils/test_csr_matrix.h +++ b/tests/utils/test_csr_matrix.h @@ -3,6 +3,8 @@ #include #include "minunit.h" +#include "old-code/old_CSR.h" +#include "old-code/old_CSR_sum.h" #include "test_helpers.h" #include "utils/CSR_Matrix.h" #include "utils/CSR_sum.h" @@ -187,7 +189,7 @@ const char *test_csr_vecmat_values_sparse(void) CSR_Matrix *AT = transpose(A, iwork); - csr_matvec_fill_values(AT, z, C); + Ax_csr_fill_values(AT, z, C); double Cx_correct[3] = {7.0, 22.0, 1.0}; From f13816e78804bd264056d01693bc415731d1e2f9 Mon Sep 17 00:00:00 2001 From: dance858 Date: Tue, 31 Mar 2026 06:52:54 -0700 Subject: [PATCH 2/2] new folder structure --- include/{ => atoms}/affine.h | 0 include/{ => atoms}/bivariate_full_dom.h | 0 .../{ => atoms}/bivariate_restricted_dom.h | 0 include/{ => atoms}/elementwise_full_dom.h | 0 .../{ => atoms}/elementwise_restricted_dom.h | 0 .../non_elementwise_full_dom.h} | 6 ++-- include/bivariate.h | 28 ------------------- src/{ => atoms}/affine/add.c | 2 +- src/{ => atoms}/affine/broadcast.c | 2 +- src/{ => atoms}/affine/const_scalar_mult.c | 2 +- src/{ => atoms}/affine/const_vector_mult.c | 2 +- src/{ => atoms}/affine/constant.c | 2 +- src/{ => atoms}/affine/diag_vec.c | 2 +- src/{ => atoms}/affine/hstack.c | 2 +- src/{ => atoms}/affine/index.c | 2 +- src/{ => atoms}/affine/left_matmul.c | 2 +- src/{ => atoms}/affine/neg.c | 2 +- src/{ => atoms}/affine/promote.c | 2 +- src/{ => atoms}/affine/reshape.c | 2 +- src/{ => atoms}/affine/right_matmul.c | 2 +- src/{ => atoms}/affine/sum.c | 2 +- src/{ => atoms}/affine/trace.c | 2 +- src/{ => atoms}/affine/transpose.c | 2 +- src/{ => atoms}/affine/variable.c | 2 +- src/{ => atoms}/affine/vstack.c | 2 +- src/{ => atoms}/bivariate_full_dom/matmul.c | 2 +- src/{ => atoms}/bivariate_full_dom/multiply.c | 2 +- .../bivariate_restricted_dom/quad_over_lin.c | 2 +- .../bivariate_restricted_dom/rel_entr.c | 2 +- .../rel_entr_scalar_vector.c | 2 +- .../rel_entr_vector_scalar.c | 2 +- src/{ => atoms}/elementwise_full_dom/common.c | 2 +- src/{ => atoms}/elementwise_full_dom/exp.c | 2 +- .../elementwise_full_dom/hyperbolic.c | 2 +- .../elementwise_full_dom/logistic.c | 2 +- .../elementwise_full_dom/normal_cdf.c | 2 +- src/{ => atoms}/elementwise_full_dom/power.c | 2 +- src/{ => atoms}/elementwise_full_dom/trig.c | 2 +- src/{ => atoms}/elementwise_full_dom/xexp.c | 2 +- .../elementwise_restricted_dom/atanh.c | 2 +- .../elementwise_restricted_dom/common.c | 2 +- .../elementwise_restricted_dom/entr.c | 2 +- .../elementwise_restricted_dom/log.c | 2 +- .../elementwise_restricted_dom/tan.c | 2 +- src/{ => atoms}/other/prod.c | 2 +- src/{ => atoms}/other/prod_axis_one.c | 2 +- src/{ => atoms}/other/prod_axis_zero.c | 2 +- src/{ => atoms}/other/quad_form.c | 2 +- tests/forward_pass/affine/test_add.h | 2 +- tests/forward_pass/affine/test_broadcast.h | 2 +- tests/forward_pass/affine/test_hstack.h | 6 ++-- .../affine/test_left_matmul_dense.h | 2 +- tests/forward_pass/affine/test_linear_op.h | 2 +- tests/forward_pass/affine/test_neg.h | 2 +- tests/forward_pass/affine/test_promote.h | 2 +- tests/forward_pass/affine/test_sum.h | 6 ++-- .../affine/test_variable_constant.h | 2 +- tests/forward_pass/affine/test_vstack.h | 6 ++-- .../bivariate_full_dom/test_matmul.h | 2 +- tests/forward_pass/composite/test_composite.h | 6 ++-- .../elementwise_full_dom/test_exp.h | 6 ++-- .../elementwise_full_dom/test_normal_cdf.h | 6 ++-- .../elementwise_restricted_dom/test_log.h | 6 ++-- tests/forward_pass/other/test_prod_axis_one.h | 4 +-- .../forward_pass/other/test_prod_axis_zero.h | 4 +-- tests/jacobian_tests/affine/test_broadcast.h | 2 +- .../affine/test_const_scalar_mult.h | 6 ++-- .../affine/test_const_vector_mult.h | 6 ++-- tests/jacobian_tests/affine/test_hstack.h | 6 ++-- tests/jacobian_tests/affine/test_index.h | 6 ++-- .../jacobian_tests/affine/test_left_matmul.h | 6 ++-- tests/jacobian_tests/affine/test_neg.h | 2 +- tests/jacobian_tests/affine/test_promote.h | 2 +- .../jacobian_tests/affine/test_right_matmul.h | 6 ++-- tests/jacobian_tests/affine/test_sum.h | 8 +++--- tests/jacobian_tests/affine/test_trace.h | 6 ++-- tests/jacobian_tests/affine/test_transpose.h | 2 +- tests/jacobian_tests/affine/test_vstack.h | 6 ++-- .../test_elementwise_mult.h | 4 +-- .../bivariate_full_dom/test_matmul.h | 2 +- .../test_quad_over_lin.h | 4 +-- .../bivariate_restricted_dom/test_rel_entr.h | 4 +-- .../test_rel_entr_scalar_vector.h | 2 +- .../test_rel_entr_vector_scalar.h | 2 +- .../composite/test_chain_rule_jacobian.h | 8 +++--- .../composite/test_composite_exp.h | 4 +-- .../elementwise_restricted_dom/test_log.h | 6 ++-- tests/jacobian_tests/other/test_prod.h | 4 +-- .../jacobian_tests/other/test_prod_axis_one.h | 4 +-- .../other/test_prod_axis_zero.h | 4 +-- tests/jacobian_tests/other/test_quad_form.h | 4 +-- tests/numerical_diff/test_numerical_diff.h | 4 +-- tests/problem/test_problem.h | 6 ++-- tests/profiling/profile_left_matmul.h | 6 ++-- tests/wsum_hess/affine/test_broadcast.h | 6 ++-- .../wsum_hess/affine/test_const_scalar_mult.h | 6 ++-- .../wsum_hess/affine/test_const_vector_mult.h | 6 ++-- tests/wsum_hess/affine/test_hstack.h | 6 ++-- tests/wsum_hess/affine/test_index.h | 6 ++-- tests/wsum_hess/affine/test_left_matmul.h | 6 ++-- tests/wsum_hess/affine/test_right_matmul.h | 6 ++-- tests/wsum_hess/affine/test_sum.h | 6 ++-- tests/wsum_hess/affine/test_trace.h | 6 ++-- tests/wsum_hess/affine/test_transpose.h | 2 +- tests/wsum_hess/affine/test_vstack.h | 6 ++-- .../bivariate_full_dom/test_matmul.h | 2 +- .../bivariate_full_dom/test_multiply.h | 4 +-- .../test_quad_over_lin.h | 4 +-- .../bivariate_restricted_dom/test_rel_entr.h | 4 +-- .../test_rel_entr_scalar_vector.h | 2 +- .../test_rel_entr_vector_scalar.h | 2 +- .../composite/test_chain_rule_wsum_hess.h | 8 +++--- .../wsum_hess/elementwise_full_dom/test_exp.h | 6 ++-- .../elementwise_full_dom/test_hyperbolic.h | 6 ++-- .../elementwise_full_dom/test_logistic.h | 6 ++-- .../elementwise_full_dom/test_power.h | 6 ++-- .../elementwise_full_dom/test_trig.h | 6 ++-- .../elementwise_full_dom/test_xexp.h | 6 ++-- .../elementwise_restricted_dom/test_entr.h | 6 ++-- .../elementwise_restricted_dom/test_log.h | 6 ++-- tests/wsum_hess/other/test_prod.h | 2 +- tests/wsum_hess/other/test_prod_axis_one.h | 2 +- tests/wsum_hess/other/test_prod_axis_zero.h | 2 +- tests/wsum_hess/other/test_quad_form.h | 4 +-- 124 files changed, 216 insertions(+), 244 deletions(-) rename include/{ => atoms}/affine.h (100%) rename include/{ => atoms}/bivariate_full_dom.h (100%) rename include/{ => atoms}/bivariate_restricted_dom.h (100%) rename include/{ => atoms}/elementwise_full_dom.h (100%) rename include/{ => atoms}/elementwise_restricted_dom.h (100%) rename include/{other.h => atoms/non_elementwise_full_dom.h} (90%) delete mode 100644 include/bivariate.h rename src/{ => atoms}/affine/add.c (99%) rename src/{ => atoms}/affine/broadcast.c (99%) rename src/{ => atoms}/affine/const_scalar_mult.c (99%) rename src/{ => atoms}/affine/const_vector_mult.c (99%) rename src/{ => atoms}/affine/constant.c (98%) rename src/{ => atoms}/affine/diag_vec.c (99%) rename src/{ => atoms}/affine/hstack.c (99%) rename src/{ => atoms}/affine/index.c (99%) rename src/{ => atoms}/affine/left_matmul.c (99%) rename src/{ => atoms}/affine/neg.c (99%) rename src/{ => atoms}/affine/promote.c (99%) rename src/{ => atoms}/affine/reshape.c (98%) rename src/{ => atoms}/affine/right_matmul.c (98%) rename src/{ => atoms}/affine/sum.c (99%) rename src/{ => atoms}/affine/trace.c (99%) rename src/{ => atoms}/affine/transpose.c (99%) rename src/{ => atoms}/affine/variable.c (98%) rename src/{ => atoms}/affine/vstack.c (98%) rename src/{ => atoms}/bivariate_full_dom/matmul.c (99%) rename src/{ => atoms}/bivariate_full_dom/multiply.c (99%) rename src/{ => atoms}/bivariate_restricted_dom/quad_over_lin.c (99%) rename src/{ => atoms}/bivariate_restricted_dom/rel_entr.c (99%) rename src/{ => atoms}/bivariate_restricted_dom/rel_entr_scalar_vector.c (99%) rename src/{ => atoms}/bivariate_restricted_dom/rel_entr_vector_scalar.c (99%) rename src/{ => atoms}/elementwise_full_dom/common.c (99%) rename src/{ => atoms}/elementwise_full_dom/exp.c (95%) rename src/{ => atoms}/elementwise_full_dom/hyperbolic.c (98%) rename src/{ => atoms}/elementwise_full_dom/logistic.c (97%) rename src/{ => atoms}/elementwise_full_dom/normal_cdf.c (96%) rename src/{ => atoms}/elementwise_full_dom/power.c (96%) rename src/{ => atoms}/elementwise_full_dom/trig.c (97%) rename src/{ => atoms}/elementwise_full_dom/xexp.c (95%) rename src/{ => atoms}/elementwise_restricted_dom/atanh.c (95%) rename src/{ => atoms}/elementwise_restricted_dom/common.c (96%) rename src/{ => atoms}/elementwise_restricted_dom/entr.c (94%) rename src/{ => atoms}/elementwise_restricted_dom/log.c (94%) rename src/{ => atoms}/elementwise_restricted_dom/tan.c (95%) rename src/{ => atoms}/other/prod.c (99%) rename src/{ => atoms}/other/prod_axis_one.c (99%) rename src/{ => atoms}/other/prod_axis_zero.c (99%) rename src/{ => atoms}/other/quad_form.c (99%) diff --git a/include/affine.h b/include/atoms/affine.h similarity index 100% rename from include/affine.h rename to include/atoms/affine.h diff --git a/include/bivariate_full_dom.h b/include/atoms/bivariate_full_dom.h similarity index 100% rename from include/bivariate_full_dom.h rename to include/atoms/bivariate_full_dom.h diff --git a/include/bivariate_restricted_dom.h b/include/atoms/bivariate_restricted_dom.h similarity index 100% rename from include/bivariate_restricted_dom.h rename to include/atoms/bivariate_restricted_dom.h diff --git a/include/elementwise_full_dom.h b/include/atoms/elementwise_full_dom.h similarity index 100% rename from include/elementwise_full_dom.h rename to include/atoms/elementwise_full_dom.h diff --git a/include/elementwise_restricted_dom.h b/include/atoms/elementwise_restricted_dom.h similarity index 100% rename from include/elementwise_restricted_dom.h rename to include/atoms/elementwise_restricted_dom.h diff --git a/include/other.h b/include/atoms/non_elementwise_full_dom.h similarity index 90% rename from include/other.h rename to include/atoms/non_elementwise_full_dom.h index 5088ee1f..c1f7b05a 100644 --- a/include/other.h +++ b/include/atoms/non_elementwise_full_dom.h @@ -15,8 +15,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef OTHER_H -#define OTHER_H +#ifndef NON_ELEMENTWISE_FULL_DOM_H +#define NON_ELEMENTWISE_FULL_DOM_H #include "expr.h" #include "subexpr.h" @@ -33,4 +33,4 @@ expr *new_prod_axis_zero(expr *child); /* product of entries along axis=1 (rowwise products) */ expr *new_prod_axis_one(expr *child); -#endif /* OTHER_H */ +#endif /* NON_ELEMENTWISE_FULL_DOM_H */ diff --git a/include/bivariate.h b/include/bivariate.h deleted file mode 100644 index 977ac2a8..00000000 --- a/include/bivariate.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2026 Daniel Cederberg and William Zhang - * - * This file is part of the DNLP-differentiation-engine project. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef BIVARIATE_H -#define BIVARIATE_H - -/* Compatibility header — includes all bivariate-related declarations. - * Prefer including the specific header directly: - * affine.h, bivariate_full_dom.h, bivariate_restricted_dom.h */ -#include "affine.h" -#include "bivariate_full_dom.h" -#include "bivariate_restricted_dom.h" - -#endif /* BIVARIATE_H */ diff --git a/src/affine/add.c b/src/atoms/affine/add.c similarity index 99% rename from src/affine/add.c rename to src/atoms/affine/add.c index bd86da43..59b62239 100644 --- a/src/affine/add.c +++ b/src/atoms/affine/add.c @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "affine.h" +#include "atoms/affine.h" #include "utils/CSR_sum.h" #include #include diff --git a/src/affine/broadcast.c b/src/atoms/affine/broadcast.c similarity index 99% rename from src/affine/broadcast.c rename to src/atoms/affine/broadcast.c index cc7e6406..9e3ddae7 100644 --- a/src/affine/broadcast.c +++ b/src/atoms/affine/broadcast.c @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "affine.h" +#include "atoms/affine.h" #include "subexpr.h" #include "utils/mini_numpy.h" #include diff --git a/src/affine/const_scalar_mult.c b/src/atoms/affine/const_scalar_mult.c similarity index 99% rename from src/affine/const_scalar_mult.c rename to src/atoms/affine/const_scalar_mult.c index 0c81aff9..abc4651a 100644 --- a/src/affine/const_scalar_mult.c +++ b/src/atoms/affine/const_scalar_mult.c @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "affine.h" +#include "atoms/affine.h" #include "subexpr.h" #include #include diff --git a/src/affine/const_vector_mult.c b/src/atoms/affine/const_vector_mult.c similarity index 99% rename from src/affine/const_vector_mult.c rename to src/atoms/affine/const_vector_mult.c index ad7c81e3..3b6346eb 100644 --- a/src/affine/const_vector_mult.c +++ b/src/atoms/affine/const_vector_mult.c @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "affine.h" +#include "atoms/affine.h" #include "subexpr.h" #include #include diff --git a/src/affine/constant.c b/src/atoms/affine/constant.c similarity index 98% rename from src/affine/constant.c rename to src/atoms/affine/constant.c index b2764f3a..b7a5bfc5 100644 --- a/src/affine/constant.c +++ b/src/atoms/affine/constant.c @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "affine.h" +#include "atoms/affine.h" #include #include diff --git a/src/affine/diag_vec.c b/src/atoms/affine/diag_vec.c similarity index 99% rename from src/affine/diag_vec.c rename to src/atoms/affine/diag_vec.c index 05404d18..0c887ddb 100644 --- a/src/affine/diag_vec.c +++ b/src/atoms/affine/diag_vec.c @@ -17,7 +17,7 @@ */ // SPDX-License-Identifier: Apache-2.0 -#include "affine.h" +#include "atoms/affine.h" #include #include #include diff --git a/src/affine/hstack.c b/src/atoms/affine/hstack.c similarity index 99% rename from src/affine/hstack.c rename to src/atoms/affine/hstack.c index 92f99ad2..1be5fb9e 100644 --- a/src/affine/hstack.c +++ b/src/atoms/affine/hstack.c @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "affine.h" +#include "atoms/affine.h" #include "utils/CSR_sum.h" #include #include diff --git a/src/affine/index.c b/src/atoms/affine/index.c similarity index 99% rename from src/affine/index.c rename to src/atoms/affine/index.c index 70fd11da..57b8af77 100644 --- a/src/affine/index.c +++ b/src/atoms/affine/index.c @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "affine.h" +#include "atoms/affine.h" #include "subexpr.h" #include #include diff --git a/src/affine/left_matmul.c b/src/atoms/affine/left_matmul.c similarity index 99% rename from src/affine/left_matmul.c rename to src/atoms/affine/left_matmul.c index 4067e65f..ec7e0821 100644 --- a/src/affine/left_matmul.c +++ b/src/atoms/affine/left_matmul.c @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "affine.h" +#include "atoms/affine.h" #include "subexpr.h" #include "utils/dense_matrix.h" #include diff --git a/src/affine/neg.c b/src/atoms/affine/neg.c similarity index 99% rename from src/affine/neg.c rename to src/atoms/affine/neg.c index 2c86267f..3bc4cbec 100644 --- a/src/affine/neg.c +++ b/src/atoms/affine/neg.c @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "affine.h" +#include "atoms/affine.h" #include #include #include diff --git a/src/affine/promote.c b/src/atoms/affine/promote.c similarity index 99% rename from src/affine/promote.c rename to src/atoms/affine/promote.c index ddad1e79..61bd2329 100644 --- a/src/affine/promote.c +++ b/src/atoms/affine/promote.c @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "affine.h" +#include "atoms/affine.h" #include #include #include diff --git a/src/affine/reshape.c b/src/atoms/affine/reshape.c similarity index 98% rename from src/affine/reshape.c rename to src/atoms/affine/reshape.c index 2fb5f600..1444724b 100644 --- a/src/affine/reshape.c +++ b/src/atoms/affine/reshape.c @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "affine.h" +#include "atoms/affine.h" #include #include #include diff --git a/src/affine/right_matmul.c b/src/atoms/affine/right_matmul.c similarity index 98% rename from src/affine/right_matmul.c rename to src/atoms/affine/right_matmul.c index f3740a9f..723086e9 100644 --- a/src/affine/right_matmul.c +++ b/src/atoms/affine/right_matmul.c @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "affine.h" +#include "atoms/affine.h" #include "utils/CSR_Matrix.h" #include diff --git a/src/affine/sum.c b/src/atoms/affine/sum.c similarity index 99% rename from src/affine/sum.c rename to src/atoms/affine/sum.c index 288b0a18..bdd71405 100644 --- a/src/affine/sum.c +++ b/src/atoms/affine/sum.c @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "affine.h" +#include "atoms/affine.h" #include "utils/CSR_sum.h" #include "utils/int_double_pair.h" #include "utils/mini_numpy.h" diff --git a/src/affine/trace.c b/src/atoms/affine/trace.c similarity index 99% rename from src/affine/trace.c rename to src/atoms/affine/trace.c index ab644760..7a2f0456 100644 --- a/src/affine/trace.c +++ b/src/atoms/affine/trace.c @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "affine.h" +#include "atoms/affine.h" #include "utils/CSR_sum.h" #include "utils/int_double_pair.h" #include "utils/utils.h" diff --git a/src/affine/transpose.c b/src/atoms/affine/transpose.c similarity index 99% rename from src/affine/transpose.c rename to src/atoms/affine/transpose.c index 67e53339..56b73268 100644 --- a/src/affine/transpose.c +++ b/src/atoms/affine/transpose.c @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "affine.h" +#include "atoms/affine.h" #include #include #include diff --git a/src/affine/variable.c b/src/atoms/affine/variable.c similarity index 98% rename from src/affine/variable.c rename to src/atoms/affine/variable.c index 0fd944d3..23844d1f 100644 --- a/src/affine/variable.c +++ b/src/atoms/affine/variable.c @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "affine.h" +#include "atoms/affine.h" #include #include diff --git a/src/affine/vstack.c b/src/atoms/affine/vstack.c similarity index 98% rename from src/affine/vstack.c rename to src/atoms/affine/vstack.c index 6fcfbd0b..8f726309 100644 --- a/src/affine/vstack.c +++ b/src/atoms/affine/vstack.c @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "affine.h" +#include "atoms/affine.h" #include #include diff --git a/src/bivariate_full_dom/matmul.c b/src/atoms/bivariate_full_dom/matmul.c similarity index 99% rename from src/bivariate_full_dom/matmul.c rename to src/atoms/bivariate_full_dom/matmul.c index 50450cda..cfe3ceb8 100644 --- a/src/bivariate_full_dom/matmul.c +++ b/src/atoms/bivariate_full_dom/matmul.c @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "bivariate_full_dom.h" +#include "atoms/bivariate_full_dom.h" #include "subexpr.h" #include "utils/CSC_Matrix.h" #include "utils/CSR_Matrix.h" diff --git a/src/bivariate_full_dom/multiply.c b/src/atoms/bivariate_full_dom/multiply.c similarity index 99% rename from src/bivariate_full_dom/multiply.c rename to src/atoms/bivariate_full_dom/multiply.c index 289cd755..d1e2a6f2 100644 --- a/src/bivariate_full_dom/multiply.c +++ b/src/atoms/bivariate_full_dom/multiply.c @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "bivariate_full_dom.h" +#include "atoms/bivariate_full_dom.h" #include "subexpr.h" #include "utils/CSR_sum.h" #include diff --git a/src/bivariate_restricted_dom/quad_over_lin.c b/src/atoms/bivariate_restricted_dom/quad_over_lin.c similarity index 99% rename from src/bivariate_restricted_dom/quad_over_lin.c rename to src/atoms/bivariate_restricted_dom/quad_over_lin.c index bc8ea052..4ad795a1 100644 --- a/src/bivariate_restricted_dom/quad_over_lin.c +++ b/src/atoms/bivariate_restricted_dom/quad_over_lin.c @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "bivariate_restricted_dom.h" +#include "atoms/bivariate_restricted_dom.h" #include "subexpr.h" #include "utils/CSC_Matrix.h" #include diff --git a/src/bivariate_restricted_dom/rel_entr.c b/src/atoms/bivariate_restricted_dom/rel_entr.c similarity index 99% rename from src/bivariate_restricted_dom/rel_entr.c rename to src/atoms/bivariate_restricted_dom/rel_entr.c index 4a3c771e..62772f8d 100644 --- a/src/bivariate_restricted_dom/rel_entr.c +++ b/src/atoms/bivariate_restricted_dom/rel_entr.c @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "bivariate_restricted_dom.h" +#include "atoms/bivariate_restricted_dom.h" #include #include #include diff --git a/src/bivariate_restricted_dom/rel_entr_scalar_vector.c b/src/atoms/bivariate_restricted_dom/rel_entr_scalar_vector.c similarity index 99% rename from src/bivariate_restricted_dom/rel_entr_scalar_vector.c rename to src/atoms/bivariate_restricted_dom/rel_entr_scalar_vector.c index 36da26ee..28a3c0d9 100644 --- a/src/bivariate_restricted_dom/rel_entr_scalar_vector.c +++ b/src/atoms/bivariate_restricted_dom/rel_entr_scalar_vector.c @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "bivariate_restricted_dom.h" +#include "atoms/bivariate_restricted_dom.h" #include #include #include diff --git a/src/bivariate_restricted_dom/rel_entr_vector_scalar.c b/src/atoms/bivariate_restricted_dom/rel_entr_vector_scalar.c similarity index 99% rename from src/bivariate_restricted_dom/rel_entr_vector_scalar.c rename to src/atoms/bivariate_restricted_dom/rel_entr_vector_scalar.c index dfe31b2e..b8e4c2c0 100644 --- a/src/bivariate_restricted_dom/rel_entr_vector_scalar.c +++ b/src/atoms/bivariate_restricted_dom/rel_entr_vector_scalar.c @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "bivariate_restricted_dom.h" +#include "atoms/bivariate_restricted_dom.h" #include #include #include diff --git a/src/elementwise_full_dom/common.c b/src/atoms/elementwise_full_dom/common.c similarity index 99% rename from src/elementwise_full_dom/common.c rename to src/atoms/elementwise_full_dom/common.c index 73de379c..3a6df35d 100644 --- a/src/elementwise_full_dom/common.c +++ b/src/atoms/elementwise_full_dom/common.c @@ -1,4 +1,4 @@ -#include "elementwise_full_dom.h" +#include "atoms/elementwise_full_dom.h" #include "subexpr.h" #include "utils/CSC_Matrix.h" #include "utils/CSR_Matrix.h" diff --git a/src/elementwise_full_dom/exp.c b/src/atoms/elementwise_full_dom/exp.c similarity index 95% rename from src/elementwise_full_dom/exp.c rename to src/atoms/elementwise_full_dom/exp.c index 567784e1..20f6f0e7 100644 --- a/src/elementwise_full_dom/exp.c +++ b/src/atoms/elementwise_full_dom/exp.c @@ -1,4 +1,4 @@ -#include "elementwise_full_dom.h" +#include "atoms/elementwise_full_dom.h" #include #include diff --git a/src/elementwise_full_dom/hyperbolic.c b/src/atoms/elementwise_full_dom/hyperbolic.c similarity index 98% rename from src/elementwise_full_dom/hyperbolic.c rename to src/atoms/elementwise_full_dom/hyperbolic.c index eb4bcbe0..0d2916ef 100644 --- a/src/elementwise_full_dom/hyperbolic.c +++ b/src/atoms/elementwise_full_dom/hyperbolic.c @@ -1,4 +1,4 @@ -#include "elementwise_full_dom.h" +#include "atoms/elementwise_full_dom.h" #include #include diff --git a/src/elementwise_full_dom/logistic.c b/src/atoms/elementwise_full_dom/logistic.c similarity index 97% rename from src/elementwise_full_dom/logistic.c rename to src/atoms/elementwise_full_dom/logistic.c index 16f88c2e..5a492b70 100644 --- a/src/elementwise_full_dom/logistic.c +++ b/src/atoms/elementwise_full_dom/logistic.c @@ -1,4 +1,4 @@ -#include "elementwise_full_dom.h" +#include "atoms/elementwise_full_dom.h" #include static void forward(expr *node, const double *u) diff --git a/src/elementwise_full_dom/normal_cdf.c b/src/atoms/elementwise_full_dom/normal_cdf.c similarity index 96% rename from src/elementwise_full_dom/normal_cdf.c rename to src/atoms/elementwise_full_dom/normal_cdf.c index 6c4a6e13..ae6b07ec 100644 --- a/src/elementwise_full_dom/normal_cdf.c +++ b/src/atoms/elementwise_full_dom/normal_cdf.c @@ -1,4 +1,4 @@ -#include "elementwise_full_dom.h" +#include "atoms/elementwise_full_dom.h" #include #ifndef M_PI diff --git a/src/elementwise_full_dom/power.c b/src/atoms/elementwise_full_dom/power.c similarity index 96% rename from src/elementwise_full_dom/power.c rename to src/atoms/elementwise_full_dom/power.c index 899d87b6..1564433e 100644 --- a/src/elementwise_full_dom/power.c +++ b/src/atoms/elementwise_full_dom/power.c @@ -1,4 +1,4 @@ -#include "elementwise_full_dom.h" +#include "atoms/elementwise_full_dom.h" #include "subexpr.h" #include #include diff --git a/src/elementwise_full_dom/trig.c b/src/atoms/elementwise_full_dom/trig.c similarity index 97% rename from src/elementwise_full_dom/trig.c rename to src/atoms/elementwise_full_dom/trig.c index 96c3efeb..f9de761c 100644 --- a/src/elementwise_full_dom/trig.c +++ b/src/atoms/elementwise_full_dom/trig.c @@ -1,4 +1,4 @@ -#include "elementwise_full_dom.h" +#include "atoms/elementwise_full_dom.h" #include /* ----------------------- sin ----------------------- */ diff --git a/src/elementwise_full_dom/xexp.c b/src/atoms/elementwise_full_dom/xexp.c similarity index 95% rename from src/elementwise_full_dom/xexp.c rename to src/atoms/elementwise_full_dom/xexp.c index e6deb49a..591caaf2 100644 --- a/src/elementwise_full_dom/xexp.c +++ b/src/atoms/elementwise_full_dom/xexp.c @@ -1,4 +1,4 @@ -#include "elementwise_full_dom.h" +#include "atoms/elementwise_full_dom.h" #include #include diff --git a/src/elementwise_restricted_dom/atanh.c b/src/atoms/elementwise_restricted_dom/atanh.c similarity index 95% rename from src/elementwise_restricted_dom/atanh.c rename to src/atoms/elementwise_restricted_dom/atanh.c index a0c49f21..52bc14ea 100644 --- a/src/elementwise_restricted_dom/atanh.c +++ b/src/atoms/elementwise_restricted_dom/atanh.c @@ -1,4 +1,4 @@ -#include "elementwise_restricted_dom.h" +#include "atoms/elementwise_restricted_dom.h" #include static void atanh_forward(expr *node, const double *u) diff --git a/src/elementwise_restricted_dom/common.c b/src/atoms/elementwise_restricted_dom/common.c similarity index 96% rename from src/elementwise_restricted_dom/common.c rename to src/atoms/elementwise_restricted_dom/common.c index 05f80f76..67d84841 100644 --- a/src/elementwise_restricted_dom/common.c +++ b/src/atoms/elementwise_restricted_dom/common.c @@ -1,4 +1,4 @@ -#include "elementwise_restricted_dom.h" +#include "atoms/elementwise_restricted_dom.h" #include void jacobian_init_restricted(expr *node) diff --git a/src/elementwise_restricted_dom/entr.c b/src/atoms/elementwise_restricted_dom/entr.c similarity index 94% rename from src/elementwise_restricted_dom/entr.c rename to src/atoms/elementwise_restricted_dom/entr.c index 1627032b..65da646f 100644 --- a/src/elementwise_restricted_dom/entr.c +++ b/src/atoms/elementwise_restricted_dom/entr.c @@ -1,4 +1,4 @@ -#include "elementwise_restricted_dom.h" +#include "atoms/elementwise_restricted_dom.h" #include static void entr_forward(expr *node, const double *u) diff --git a/src/elementwise_restricted_dom/log.c b/src/atoms/elementwise_restricted_dom/log.c similarity index 94% rename from src/elementwise_restricted_dom/log.c rename to src/atoms/elementwise_restricted_dom/log.c index 441eb3f5..a14d9288 100644 --- a/src/elementwise_restricted_dom/log.c +++ b/src/atoms/elementwise_restricted_dom/log.c @@ -1,4 +1,4 @@ -#include "elementwise_restricted_dom.h" +#include "atoms/elementwise_restricted_dom.h" #include static void log_forward(expr *node, const double *u) diff --git a/src/elementwise_restricted_dom/tan.c b/src/atoms/elementwise_restricted_dom/tan.c similarity index 95% rename from src/elementwise_restricted_dom/tan.c rename to src/atoms/elementwise_restricted_dom/tan.c index 897cec4d..4155fbe7 100644 --- a/src/elementwise_restricted_dom/tan.c +++ b/src/atoms/elementwise_restricted_dom/tan.c @@ -1,4 +1,4 @@ -#include "elementwise_restricted_dom.h" +#include "atoms/elementwise_restricted_dom.h" #include static void tan_forward(expr *node, const double *u) diff --git a/src/other/prod.c b/src/atoms/other/prod.c similarity index 99% rename from src/other/prod.c rename to src/atoms/other/prod.c index 31428af2..58261678 100644 --- a/src/other/prod.c +++ b/src/atoms/other/prod.c @@ -1,4 +1,4 @@ -#include "other.h" +#include "atoms/non_elementwise_full_dom.h" #include #include #include diff --git a/src/other/prod_axis_one.c b/src/atoms/other/prod_axis_one.c similarity index 99% rename from src/other/prod_axis_one.c rename to src/atoms/other/prod_axis_one.c index 03edaf88..72cd12ae 100644 --- a/src/other/prod_axis_one.c +++ b/src/atoms/other/prod_axis_one.c @@ -1,4 +1,4 @@ -#include "other.h" +#include "atoms/non_elementwise_full_dom.h" #include #include #include diff --git a/src/other/prod_axis_zero.c b/src/atoms/other/prod_axis_zero.c similarity index 99% rename from src/other/prod_axis_zero.c rename to src/atoms/other/prod_axis_zero.c index 198bdba2..f6411dec 100644 --- a/src/other/prod_axis_zero.c +++ b/src/atoms/other/prod_axis_zero.c @@ -1,4 +1,4 @@ -#include "other.h" +#include "atoms/non_elementwise_full_dom.h" #include #include #include diff --git a/src/other/quad_form.c b/src/atoms/other/quad_form.c similarity index 99% rename from src/other/quad_form.c rename to src/atoms/other/quad_form.c index 03f91939..02dba70f 100644 --- a/src/other/quad_form.c +++ b/src/atoms/other/quad_form.c @@ -1,4 +1,4 @@ -#include "other.h" +#include "atoms/non_elementwise_full_dom.h" #include "subexpr.h" #include "utils/CSC_Matrix.h" #include "utils/CSR_sum.h" diff --git a/tests/forward_pass/affine/test_add.h b/tests/forward_pass/affine/test_add.h index 11fb35c8..0c4e41f0 100644 --- a/tests/forward_pass/affine/test_add.h +++ b/tests/forward_pass/affine/test_add.h @@ -2,7 +2,7 @@ #include #include -#include "affine.h" +#include "atoms/affine.h" #include "expr.h" #include "minunit.h" #include "test_helpers.h" diff --git a/tests/forward_pass/affine/test_broadcast.h b/tests/forward_pass/affine/test_broadcast.h index e4adaab8..f6870d17 100644 --- a/tests/forward_pass/affine/test_broadcast.h +++ b/tests/forward_pass/affine/test_broadcast.h @@ -2,7 +2,7 @@ #include #include -#include "affine.h" +#include "atoms/affine.h" #include "expr.h" #include "minunit.h" #include "test_helpers.h" diff --git a/tests/forward_pass/affine/test_hstack.h b/tests/forward_pass/affine/test_hstack.h index 95fc7cce..42318851 100644 --- a/tests/forward_pass/affine/test_hstack.h +++ b/tests/forward_pass/affine/test_hstack.h @@ -2,9 +2,9 @@ #include #include -#include "affine.h" -#include "elementwise_full_dom.h" -#include "elementwise_restricted_dom.h" +#include "atoms/affine.h" +#include "atoms/elementwise_full_dom.h" +#include "atoms/elementwise_restricted_dom.h" #include "expr.h" #include "minunit.h" #include "test_helpers.h" diff --git a/tests/forward_pass/affine/test_left_matmul_dense.h b/tests/forward_pass/affine/test_left_matmul_dense.h index 5cd9c75d..e911ba57 100644 --- a/tests/forward_pass/affine/test_left_matmul_dense.h +++ b/tests/forward_pass/affine/test_left_matmul_dense.h @@ -1,7 +1,7 @@ #include #include -#include "affine.h" +#include "atoms/affine.h" #include "expr.h" #include "minunit.h" #include "test_helpers.h" diff --git a/tests/forward_pass/affine/test_linear_op.h b/tests/forward_pass/affine/test_linear_op.h index 7cb22724..801a4035 100644 --- a/tests/forward_pass/affine/test_linear_op.h +++ b/tests/forward_pass/affine/test_linear_op.h @@ -4,7 +4,7 @@ #include #include -#include "affine.h" +#include "atoms/affine.h" #include "expr.h" #include "minunit.h" #include "test_helpers.h" diff --git a/tests/forward_pass/affine/test_neg.h b/tests/forward_pass/affine/test_neg.h index 0fad2b1d..3819d7ae 100644 --- a/tests/forward_pass/affine/test_neg.h +++ b/tests/forward_pass/affine/test_neg.h @@ -2,7 +2,7 @@ #include #include -#include "affine.h" +#include "atoms/affine.h" #include "expr.h" #include "minunit.h" #include "test_helpers.h" diff --git a/tests/forward_pass/affine/test_promote.h b/tests/forward_pass/affine/test_promote.h index dcc90601..c3280588 100644 --- a/tests/forward_pass/affine/test_promote.h +++ b/tests/forward_pass/affine/test_promote.h @@ -2,7 +2,7 @@ #include #include -#include "affine.h" +#include "atoms/affine.h" #include "expr.h" #include "minunit.h" #include "test_helpers.h" diff --git a/tests/forward_pass/affine/test_sum.h b/tests/forward_pass/affine/test_sum.h index bf95c84c..74614a98 100644 --- a/tests/forward_pass/affine/test_sum.h +++ b/tests/forward_pass/affine/test_sum.h @@ -2,9 +2,9 @@ #include #include -#include "affine.h" -#include "elementwise_full_dom.h" -#include "elementwise_restricted_dom.h" +#include "atoms/affine.h" +#include "atoms/elementwise_full_dom.h" +#include "atoms/elementwise_restricted_dom.h" #include "expr.h" #include "minunit.h" #include "test_helpers.h" diff --git a/tests/forward_pass/affine/test_variable_constant.h b/tests/forward_pass/affine/test_variable_constant.h index 9df0f1a5..2878019b 100644 --- a/tests/forward_pass/affine/test_variable_constant.h +++ b/tests/forward_pass/affine/test_variable_constant.h @@ -2,7 +2,7 @@ #include #include -#include "affine.h" +#include "atoms/affine.h" #include "expr.h" #include "minunit.h" #include "test_helpers.h" diff --git a/tests/forward_pass/affine/test_vstack.h b/tests/forward_pass/affine/test_vstack.h index e49a44b0..96e1a159 100644 --- a/tests/forward_pass/affine/test_vstack.h +++ b/tests/forward_pass/affine/test_vstack.h @@ -2,9 +2,9 @@ #include #include -#include "affine.h" -#include "elementwise_full_dom.h" -#include "elementwise_restricted_dom.h" +#include "atoms/affine.h" +#include "atoms/elementwise_full_dom.h" +#include "atoms/elementwise_restricted_dom.h" #include "expr.h" #include "minunit.h" #include "test_helpers.h" diff --git a/tests/forward_pass/bivariate_full_dom/test_matmul.h b/tests/forward_pass/bivariate_full_dom/test_matmul.h index af181e4f..47391c2c 100644 --- a/tests/forward_pass/bivariate_full_dom/test_matmul.h +++ b/tests/forward_pass/bivariate_full_dom/test_matmul.h @@ -2,7 +2,7 @@ #include #include -#include "bivariate_full_dom.h" +#include "atoms/bivariate_full_dom.h" #include "expr.h" #include "minunit.h" #include "test_helpers.h" diff --git a/tests/forward_pass/composite/test_composite.h b/tests/forward_pass/composite/test_composite.h index f45a190b..b710aaca 100644 --- a/tests/forward_pass/composite/test_composite.h +++ b/tests/forward_pass/composite/test_composite.h @@ -2,9 +2,9 @@ #include #include -#include "affine.h" -#include "elementwise_full_dom.h" -#include "elementwise_restricted_dom.h" +#include "atoms/affine.h" +#include "atoms/elementwise_full_dom.h" +#include "atoms/elementwise_restricted_dom.h" #include "expr.h" #include "minunit.h" #include "test_helpers.h" diff --git a/tests/forward_pass/elementwise_full_dom/test_exp.h b/tests/forward_pass/elementwise_full_dom/test_exp.h index 8b191cb6..60a086ee 100644 --- a/tests/forward_pass/elementwise_full_dom/test_exp.h +++ b/tests/forward_pass/elementwise_full_dom/test_exp.h @@ -2,9 +2,9 @@ #include #include -#include "affine.h" -#include "elementwise_full_dom.h" -#include "elementwise_restricted_dom.h" +#include "atoms/affine.h" +#include "atoms/elementwise_full_dom.h" +#include "atoms/elementwise_restricted_dom.h" #include "expr.h" #include "minunit.h" #include "test_helpers.h" diff --git a/tests/forward_pass/elementwise_full_dom/test_normal_cdf.h b/tests/forward_pass/elementwise_full_dom/test_normal_cdf.h index 97a8159d..a191f004 100644 --- a/tests/forward_pass/elementwise_full_dom/test_normal_cdf.h +++ b/tests/forward_pass/elementwise_full_dom/test_normal_cdf.h @@ -2,9 +2,9 @@ #include #include -#include "affine.h" -#include "elementwise_full_dom.h" -#include "elementwise_restricted_dom.h" +#include "atoms/affine.h" +#include "atoms/elementwise_full_dom.h" +#include "atoms/elementwise_restricted_dom.h" #include "expr.h" #include "minunit.h" #include "test_helpers.h" diff --git a/tests/forward_pass/elementwise_restricted_dom/test_log.h b/tests/forward_pass/elementwise_restricted_dom/test_log.h index 25d17e76..190a24fe 100644 --- a/tests/forward_pass/elementwise_restricted_dom/test_log.h +++ b/tests/forward_pass/elementwise_restricted_dom/test_log.h @@ -2,9 +2,9 @@ #include #include -#include "affine.h" -#include "elementwise_full_dom.h" -#include "elementwise_restricted_dom.h" +#include "atoms/affine.h" +#include "atoms/elementwise_full_dom.h" +#include "atoms/elementwise_restricted_dom.h" #include "expr.h" #include "minunit.h" #include "test_helpers.h" diff --git a/tests/forward_pass/other/test_prod_axis_one.h b/tests/forward_pass/other/test_prod_axis_one.h index 7cf74e03..663f1f81 100644 --- a/tests/forward_pass/other/test_prod_axis_one.h +++ b/tests/forward_pass/other/test_prod_axis_one.h @@ -2,10 +2,10 @@ #include #include -#include "affine.h" +#include "atoms/affine.h" +#include "atoms/non_elementwise_full_dom.h" #include "expr.h" #include "minunit.h" -#include "other.h" #include "test_helpers.h" const char *test_forward_prod_axis_one(void) diff --git a/tests/forward_pass/other/test_prod_axis_zero.h b/tests/forward_pass/other/test_prod_axis_zero.h index f87782a0..fe6b67a6 100644 --- a/tests/forward_pass/other/test_prod_axis_zero.h +++ b/tests/forward_pass/other/test_prod_axis_zero.h @@ -2,10 +2,10 @@ #include #include -#include "affine.h" +#include "atoms/affine.h" +#include "atoms/non_elementwise_full_dom.h" #include "expr.h" #include "minunit.h" -#include "other.h" #include "test_helpers.h" const char *test_forward_prod_axis_zero(void) diff --git a/tests/jacobian_tests/affine/test_broadcast.h b/tests/jacobian_tests/affine/test_broadcast.h index a66e761b..e3d79d2f 100644 --- a/tests/jacobian_tests/affine/test_broadcast.h +++ b/tests/jacobian_tests/affine/test_broadcast.h @@ -2,7 +2,7 @@ #include #include -#include "affine.h" +#include "atoms/affine.h" #include "expr.h" #include "minunit.h" #include "test_helpers.h" diff --git a/tests/jacobian_tests/affine/test_const_scalar_mult.h b/tests/jacobian_tests/affine/test_const_scalar_mult.h index b459e77c..ca27f94e 100644 --- a/tests/jacobian_tests/affine/test_const_scalar_mult.h +++ b/tests/jacobian_tests/affine/test_const_scalar_mult.h @@ -1,8 +1,8 @@ #include -#include "affine.h" -#include "elementwise_full_dom.h" -#include "elementwise_restricted_dom.h" +#include "atoms/affine.h" +#include "atoms/elementwise_full_dom.h" +#include "atoms/elementwise_restricted_dom.h" #include "expr.h" #include "minunit.h" #include "test_helpers.h" diff --git a/tests/jacobian_tests/affine/test_const_vector_mult.h b/tests/jacobian_tests/affine/test_const_vector_mult.h index 45ca3fd4..fbee7df5 100644 --- a/tests/jacobian_tests/affine/test_const_vector_mult.h +++ b/tests/jacobian_tests/affine/test_const_vector_mult.h @@ -1,8 +1,8 @@ #include -#include "affine.h" -#include "elementwise_full_dom.h" -#include "elementwise_restricted_dom.h" +#include "atoms/affine.h" +#include "atoms/elementwise_full_dom.h" +#include "atoms/elementwise_restricted_dom.h" #include "expr.h" #include "minunit.h" #include "test_helpers.h" diff --git a/tests/jacobian_tests/affine/test_hstack.h b/tests/jacobian_tests/affine/test_hstack.h index 17bafe24..a5b163ca 100644 --- a/tests/jacobian_tests/affine/test_hstack.h +++ b/tests/jacobian_tests/affine/test_hstack.h @@ -1,9 +1,9 @@ #include #include -#include "affine.h" -#include "elementwise_full_dom.h" -#include "elementwise_restricted_dom.h" +#include "atoms/affine.h" +#include "atoms/elementwise_full_dom.h" +#include "atoms/elementwise_restricted_dom.h" #include "expr.h" #include "minunit.h" #include "test_helpers.h" diff --git a/tests/jacobian_tests/affine/test_index.h b/tests/jacobian_tests/affine/test_index.h index 943fd0a1..e0eff49a 100644 --- a/tests/jacobian_tests/affine/test_index.h +++ b/tests/jacobian_tests/affine/test_index.h @@ -2,9 +2,9 @@ #include -#include "affine.h" -#include "elementwise_full_dom.h" -#include "elementwise_restricted_dom.h" +#include "atoms/affine.h" +#include "atoms/elementwise_full_dom.h" +#include "atoms/elementwise_restricted_dom.h" #include "expr.h" #include "minunit.h" #include "test_helpers.h" diff --git a/tests/jacobian_tests/affine/test_left_matmul.h b/tests/jacobian_tests/affine/test_left_matmul.h index 270a2be2..c4968d68 100644 --- a/tests/jacobian_tests/affine/test_left_matmul.h +++ b/tests/jacobian_tests/affine/test_left_matmul.h @@ -1,9 +1,9 @@ #include #include -#include "affine.h" -#include "elementwise_full_dom.h" -#include "elementwise_restricted_dom.h" +#include "atoms/affine.h" +#include "atoms/elementwise_full_dom.h" +#include "atoms/elementwise_restricted_dom.h" #include "expr.h" #include "minunit.h" #include "numerical_diff.h" diff --git a/tests/jacobian_tests/affine/test_neg.h b/tests/jacobian_tests/affine/test_neg.h index 1c0de551..ca4e5951 100644 --- a/tests/jacobian_tests/affine/test_neg.h +++ b/tests/jacobian_tests/affine/test_neg.h @@ -1,6 +1,6 @@ #include -#include "affine.h" +#include "atoms/affine.h" #include "expr.h" #include "minunit.h" #include "test_helpers.h" diff --git a/tests/jacobian_tests/affine/test_promote.h b/tests/jacobian_tests/affine/test_promote.h index 30dc7552..ad2ab498 100644 --- a/tests/jacobian_tests/affine/test_promote.h +++ b/tests/jacobian_tests/affine/test_promote.h @@ -2,7 +2,7 @@ #include #include -#include "affine.h" +#include "atoms/affine.h" #include "expr.h" #include "minunit.h" #include "test_helpers.h" diff --git a/tests/jacobian_tests/affine/test_right_matmul.h b/tests/jacobian_tests/affine/test_right_matmul.h index e3af6655..e9f40dab 100644 --- a/tests/jacobian_tests/affine/test_right_matmul.h +++ b/tests/jacobian_tests/affine/test_right_matmul.h @@ -1,9 +1,9 @@ #include #include -#include "affine.h" -#include "elementwise_full_dom.h" -#include "elementwise_restricted_dom.h" +#include "atoms/affine.h" +#include "atoms/elementwise_full_dom.h" +#include "atoms/elementwise_restricted_dom.h" #include "expr.h" #include "minunit.h" #include "test_helpers.h" diff --git a/tests/jacobian_tests/affine/test_sum.h b/tests/jacobian_tests/affine/test_sum.h index 607c874b..f34ee917 100644 --- a/tests/jacobian_tests/affine/test_sum.h +++ b/tests/jacobian_tests/affine/test_sum.h @@ -1,9 +1,9 @@ #include -#include "affine.h" -#include "bivariate_full_dom.h" -#include "elementwise_full_dom.h" -#include "elementwise_restricted_dom.h" +#include "atoms/affine.h" +#include "atoms/bivariate_full_dom.h" +#include "atoms/elementwise_full_dom.h" +#include "atoms/elementwise_restricted_dom.h" #include "expr.h" #include "minunit.h" #include "test_helpers.h" diff --git a/tests/jacobian_tests/affine/test_trace.h b/tests/jacobian_tests/affine/test_trace.h index df0c53f8..61701bd1 100644 --- a/tests/jacobian_tests/affine/test_trace.h +++ b/tests/jacobian_tests/affine/test_trace.h @@ -1,8 +1,8 @@ #include -#include "affine.h" -#include "elementwise_full_dom.h" -#include "elementwise_restricted_dom.h" +#include "atoms/affine.h" +#include "atoms/elementwise_full_dom.h" +#include "atoms/elementwise_restricted_dom.h" #include "expr.h" #include "minunit.h" #include "test_helpers.h" diff --git a/tests/jacobian_tests/affine/test_transpose.h b/tests/jacobian_tests/affine/test_transpose.h index 4cf6e7e9..44193159 100644 --- a/tests/jacobian_tests/affine/test_transpose.h +++ b/tests/jacobian_tests/affine/test_transpose.h @@ -2,7 +2,7 @@ #ifndef TEST_TRANSPOSE_H #define TEST_TRANSPOSE_H -#include "affine.h" +#include "atoms/affine.h" #include "minunit.h" #include "test_helpers.h" #include diff --git a/tests/jacobian_tests/affine/test_vstack.h b/tests/jacobian_tests/affine/test_vstack.h index ca42d691..fc4229f1 100644 --- a/tests/jacobian_tests/affine/test_vstack.h +++ b/tests/jacobian_tests/affine/test_vstack.h @@ -1,9 +1,9 @@ #include #include -#include "affine.h" -#include "elementwise_full_dom.h" -#include "elementwise_restricted_dom.h" +#include "atoms/affine.h" +#include "atoms/elementwise_full_dom.h" +#include "atoms/elementwise_restricted_dom.h" #include "expr.h" #include "minunit.h" #include "test_helpers.h" 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 ce66d013..9e7e6e5e 100644 --- a/tests/jacobian_tests/bivariate_full_dom/test_elementwise_mult.h +++ b/tests/jacobian_tests/bivariate_full_dom/test_elementwise_mult.h @@ -1,5 +1,5 @@ -#include "affine.h" -#include "bivariate_full_dom.h" +#include "atoms/affine.h" +#include "atoms/bivariate_full_dom.h" #include "expr.h" #include "minunit.h" #include "test_helpers.h" diff --git a/tests/jacobian_tests/bivariate_full_dom/test_matmul.h b/tests/jacobian_tests/bivariate_full_dom/test_matmul.h index 48babbdb..386efa16 100644 --- a/tests/jacobian_tests/bivariate_full_dom/test_matmul.h +++ b/tests/jacobian_tests/bivariate_full_dom/test_matmul.h @@ -1,4 +1,4 @@ -#include "bivariate_full_dom.h" +#include "atoms/bivariate_full_dom.h" #include "expr.h" #include "minunit.h" #include "test_helpers.h" 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 1a05a7e4..e1007f82 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 @@ -1,6 +1,6 @@ -#include "affine.h" +#include "atoms/affine.h" -#include "bivariate_restricted_dom.h" +#include "atoms/bivariate_restricted_dom.h" #include "expr.h" #include "minunit.h" #include "test_helpers.h" 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 89726e98..883e2330 100644 --- a/tests/jacobian_tests/bivariate_restricted_dom/test_rel_entr.h +++ b/tests/jacobian_tests/bivariate_restricted_dom/test_rel_entr.h @@ -1,5 +1,5 @@ -#include "affine.h" -#include "bivariate_restricted_dom.h" +#include "atoms/affine.h" +#include "atoms/bivariate_restricted_dom.h" #include "expr.h" #include "minunit.h" #include "test_helpers.h" 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 0a6f734f..20cd6fa7 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 @@ -1,4 +1,4 @@ -#include "bivariate_restricted_dom.h" +#include "atoms/bivariate_restricted_dom.h" #include "expr.h" #include "minunit.h" #include "test_helpers.h" 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 02d19b4a..9a454ddb 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 @@ -1,4 +1,4 @@ -#include "bivariate_restricted_dom.h" +#include "atoms/bivariate_restricted_dom.h" #include "expr.h" #include "minunit.h" #include "test_helpers.h" diff --git a/tests/jacobian_tests/composite/test_chain_rule_jacobian.h b/tests/jacobian_tests/composite/test_chain_rule_jacobian.h index bc61d834..8139a33b 100644 --- a/tests/jacobian_tests/composite/test_chain_rule_jacobian.h +++ b/tests/jacobian_tests/composite/test_chain_rule_jacobian.h @@ -1,10 +1,10 @@ -#include "affine.h" -#include "bivariate_full_dom.h" -#include "elementwise_full_dom.h" +#include "atoms/affine.h" +#include "atoms/bivariate_full_dom.h" +#include "atoms/elementwise_full_dom.h" +#include "atoms/non_elementwise_full_dom.h" #include "expr.h" #include "minunit.h" #include "numerical_diff.h" -#include "other.h" #include "test_helpers.h" #include "utils/CSR_Matrix.h" diff --git a/tests/jacobian_tests/composite/test_composite_exp.h b/tests/jacobian_tests/composite/test_composite_exp.h index 98cf2d9b..725e1531 100644 --- a/tests/jacobian_tests/composite/test_composite_exp.h +++ b/tests/jacobian_tests/composite/test_composite_exp.h @@ -1,8 +1,8 @@ #include #include -#include "affine.h" -#include "elementwise_full_dom.h" +#include "atoms/affine.h" +#include "atoms/elementwise_full_dom.h" #include "minunit.h" #include "numerical_diff.h" #include "test_helpers.h" diff --git a/tests/jacobian_tests/elementwise_restricted_dom/test_log.h b/tests/jacobian_tests/elementwise_restricted_dom/test_log.h index 2378bbce..ff99d648 100644 --- a/tests/jacobian_tests/elementwise_restricted_dom/test_log.h +++ b/tests/jacobian_tests/elementwise_restricted_dom/test_log.h @@ -1,8 +1,8 @@ #include -#include "affine.h" -#include "elementwise_full_dom.h" -#include "elementwise_restricted_dom.h" +#include "atoms/affine.h" +#include "atoms/elementwise_full_dom.h" +#include "atoms/elementwise_restricted_dom.h" #include "expr.h" #include "minunit.h" #include "test_helpers.h" diff --git a/tests/jacobian_tests/other/test_prod.h b/tests/jacobian_tests/other/test_prod.h index 87900b02..ef592504 100644 --- a/tests/jacobian_tests/other/test_prod.h +++ b/tests/jacobian_tests/other/test_prod.h @@ -1,9 +1,9 @@ #include -#include "affine.h" +#include "atoms/affine.h" +#include "atoms/non_elementwise_full_dom.h" #include "expr.h" #include "minunit.h" -#include "other.h" #include "test_helpers.h" const char *test_jacobian_prod_no_zero(void) diff --git a/tests/jacobian_tests/other/test_prod_axis_one.h b/tests/jacobian_tests/other/test_prod_axis_one.h index 564920af..b4757ee4 100644 --- a/tests/jacobian_tests/other/test_prod_axis_one.h +++ b/tests/jacobian_tests/other/test_prod_axis_one.h @@ -1,9 +1,9 @@ #include -#include "affine.h" +#include "atoms/affine.h" +#include "atoms/non_elementwise_full_dom.h" #include "expr.h" #include "minunit.h" -#include "other.h" #include "test_helpers.h" const char *test_jacobian_prod_axis_one(void) diff --git a/tests/jacobian_tests/other/test_prod_axis_zero.h b/tests/jacobian_tests/other/test_prod_axis_zero.h index 952713b2..42b4ad16 100644 --- a/tests/jacobian_tests/other/test_prod_axis_zero.h +++ b/tests/jacobian_tests/other/test_prod_axis_zero.h @@ -1,9 +1,9 @@ #include -#include "affine.h" +#include "atoms/affine.h" +#include "atoms/non_elementwise_full_dom.h" #include "expr.h" #include "minunit.h" -#include "other.h" #include "test_helpers.h" const char *test_jacobian_prod_axis_zero(void) diff --git a/tests/jacobian_tests/other/test_quad_form.h b/tests/jacobian_tests/other/test_quad_form.h index b72c443e..d832a83e 100644 --- a/tests/jacobian_tests/other/test_quad_form.h +++ b/tests/jacobian_tests/other/test_quad_form.h @@ -1,8 +1,8 @@ -#include "affine.h" +#include "atoms/affine.h" +#include "atoms/non_elementwise_full_dom.h" #include "expr.h" #include "minunit.h" -#include "other.h" #include "test_helpers.h" #include #include diff --git a/tests/numerical_diff/test_numerical_diff.h b/tests/numerical_diff/test_numerical_diff.h index bf2c568f..f77e3e99 100644 --- a/tests/numerical_diff/test_numerical_diff.h +++ b/tests/numerical_diff/test_numerical_diff.h @@ -1,7 +1,7 @@ #include -#include "affine.h" -#include "elementwise_full_dom.h" +#include "atoms/affine.h" +#include "atoms/elementwise_full_dom.h" #include "minunit.h" #include "numerical_diff.h" diff --git a/tests/problem/test_problem.h b/tests/problem/test_problem.h index 97fcb0b1..fbb512f5 100644 --- a/tests/problem/test_problem.h +++ b/tests/problem/test_problem.h @@ -4,9 +4,9 @@ #include #include -#include "affine.h" -#include "elementwise_full_dom.h" -#include "elementwise_restricted_dom.h" +#include "atoms/affine.h" +#include "atoms/elementwise_full_dom.h" +#include "atoms/elementwise_restricted_dom.h" #include "expr.h" #include "minunit.h" #include "problem.h" diff --git a/tests/profiling/profile_left_matmul.h b/tests/profiling/profile_left_matmul.h index 5ff98bef..df80a903 100644 --- a/tests/profiling/profile_left_matmul.h +++ b/tests/profiling/profile_left_matmul.h @@ -3,9 +3,9 @@ #include #include -#include "affine.h" -#include "elementwise_full_dom.h" -#include "elementwise_restricted_dom.h" +#include "atoms/affine.h" +#include "atoms/elementwise_full_dom.h" +#include "atoms/elementwise_restricted_dom.h" #include "expr.h" #include "minunit.h" #include "test_helpers.h" diff --git a/tests/wsum_hess/affine/test_broadcast.h b/tests/wsum_hess/affine/test_broadcast.h index 3b1a0bfa..3d36cb42 100644 --- a/tests/wsum_hess/affine/test_broadcast.h +++ b/tests/wsum_hess/affine/test_broadcast.h @@ -3,9 +3,9 @@ #include #include -#include "affine.h" -#include "elementwise_full_dom.h" -#include "elementwise_restricted_dom.h" +#include "atoms/affine.h" +#include "atoms/elementwise_full_dom.h" +#include "atoms/elementwise_restricted_dom.h" #include "expr.h" #include "minunit.h" #include "test_helpers.h" diff --git a/tests/wsum_hess/affine/test_const_scalar_mult.h b/tests/wsum_hess/affine/test_const_scalar_mult.h index 1756f3f5..08e6d86b 100644 --- a/tests/wsum_hess/affine/test_const_scalar_mult.h +++ b/tests/wsum_hess/affine/test_const_scalar_mult.h @@ -1,9 +1,9 @@ #include #include -#include "affine.h" -#include "elementwise_full_dom.h" -#include "elementwise_restricted_dom.h" +#include "atoms/affine.h" +#include "atoms/elementwise_full_dom.h" +#include "atoms/elementwise_restricted_dom.h" #include "expr.h" #include "minunit.h" #include "test_helpers.h" diff --git a/tests/wsum_hess/affine/test_const_vector_mult.h b/tests/wsum_hess/affine/test_const_vector_mult.h index febb3bae..d265c71c 100644 --- a/tests/wsum_hess/affine/test_const_vector_mult.h +++ b/tests/wsum_hess/affine/test_const_vector_mult.h @@ -1,9 +1,9 @@ #include #include -#include "affine.h" -#include "elementwise_full_dom.h" -#include "elementwise_restricted_dom.h" +#include "atoms/affine.h" +#include "atoms/elementwise_full_dom.h" +#include "atoms/elementwise_restricted_dom.h" #include "expr.h" #include "minunit.h" #include "test_helpers.h" diff --git a/tests/wsum_hess/affine/test_hstack.h b/tests/wsum_hess/affine/test_hstack.h index 3b534741..78c81607 100644 --- a/tests/wsum_hess/affine/test_hstack.h +++ b/tests/wsum_hess/affine/test_hstack.h @@ -1,6 +1,6 @@ -#include "affine.h" -#include "elementwise_full_dom.h" -#include "elementwise_restricted_dom.h" +#include "atoms/affine.h" +#include "atoms/elementwise_full_dom.h" +#include "atoms/elementwise_restricted_dom.h" #include "expr.h" #include "minunit.h" #include "test_helpers.h" diff --git a/tests/wsum_hess/affine/test_index.h b/tests/wsum_hess/affine/test_index.h index 9423f12f..2ce7707a 100644 --- a/tests/wsum_hess/affine/test_index.h +++ b/tests/wsum_hess/affine/test_index.h @@ -5,9 +5,9 @@ #include #include -#include "affine.h" -#include "elementwise_full_dom.h" -#include "elementwise_restricted_dom.h" +#include "atoms/affine.h" +#include "atoms/elementwise_full_dom.h" +#include "atoms/elementwise_restricted_dom.h" #include "expr.h" #include "minunit.h" #include "test_helpers.h" diff --git a/tests/wsum_hess/affine/test_left_matmul.h b/tests/wsum_hess/affine/test_left_matmul.h index 3ccaff18..f5441b94 100644 --- a/tests/wsum_hess/affine/test_left_matmul.h +++ b/tests/wsum_hess/affine/test_left_matmul.h @@ -3,9 +3,9 @@ #include #include -#include "affine.h" -#include "elementwise_full_dom.h" -#include "elementwise_restricted_dom.h" +#include "atoms/affine.h" +#include "atoms/elementwise_full_dom.h" +#include "atoms/elementwise_restricted_dom.h" #include "expr.h" #include "minunit.h" #include "numerical_diff.h" diff --git a/tests/wsum_hess/affine/test_right_matmul.h b/tests/wsum_hess/affine/test_right_matmul.h index e697b588..a74df5cd 100644 --- a/tests/wsum_hess/affine/test_right_matmul.h +++ b/tests/wsum_hess/affine/test_right_matmul.h @@ -3,9 +3,9 @@ #include #include -#include "affine.h" -#include "elementwise_full_dom.h" -#include "elementwise_restricted_dom.h" +#include "atoms/affine.h" +#include "atoms/elementwise_full_dom.h" +#include "atoms/elementwise_restricted_dom.h" #include "expr.h" #include "minunit.h" #include "test_helpers.h" diff --git a/tests/wsum_hess/affine/test_sum.h b/tests/wsum_hess/affine/test_sum.h index 0ef1455c..8ade78b5 100644 --- a/tests/wsum_hess/affine/test_sum.h +++ b/tests/wsum_hess/affine/test_sum.h @@ -3,9 +3,9 @@ #include #include -#include "affine.h" -#include "elementwise_full_dom.h" -#include "elementwise_restricted_dom.h" +#include "atoms/affine.h" +#include "atoms/elementwise_full_dom.h" +#include "atoms/elementwise_restricted_dom.h" #include "expr.h" #include "minunit.h" #include "numerical_diff.h" diff --git a/tests/wsum_hess/affine/test_trace.h b/tests/wsum_hess/affine/test_trace.h index ad0b693b..bb3f98c7 100644 --- a/tests/wsum_hess/affine/test_trace.h +++ b/tests/wsum_hess/affine/test_trace.h @@ -3,9 +3,9 @@ #include #include -#include "affine.h" -#include "elementwise_full_dom.h" -#include "elementwise_restricted_dom.h" +#include "atoms/affine.h" +#include "atoms/elementwise_full_dom.h" +#include "atoms/elementwise_restricted_dom.h" #include "expr.h" #include "minunit.h" #include "test_helpers.h" diff --git a/tests/wsum_hess/affine/test_transpose.h b/tests/wsum_hess/affine/test_transpose.h index f41b5f9e..be91541c 100644 --- a/tests/wsum_hess/affine/test_transpose.h +++ b/tests/wsum_hess/affine/test_transpose.h @@ -1,7 +1,7 @@ #ifndef TEST_WSUM_HESS_TRANSPOSE_H #define TEST_WSUM_HESS_TRANSPOSE_H -#include "affine.h" +#include "atoms/affine.h" #include "minunit.h" #include "test_helpers.h" #include diff --git a/tests/wsum_hess/affine/test_vstack.h b/tests/wsum_hess/affine/test_vstack.h index bb99d852..f003431d 100644 --- a/tests/wsum_hess/affine/test_vstack.h +++ b/tests/wsum_hess/affine/test_vstack.h @@ -1,6 +1,6 @@ -#include "affine.h" -#include "elementwise_full_dom.h" -#include "elementwise_restricted_dom.h" +#include "atoms/affine.h" +#include "atoms/elementwise_full_dom.h" +#include "atoms/elementwise_restricted_dom.h" #include "expr.h" #include "minunit.h" #include "test_helpers.h" diff --git a/tests/wsum_hess/bivariate_full_dom/test_matmul.h b/tests/wsum_hess/bivariate_full_dom/test_matmul.h index 7ca03e4a..61a2d2d8 100644 --- a/tests/wsum_hess/bivariate_full_dom/test_matmul.h +++ b/tests/wsum_hess/bivariate_full_dom/test_matmul.h @@ -1,4 +1,4 @@ -#include "bivariate_full_dom.h" +#include "atoms/bivariate_full_dom.h" #include "expr.h" #include "minunit.h" #include "test_helpers.h" diff --git a/tests/wsum_hess/bivariate_full_dom/test_multiply.h b/tests/wsum_hess/bivariate_full_dom/test_multiply.h index 8b447f15..e85c7a1e 100644 --- a/tests/wsum_hess/bivariate_full_dom/test_multiply.h +++ b/tests/wsum_hess/bivariate_full_dom/test_multiply.h @@ -1,5 +1,5 @@ -#include "affine.h" -#include "bivariate_full_dom.h" +#include "atoms/affine.h" +#include "atoms/bivariate_full_dom.h" #include "expr.h" #include "minunit.h" #include "test_helpers.h" 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 c428432a..f1053e20 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 @@ -1,5 +1,5 @@ -#include "affine.h" -#include "bivariate_restricted_dom.h" +#include "atoms/affine.h" +#include "atoms/bivariate_restricted_dom.h" #include "expr.h" #include "minunit.h" #include "test_helpers.h" 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 a825a59d..ce2137af 100644 --- a/tests/wsum_hess/bivariate_restricted_dom/test_rel_entr.h +++ b/tests/wsum_hess/bivariate_restricted_dom/test_rel_entr.h @@ -1,5 +1,5 @@ -#include "affine.h" -#include "bivariate_restricted_dom.h" +#include "atoms/affine.h" +#include "atoms/bivariate_restricted_dom.h" #include "expr.h" #include "minunit.h" #include "test_helpers.h" 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 d305b976..a431b96b 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 @@ -1,4 +1,4 @@ -#include "bivariate_restricted_dom.h" +#include "atoms/bivariate_restricted_dom.h" #include "expr.h" #include "minunit.h" #include "test_helpers.h" 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 700e1630..60b94360 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 @@ -1,4 +1,4 @@ -#include "bivariate_restricted_dom.h" +#include "atoms/bivariate_restricted_dom.h" #include "expr.h" #include "minunit.h" #include "test_helpers.h" diff --git a/tests/wsum_hess/composite/test_chain_rule_wsum_hess.h b/tests/wsum_hess/composite/test_chain_rule_wsum_hess.h index a0c469c1..ca414f71 100644 --- a/tests/wsum_hess/composite/test_chain_rule_wsum_hess.h +++ b/tests/wsum_hess/composite/test_chain_rule_wsum_hess.h @@ -1,9 +1,9 @@ -#include "affine.h" -#include "bivariate_full_dom.h" -#include "elementwise_full_dom.h" +#include "atoms/affine.h" +#include "atoms/bivariate_full_dom.h" +#include "atoms/elementwise_full_dom.h" +#include "atoms/non_elementwise_full_dom.h" #include "minunit.h" #include "numerical_diff.h" -#include "other.h" #include "test_helpers.h" const char *test_wsum_hess_exp_sum(void) diff --git a/tests/wsum_hess/elementwise_full_dom/test_exp.h b/tests/wsum_hess/elementwise_full_dom/test_exp.h index a7eb37f1..be005537 100644 --- a/tests/wsum_hess/elementwise_full_dom/test_exp.h +++ b/tests/wsum_hess/elementwise_full_dom/test_exp.h @@ -3,9 +3,9 @@ #include #include -#include "affine.h" -#include "elementwise_full_dom.h" -#include "elementwise_restricted_dom.h" +#include "atoms/affine.h" +#include "atoms/elementwise_full_dom.h" +#include "atoms/elementwise_restricted_dom.h" #include "expr.h" #include "minunit.h" #include "test_helpers.h" diff --git a/tests/wsum_hess/elementwise_full_dom/test_hyperbolic.h b/tests/wsum_hess/elementwise_full_dom/test_hyperbolic.h index 6acab844..88a655fd 100644 --- a/tests/wsum_hess/elementwise_full_dom/test_hyperbolic.h +++ b/tests/wsum_hess/elementwise_full_dom/test_hyperbolic.h @@ -3,9 +3,9 @@ #include #include -#include "affine.h" -#include "elementwise_full_dom.h" -#include "elementwise_restricted_dom.h" +#include "atoms/affine.h" +#include "atoms/elementwise_full_dom.h" +#include "atoms/elementwise_restricted_dom.h" #include "expr.h" #include "minunit.h" #include "test_helpers.h" diff --git a/tests/wsum_hess/elementwise_full_dom/test_logistic.h b/tests/wsum_hess/elementwise_full_dom/test_logistic.h index 3dd22a14..2de60708 100644 --- a/tests/wsum_hess/elementwise_full_dom/test_logistic.h +++ b/tests/wsum_hess/elementwise_full_dom/test_logistic.h @@ -3,9 +3,9 @@ #include #include -#include "affine.h" -#include "elementwise_full_dom.h" -#include "elementwise_restricted_dom.h" +#include "atoms/affine.h" +#include "atoms/elementwise_full_dom.h" +#include "atoms/elementwise_restricted_dom.h" #include "expr.h" #include "minunit.h" #include "test_helpers.h" diff --git a/tests/wsum_hess/elementwise_full_dom/test_power.h b/tests/wsum_hess/elementwise_full_dom/test_power.h index f104a94a..c21021e2 100644 --- a/tests/wsum_hess/elementwise_full_dom/test_power.h +++ b/tests/wsum_hess/elementwise_full_dom/test_power.h @@ -3,9 +3,9 @@ #include #include -#include "affine.h" -#include "elementwise_full_dom.h" -#include "elementwise_restricted_dom.h" +#include "atoms/affine.h" +#include "atoms/elementwise_full_dom.h" +#include "atoms/elementwise_restricted_dom.h" #include "expr.h" #include "minunit.h" #include "test_helpers.h" diff --git a/tests/wsum_hess/elementwise_full_dom/test_trig.h b/tests/wsum_hess/elementwise_full_dom/test_trig.h index 19460b69..51b14220 100644 --- a/tests/wsum_hess/elementwise_full_dom/test_trig.h +++ b/tests/wsum_hess/elementwise_full_dom/test_trig.h @@ -3,9 +3,9 @@ #include #include -#include "affine.h" -#include "elementwise_full_dom.h" -#include "elementwise_restricted_dom.h" +#include "atoms/affine.h" +#include "atoms/elementwise_full_dom.h" +#include "atoms/elementwise_restricted_dom.h" #include "expr.h" #include "minunit.h" #include "test_helpers.h" diff --git a/tests/wsum_hess/elementwise_full_dom/test_xexp.h b/tests/wsum_hess/elementwise_full_dom/test_xexp.h index 5630b65f..c4c6f945 100644 --- a/tests/wsum_hess/elementwise_full_dom/test_xexp.h +++ b/tests/wsum_hess/elementwise_full_dom/test_xexp.h @@ -3,9 +3,9 @@ #include #include -#include "affine.h" -#include "elementwise_full_dom.h" -#include "elementwise_restricted_dom.h" +#include "atoms/affine.h" +#include "atoms/elementwise_full_dom.h" +#include "atoms/elementwise_restricted_dom.h" #include "expr.h" #include "minunit.h" #include "test_helpers.h" diff --git a/tests/wsum_hess/elementwise_restricted_dom/test_entr.h b/tests/wsum_hess/elementwise_restricted_dom/test_entr.h index 1c3b433d..1f4fb149 100644 --- a/tests/wsum_hess/elementwise_restricted_dom/test_entr.h +++ b/tests/wsum_hess/elementwise_restricted_dom/test_entr.h @@ -3,9 +3,9 @@ #include #include -#include "affine.h" -#include "elementwise_full_dom.h" -#include "elementwise_restricted_dom.h" +#include "atoms/affine.h" +#include "atoms/elementwise_full_dom.h" +#include "atoms/elementwise_restricted_dom.h" #include "expr.h" #include "minunit.h" #include "test_helpers.h" diff --git a/tests/wsum_hess/elementwise_restricted_dom/test_log.h b/tests/wsum_hess/elementwise_restricted_dom/test_log.h index 3632ff1c..024ea358 100644 --- a/tests/wsum_hess/elementwise_restricted_dom/test_log.h +++ b/tests/wsum_hess/elementwise_restricted_dom/test_log.h @@ -3,9 +3,9 @@ #include #include -#include "affine.h" -#include "elementwise_full_dom.h" -#include "elementwise_restricted_dom.h" +#include "atoms/affine.h" +#include "atoms/elementwise_full_dom.h" +#include "atoms/elementwise_restricted_dom.h" #include "expr.h" #include "minunit.h" #include "numerical_diff.h" diff --git a/tests/wsum_hess/other/test_prod.h b/tests/wsum_hess/other/test_prod.h index f9323664..753abcf5 100644 --- a/tests/wsum_hess/other/test_prod.h +++ b/tests/wsum_hess/other/test_prod.h @@ -1,9 +1,9 @@ #include #include +#include "atoms/non_elementwise_full_dom.h" #include "expr.h" #include "minunit.h" -#include "other.h" #include "test_helpers.h" /* Common setup: x is 4x1 variable, global index 2, total 8 vars */ diff --git a/tests/wsum_hess/other/test_prod_axis_one.h b/tests/wsum_hess/other/test_prod_axis_one.h index b13bbaeb..e6915a0b 100644 --- a/tests/wsum_hess/other/test_prod_axis_one.h +++ b/tests/wsum_hess/other/test_prod_axis_one.h @@ -1,9 +1,9 @@ #include #include +#include "atoms/non_elementwise_full_dom.h" #include "expr.h" #include "minunit.h" -#include "other.h" #include "test_helpers.h" const char *test_wsum_hess_prod_axis_one_no_zeros(void) diff --git a/tests/wsum_hess/other/test_prod_axis_zero.h b/tests/wsum_hess/other/test_prod_axis_zero.h index 9e7fe02f..6a54e0d5 100644 --- a/tests/wsum_hess/other/test_prod_axis_zero.h +++ b/tests/wsum_hess/other/test_prod_axis_zero.h @@ -1,9 +1,9 @@ #include #include +#include "atoms/non_elementwise_full_dom.h" #include "expr.h" #include "minunit.h" -#include "other.h" #include "test_helpers.h" const char *test_wsum_hess_prod_axis_zero_no_zeros(void) diff --git a/tests/wsum_hess/other/test_quad_form.h b/tests/wsum_hess/other/test_quad_form.h index 6387e45e..73f8a1dd 100644 --- a/tests/wsum_hess/other/test_quad_form.h +++ b/tests/wsum_hess/other/test_quad_form.h @@ -1,7 +1,7 @@ -#include "affine.h" +#include "atoms/affine.h" +#include "atoms/non_elementwise_full_dom.h" #include "expr.h" #include "minunit.h" -#include "other.h" #include "test_helpers.h" #include