@@ -25,31 +25,29 @@ typedef struct CSR_Matrix
2525 int nnz ;
2626} CSR_Matrix ;
2727
28- /* Allocate a new CSR matrix with given dimensions and nnz */
28+ /* constructors and destructors */
2929CSR_Matrix * new_csr_matrix (int m , int n , int nnz );
30-
31- /* Free a CSR matrix */
30+ CSR_Matrix * new_csr (const CSR_Matrix * A );
3231void free_csr_matrix (CSR_Matrix * matrix );
33-
34- /* Copy CSR matrix A to C */
3532void copy_csr_matrix (const CSR_Matrix * A , CSR_Matrix * C );
3633
37- /* Build block-diagonal repeat A_blk = I_p kron A. Returns newly allocated CSR
38- * matrix of size (p*A->m) x (p*A->n) with nnz = p*A->nnz. */
34+ /* transpose functionality (iwork must be of size A->n) */
35+ CSR_Matrix * transpose (const CSR_Matrix * A , int * iwork );
36+ CSR_Matrix * AT_alloc (const CSR_Matrix * A , int * iwork );
37+ void AT_fill_values (const CSR_Matrix * A , CSR_Matrix * AT , int * iwork );
38+
39+ /* Build (I_p kron A) = blkdiag(A, A, ..., A) of size (p*A->m) x (p*A->n) */
3940CSR_Matrix * block_diag_repeat_csr (const CSR_Matrix * A , int p );
4041
41- /* Build left-repeated Kronecker A_kron = A kron I_p. Returns newly allocated CSR
42- * matrix of size (A->m * p) x (A->n * p) with nnz = A->nnz * p. */
42+ /* Build (A kron I_p) of size (A->m * p) x (A->n * p) with nnz = A->nnz * p. */
4343CSR_Matrix * kron_identity_csr (const CSR_Matrix * A , int p );
4444
45- /* matvec y = Ax, where A indices minus col_offset gives x indices. Returns y as
46- * dense. */
45+ /* y = Ax, where y is returned as dense */
4746void csr_matvec (const CSR_Matrix * A , const double * x , double * y , int col_offset );
4847void csr_matvec_wo_offset (const CSR_Matrix * A , const double * x , double * y );
4948
50- /* C = z^T A is assumed to have one row. C must have column indices pre-computed
51- and transposed matrix AT must be provided. Fills in values of C only.
52- */
49+ /* Computes values of the row matrix C = z^T A (column indices must have been
50+ pre-computed) and transposed matrix AT must be provided) */
5351void csr_matvec_fill_values (const CSR_Matrix * AT , const double * z , CSR_Matrix * C );
5452
5553/* Insert value into CSR matrix A with just one row at col_idx. Assumes that A
@@ -63,92 +61,6 @@ void csr_insert_value(CSR_Matrix *A, int col_idx, double value);
6361void diag_csr_mult (const double * d , const CSR_Matrix * A , CSR_Matrix * C );
6462void diag_csr_mult_fill_values (const double * d , const CSR_Matrix * A , CSR_Matrix * C );
6563
66- /* Compute C = A + B where A, B, C are CSR matrices
67- * A and B must have same dimensions
68- * C must be pre-allocated with sufficient nnz capacity.
69- * C must be different from A and B */
70- void sum_csr_matrices (const CSR_Matrix * A , const CSR_Matrix * B , CSR_Matrix * C );
71- /* Compute sparsity pattern of A + B where A, B, C are CSR matrices.
72- * Fills C->p, C->i, and C->nnz; does not touch C->x. */
73- void sum_csr_matrices_fill_sparsity (const CSR_Matrix * A , const CSR_Matrix * B ,
74- CSR_Matrix * C );
75-
76- /* Fill only the values of C = A + B, assuming C's sparsity pattern (p and i)
77- * is already filled and matches the union of A and B per row. Does not modify
78- * C->p, C->i, or C->nnz. */
79- void sum_csr_matrices_fill_values (const CSR_Matrix * A , const CSR_Matrix * B ,
80- CSR_Matrix * C );
81-
82- /* Compute C = diag(d1) * A + diag(d2) * B where A, B, C are CSR matrices */
83- void sum_scaled_csr_matrices (const CSR_Matrix * A , const CSR_Matrix * B , CSR_Matrix * C ,
84- const double * d1 , const double * d2 );
85-
86- /* Fill only the values of C = diag(d1) * A + diag(d2) * B, assuming C's sparsity
87- * pattern (p and i) is already filled and matches the union of A and B per row.
88- * Does not modify C->p, C->i, or C->nnz. */
89- void sum_scaled_csr_matrices_fill_values (const CSR_Matrix * A , const CSR_Matrix * B ,
90- CSR_Matrix * C , const double * d1 ,
91- const double * d2 );
92-
93- /* Sum all rows of A into a single row matrix C */
94- void sum_all_rows_csr (const CSR_Matrix * A , CSR_Matrix * C ,
95- struct int_double_pair * pairs );
96-
97- /* iwork must have size max(C->n, A->nnz), and idx_map must have size A->nnz. */
98- void sum_all_rows_csr_fill_sparsity_and_idx_map (const CSR_Matrix * A , CSR_Matrix * C ,
99- int * iwork , int * idx_map );
100-
101- /* Fill values of summed rows using precomputed idx_map and sparsity of C */
102- // void sum_all_rows_csr_fill_values(const CSR_Matrix *A, CSR_Matrix *C,
103- // const int *idx_map);
104-
105- /* Fill accumulator for summing rows using precomputed idx_map for each nnz of A.
106- Must memset accumulator to zero before calling. */
107- void idx_map_accumulator (const CSR_Matrix * A , const int * idx_map ,
108- double * accumulator );
109- void idx_map_accumulator_with_spacing (const CSR_Matrix * A , const int * idx_map ,
110- double * accumulator , int spacing );
111-
112- /* Sum blocks of rows of A into a matrix C */
113- void sum_block_of_rows_csr (const CSR_Matrix * A , CSR_Matrix * C ,
114- struct int_double_pair * pairs , int row_block_size );
115-
116- /* Build sparsity and index map for summing blocks of rows.
117- * iwork must have size max(A->n, A->nnz), and idx_map must have size A->nnz. */
118- void sum_block_of_rows_csr_fill_sparsity_and_idx_map (const CSR_Matrix * A ,
119- CSR_Matrix * C ,
120- int row_block_size , int * iwork ,
121- int * idx_map );
122-
123- /* Fill values for summing blocks of rows using precomputed idx_map */
124- // void sum_block_of_rows_csr_fill_values(const CSR_Matrix *A, CSR_Matrix *C,
125- // const int *idx_map);
126-
127- /* Sum evenly spaced rows of A into a matrix C */
128- void sum_evenly_spaced_rows_csr (const CSR_Matrix * A , CSR_Matrix * C ,
129- struct int_double_pair * pairs , int row_spacing );
130-
131- /* Build sparsity and index map for summing evenly spaced rows.
132- * iwork must have size max(A->n, A->nnz), and idx_map must have size A->nnz. */
133- void sum_evenly_spaced_rows_csr_fill_sparsity_and_idx_map (const CSR_Matrix * A ,
134- CSR_Matrix * C ,
135- int row_spacing ,
136- int * iwork , int * idx_map );
137-
138- /* Fill values for summing evenly spaced rows using precomputed idx_map */
139- // void sum_evenly_spaced_rows_csr_fill_values(const CSR_Matrix *A, CSR_Matrix *C,
140- // const int *idx_map);
141-
142- /* Sum evenly spaced rows of A starting at offset into a row matrix C */
143- void sum_spaced_rows_into_row_csr (const CSR_Matrix * A , CSR_Matrix * C ,
144- struct int_double_pair * pairs , int offset ,
145- int spacing );
146- /* Fills the sparsity and index map for summing spaced rows into a row matrix */
147- void sum_spaced_rows_into_row_csr_fill_sparsity_and_idx_map (const CSR_Matrix * A ,
148- CSR_Matrix * C ,
149- int spacing , int * iwork ,
150- int * idx_map );
151-
15264/* Count number of columns with nonzero entries */
15365int count_nonzero_cols (const CSR_Matrix * A , bool * col_nz );
15466
@@ -157,13 +69,6 @@ void insert_idx(int idx, int *arr, int len);
15769
15870double csr_get_value (const CSR_Matrix * A , int row , int col );
15971
160- /* iwork must be of size A->n*/
161- CSR_Matrix * transpose (const CSR_Matrix * A , int * iwork );
162- CSR_Matrix * AT_alloc (const CSR_Matrix * A , int * iwork );
163-
164- /* Fill values of A^T given sparsity pattern is already computed */
165- void AT_fill_values (const CSR_Matrix * A , CSR_Matrix * AT , int * iwork );
166-
16772/* Expand symmetric CSR matrix A to full matrix C. A is assumed to store
16873 only upper triangle. C must be pre-allocated with sufficient nnz */
16974void symmetrize_csr (const int * Ap , const int * Ai , int m , CSR_Matrix * C );
0 commit comments