diff --git a/RandBLAS/sparse_data/base.hh b/RandBLAS/sparse_data/base.hh index ba7dfe42..c22eeef1 100644 --- a/RandBLAS/sparse_data/base.hh +++ b/RandBLAS/sparse_data/base.hh @@ -36,13 +36,13 @@ namespace RandBLAS::sparse_data { -enum class IndexBase : char { +enum class IndexBase : int { // --------------------------------------------------------------- // zero-based indexing - Zero = 'Z', + Zero = 0, // --------------------------------------------------------------- // one-based indexing - One = 'O' + One = 1 }; template diff --git a/RandBLAS/sparse_data/conversions.hh b/RandBLAS/sparse_data/conversions.hh index 04b7ed64..d7991f0a 100644 --- a/RandBLAS/sparse_data/conversions.hh +++ b/RandBLAS/sparse_data/conversions.hh @@ -47,7 +47,7 @@ void coo_to_csc(COOMatrix &coo, CSCMatrix &csc) { randblas_require(csc.index_base == IndexBase::Zero); randblas_require(coo.index_base == IndexBase::Zero); sort_coo_data(NonzeroSort::CSC, coo); - csc.reserve(coo.nnz); + reserve(coo.nnz, csc); csc.colptr[0] = 0; int64_t ell = 0; for (int64_t j = 0; j < coo.n_cols; ++j) { @@ -67,7 +67,7 @@ void csc_to_coo(CSCMatrix &csc, COOMatrix &coo) { randblas_require(csc.n_cols == coo.n_cols); randblas_require(csc.index_base == IndexBase::Zero); randblas_require(coo.index_base == IndexBase::Zero); - coo.reserve(csc.nnz); + reserve(csc.nnz, coo); int64_t ell = 0; for (int64_t j = 0; j < csc.n_cols; ++j) { for (int64_t i = csc.colptr[j]; i < csc.colptr[j+1]; ++i) { @@ -88,7 +88,7 @@ void coo_to_csr(COOMatrix &coo, CSRMatrix &csr) { randblas_require(csr.index_base == IndexBase::Zero); randblas_require(coo.index_base == IndexBase::Zero); sort_coo_data(NonzeroSort::CSR, coo); - csr.reserve(coo.nnz); + reserve(coo.nnz, csr); csr.rowptr[0] = (sint_t2) 0; int64_t ell = 0; for (int64_t i = 0; i < coo.n_rows; ++i) { @@ -108,7 +108,7 @@ void csr_to_coo(CSRMatrix &csr, COOMatrix &coo) { randblas_require(csr.n_cols == coo.n_cols); randblas_require(csr.index_base == IndexBase::Zero); randblas_require(coo.index_base == IndexBase::Zero); - coo.reserve(csr.nnz); + reserve(csr.nnz, coo); int64_t ell = 0; for (int64_t i = 0; i < csr.n_rows; ++i) { for (int64_t j = csr.rowptr[i]; j < csr.rowptr[i+1]; ++j) { @@ -129,7 +129,7 @@ CSRMatrix transpose_as_csr(CSCMatrix &A, bool share_memory return At; } else { CSRMatrix At(A.n_cols, A.n_rows, A.index_base); - At.reserve(A.nnz); + reserve(A.nnz, At); for (int64_t i = 0; i < A.nnz; ++i) { At.colidxs[i] = A.rowidxs[i]; At.vals[i] = A.vals[i]; @@ -147,7 +147,7 @@ CSCMatrix transpose_as_csc(CSRMatrix &A, bool share_memory return At; } else { CSCMatrix At(A.n_cols, A.n_rows, A.index_base); - At.reserve(A.nnz); + reserve(A.nnz, At); for (int64_t i = 0; i < A.nnz; ++i) { At.rowidxs[i] = A.colidxs[i]; At.vals[i] = A.vals[i]; diff --git a/RandBLAS/sparse_data/coo_matrix.hh b/RandBLAS/sparse_data/coo_matrix.hh index 0a29e610..65d86ab5 100644 --- a/RandBLAS/sparse_data/coo_matrix.hh +++ b/RandBLAS/sparse_data/coo_matrix.hh @@ -112,22 +112,20 @@ struct COOMatrix { bool own_memory; int64_t nnz = 0; IndexBase index_base; - T *vals = nullptr; + T *vals; // --------------------------------------------------------------------------- - /// Row indicies for nonzeros. - sint_t *rows = nullptr; + /// Row indicies for nonzeros. If non-null, this is presumed to have length + /// at least \math{\ttt{nnz}.} + sint_t *rows; // --------------------------------------------------------------------------- - /// Column indicies for nonzeros - sint_t *cols = nullptr; + /// Column indicies for nonzeros. If non-null, this is presumed to have length + /// at least \math{\ttt{nnz}.} + sint_t *cols; // --------------------------------------------------------------------------- - /// A flag to indicate if the data in (rows, cols, vals) is sorted in a + /// A flag to indicate if the data in (vals, rows, cols) is sorted in a /// CSC-like order, a CSR-like order, or neither order. NonzeroSort sort = NonzeroSort::None; - bool _can_reserve = true; - // ^ A flag to indicate if we're allowed to allocate new memory for - // (rows, cols, vals). Set to false after COOMatrix.reserve(...) is called. - COOMatrix( int64_t n_rows, int64_t n_cols, @@ -137,15 +135,12 @@ struct COOMatrix { sint_t *cols, bool compute_sort_type, IndexBase index_base - ) : n_rows(n_rows), n_cols(n_cols), own_memory(false), index_base(index_base) { - this->nnz = nnz; - this->vals = vals; - this->rows = rows; - this->cols = cols; + ) : n_rows(n_rows), n_cols(n_cols), own_memory(false), nnz(nnz), index_base(index_base), + vals(vals), rows(rows), cols(cols) { if (compute_sort_type) { - this->sort = coo_sort_type(nnz, rows, cols); + sort = coo_sort_type(nnz, rows, cols); } else { - this->sort = NonzeroSort::None; + sort = NonzeroSort::None; } }; @@ -153,7 +148,8 @@ struct COOMatrix { int64_t n_rows, int64_t n_cols, IndexBase index_base - ) : n_rows(n_rows), n_cols(n_cols), own_memory(true), index_base(index_base) {}; + ) : n_rows(n_rows), n_cols(n_cols), own_memory(true), nnz(0), index_base(index_base), + vals(nullptr), rows(nullptr), cols(nullptr) {}; // Constructs an empty sparse matrix of given dimensions. // Data can't stored in this object until a subsequent call to reserve(int64_t nnz). @@ -219,34 +215,13 @@ struct COOMatrix { ) : COOMatrix(n_rows, n_cols, nnz, vals, rows, cols, compute_sort_type, IndexBase::Zero) {}; ~COOMatrix() { - if (this->own_memory) { + if (own_memory) { if (vals != nullptr) delete [] vals; if (rows != nullptr) delete [] rows; if (cols != nullptr) delete [] cols; } }; - // @verbatim embed:rst:leading-slashes - // Attach three buffers of length nnz for (vals, rows, cols). - // This function can only be called if :math:`\ttt{own_memory == true},`` and - // it can only be called once. - // - // @endverbatim - void reserve(int64_t nnz) { - randblas_require(this->_can_reserve); - randblas_require(this->own_memory); - randblas_require(vals == nullptr); - randblas_require(rows == nullptr); - randblas_require(cols == nullptr); - this->nnz = nnz; - if (this->nnz > 0) { - vals = new T[nnz]; - rows = new sint_t[nnz]; - cols = new sint_t[nnz]; - } - _can_reserve = false; - } - ///////////////////////////////////////////////////////////////////// // // Undocumented functions (don't appear in doxygen) @@ -255,12 +230,12 @@ struct COOMatrix { // move constructor COOMatrix(COOMatrix &&other) - : n_rows(other.n_rows), n_cols(other.n_cols), own_memory(other.own_memory), index_base(other.index_base) { - this->nnz = other.nnz; - std::swap(this->rows, other.rows); - std::swap(this->cols, other.cols); - std::swap(this->vals, other.vals); - this->_can_reserve = other._can_reserve; + : n_rows(other.n_rows), n_cols(other.n_cols), own_memory(other.own_memory), nnz(0), index_base(other.index_base), + vals(nullptr), rows(nullptr), cols(nullptr) { + nnz = other.nnz; + std::swap(rows, other.rows); + std::swap(cols, other.cols); + std::swap(vals, other.vals); other.nnz = 0; } @@ -271,6 +246,22 @@ static_assert(SparseMatrix>); static_assert(SparseMatrix>); #endif + +template +void reserve(int64_t nnz, COOMatrix &M) { + randblas_require(M.own_memory); + randblas_require(M.vals == nullptr); + randblas_require(M.rows == nullptr); + randblas_require(M.cols == nullptr); + M.nnz = nnz; + if (M.nnz > 0) { + M.vals = new T[nnz]; + M.rows = new sint_t[nnz]; + M.cols = new sint_t[nnz]; + } + return; +} + template void sort_coo_data(NonzeroSort s, int64_t nnz, T *vals, sint_t *rows, sint_t *cols) { if (s == NonzeroSort::None) @@ -358,7 +349,7 @@ void dense_to_coo(int64_t stride_row, int64_t stride_col, T *mat, T abs_tol, COO int64_t n_rows = spmat.n_rows; int64_t n_cols = spmat.n_cols; int64_t nnz = nnz_in_dense(n_rows, n_cols, stride_row, stride_col, mat, abs_tol); - spmat.reserve(nnz); + reserve(nnz, spmat); nnz = 0; #define MAT(_i, _j) mat[(_i) * stride_row + (_j) * stride_col] for (int64_t i = 0; i < n_rows; ++i) { @@ -386,7 +377,6 @@ void dense_to_coo(Layout layout, T* mat, T abs_tol, COOMatrix &spmat) { template void coo_to_dense(const COOMatrix &spmat, int64_t stride_row, int64_t stride_col, T *mat) { - randblas_require(spmat.index_base == IndexBase::Zero); #define MAT(_i, _j) mat[(_i) * stride_row + (_j) * stride_col] for (int64_t i = 0; i < spmat.n_rows; ++i) { for (int64_t j = 0; j < spmat.n_cols; ++j) { diff --git a/RandBLAS/sparse_data/coo_spmm_impl.hh b/RandBLAS/sparse_data/coo_spmm_impl.hh index 2f798eae..a32bdb04 100644 --- a/RandBLAS/sparse_data/coo_spmm_impl.hh +++ b/RandBLAS/sparse_data/coo_spmm_impl.hh @@ -42,7 +42,9 @@ namespace RandBLAS::sparse_data::coo { -template +using RandBLAS::SignedInteger; + +template static int64_t set_filtered_coo( // COO-format matrix data const T *vals, @@ -75,8 +77,7 @@ static int64_t set_filtered_coo( } - -template +template static void apply_coo_left_jki_p11( T alpha, blas::Layout layout_B, diff --git a/RandBLAS/sparse_data/csc_matrix.hh b/RandBLAS/sparse_data/csc_matrix.hh index 15933dbd..e601c8e7 100644 --- a/RandBLAS/sparse_data/csc_matrix.hh +++ b/RandBLAS/sparse_data/csc_matrix.hh @@ -36,10 +36,12 @@ namespace RandBLAS::sparse_data { +using RandBLAS::SignedInteger; + // ============================================================================= /// A CSC-format sparse matrix that complies with the SparseMatrix concept. /// -template +template struct CSCMatrix { using scalar_t = T; using index_t = sint_t; @@ -48,26 +50,26 @@ struct CSCMatrix { bool own_memory; int64_t nnz = 0; IndexBase index_base; - T *vals = nullptr; + T *vals; // --------------------------------------------------------------------------- /// Row index array in the CSC format. /// - sint_t *rowidxs = nullptr; + sint_t *rowidxs; // --------------------------------------------------------------------------- /// Pointer offset array for the CSC format. The number of nonzeros in column j /// is given by colptr[j+1] - colptr[j]. The row index of the k-th nonzero /// in column j is rowidxs[colptr[j] + k]. /// - sint_t *colptr = nullptr; - bool _can_reserve = true; + sint_t *colptr; CSCMatrix( int64_t n_rows, int64_t n_cols, IndexBase index_base - ) : n_rows(n_rows), n_cols(n_cols), own_memory(true), index_base(index_base) { }; + ) : n_rows(n_rows), n_cols(n_cols), own_memory(true), nnz(0), index_base(index_base), + vals(nullptr), rowidxs(nullptr), colptr(nullptr) { }; CSCMatrix( int64_t n_rows, @@ -77,12 +79,8 @@ struct CSCMatrix { sint_t *rowidxs, sint_t *colptr, IndexBase index_base - ) : n_rows(n_rows), n_cols(n_cols), own_memory(false), index_base(index_base) { - this->nnz = nnz; - this->vals = vals; - this->rowidxs = rowidxs; - this->colptr = colptr; - }; + ) : n_rows(n_rows), n_cols(n_cols), own_memory(false), nnz(nnz), index_base(index_base), + vals(vals), rowidxs(rowidxs), colptr(colptr) { }; // Constructs an empty sparse matrix of given dimensions. // Data can't stored in this object until a subsequent call to reserve(int64_t nnz). @@ -135,43 +133,20 @@ struct CSCMatrix { ) : CSCMatrix(n_rows, n_cols, nnz, vals, rowidxs, colptr, IndexBase::Zero) {}; ~CSCMatrix() { - if (this->own_memory) { + if (own_memory) { if (rowidxs != nullptr) delete [] rowidxs; if (colptr != nullptr) delete [] colptr; if (vals != nullptr) delete [] vals; } }; - - // @verbatim embed:rst:leading-slashes - // Attach three buffers to this CSCMatrix, (vals, rowidxs, colptr), of sufficient - // size for this matrix to hold nnz structural nonzeros. - // This function can only be called if :math:`\ttt{own_memory == true},`` and - // it can only be called once. - // - // @endverbatim - void reserve(int64_t nnz) { - randblas_require(_can_reserve); - randblas_require(own_memory); - if (colptr == nullptr) - colptr = new sint_t[n_cols + 1]{0}; - this->nnz = nnz; - if (nnz > 0) { - randblas_require( rowidxs == nullptr ); - randblas_require( vals == nullptr ); - rowidxs = new sint_t[nnz]{0}; - vals = new T[nnz]{0.0}; - } - _can_reserve = false; - }; - CSCMatrix(CSCMatrix &&other) - : n_rows(other.n_rows), n_cols(other.n_cols), own_memory(other.own_memory), index_base(other.index_base) { - this->nnz = other.nnz; - std::swap(this->rowidxs, other.rowidxs); - std::swap(this->colptr , other.colptr ); - std::swap(this->vals , other.vals ); - this->_can_reserve = other._can_reserve; + : n_rows(other.n_rows), n_cols(other.n_cols), own_memory(other.own_memory), nnz(0), index_base(other.index_base), + vals(nullptr), rowidxs(nullptr), colptr(nullptr) { + nnz = other.nnz; + std::swap(rowidxs, other.rowidxs); + std::swap(colptr , other.colptr ); + std::swap(vals , other.vals ); other.nnz = 0; }; }; @@ -181,6 +156,22 @@ static_assert(SparseMatrix>); static_assert(SparseMatrix>); #endif + +template +void reserve(int64_t nnz, CSCMatrix &M) { + randblas_require(M.own_memory); + if (M.colptr == nullptr) + M.colptr = new sint_t[M.n_cols + 1]{0}; + M.nnz = nnz; + if (nnz > 0) { + randblas_require( M.rowidxs == nullptr ); + randblas_require( M.vals == nullptr ); + M.rowidxs = new sint_t[nnz]{0}; + M.vals = new T[nnz]{0.0}; + } + return; +} + } // end namespace RandBLAS::sparse_data namespace RandBLAS::sparse_data::csc { @@ -226,7 +217,7 @@ void dense_to_csc(int64_t stride_row, int64_t stride_col, T *mat, T abs_tol, CSC // Step 1: count the number of entries with absolute value at least abstol int64_t nnz = nnz_in_dense(n_rows, n_cols, stride_row, stride_col, mat, abs_tol); // Step 2: allocate memory needed by the sparse matrix - spmat.reserve(nnz); + reserve(nnz, spmat); // Step 3: traverse the dense matrix again, populating the sparse matrix as we go nnz = 0; spmat.colptr[0] = 0; diff --git a/RandBLAS/sparse_data/csc_spmm_impl.hh b/RandBLAS/sparse_data/csc_spmm_impl.hh index 77d63654..46cbaf53 100644 --- a/RandBLAS/sparse_data/csc_spmm_impl.hh +++ b/RandBLAS/sparse_data/csc_spmm_impl.hh @@ -40,7 +40,9 @@ namespace RandBLAS::sparse_data::csc { -template +using RandBLAS::SignedInteger; + +template static void apply_csc_to_vector_from_left_ki( // CSC-format data const T *vals, @@ -64,7 +66,7 @@ static void apply_csc_to_vector_from_left_ki( } } -template +template static void apply_regular_csc_to_vector_from_left_ki( // data for "regular CSC": CSC with fixed nnz per col, // which obviates the requirement for colptr. @@ -87,7 +89,7 @@ static void apply_regular_csc_to_vector_from_left_ki( } } -template +template static void apply_csc_left_jki_p11( T alpha, blas::Layout layout_B, @@ -152,7 +154,7 @@ static void apply_csc_left_jki_p11( return; } -template +template static void apply_csc_left_kib_rowmajor_1p1( T alpha, int64_t d, diff --git a/RandBLAS/sparse_data/csr_matrix.hh b/RandBLAS/sparse_data/csr_matrix.hh index 2c3e328c..ccb30d4b 100644 --- a/RandBLAS/sparse_data/csr_matrix.hh +++ b/RandBLAS/sparse_data/csr_matrix.hh @@ -52,26 +52,26 @@ struct CSRMatrix { bool own_memory; int64_t nnz = 0; IndexBase index_base; - T *vals = nullptr; + T *vals; // --------------------------------------------------------------------------- /// Pointer offset array for the CSR format. The number of nonzeros in row i /// is given by rowptr[i+1] - rowptr[i]. The column index of the k-th nonzero /// in row i is colidxs[rowptr[i] + k]. /// - sint_t *rowptr = nullptr; + sint_t *rowptr; // --------------------------------------------------------------------------- /// Column index array in the CSR format. /// - sint_t *colidxs = nullptr; - bool _can_reserve = true; + sint_t *colidxs; CSRMatrix( int64_t n_rows, int64_t n_cols, IndexBase index_base - ) : n_rows(n_rows), n_cols(n_cols), own_memory(true), index_base(index_base) { }; + ) : n_rows(n_rows), n_cols(n_cols), own_memory(true), nnz(0), index_base(index_base), + vals(nullptr), rowptr(nullptr), colidxs(nullptr) { }; CSRMatrix( int64_t n_rows, @@ -81,12 +81,8 @@ struct CSRMatrix { sint_t *rowptr, sint_t *colidxs, IndexBase index_base - ) : n_rows(n_rows), n_cols(n_cols), own_memory(false), index_base(index_base) { - this->nnz = nnz; - this->vals = vals; - this->rowptr = rowptr; - this->colidxs = colidxs; - }; + ) : n_rows(n_rows), n_cols(n_cols), own_memory(false), nnz(nnz), index_base(index_base), + vals(vals), rowptr(rowptr), colidxs(colidxs) { }; // Constructs an empty sparse matrix of given dimensions. // Data can't stored in this object until a subsequent call to reserve(int64_t nnz). @@ -146,42 +142,14 @@ struct CSRMatrix { } }; - // @verbatim embed:rst:leading-slashes - // Attach three buffers to this CSRMatrix, (vals, rowptr, colidxs), of sufficient - // size for this matrix to hold nnz structural nonzeros. - // This function can only be called if :math:`\ttt{own_memory == true},`` and - // it can only be called once. - // - // @endverbatim - void reserve(int64_t nnz) { - randblas_require(_can_reserve); - randblas_require(own_memory); - if (rowptr == nullptr) - rowptr = new sint_t[n_rows + 1]{0}; - this->nnz = nnz; - if (nnz > 0) { - randblas_require(colidxs == nullptr); - randblas_require(vals == nullptr); - colidxs = new sint_t[nnz]{0}; - vals = new T[nnz]{0.0}; - } - _can_reserve = false; - }; - - ///////////////////////////////////////////////////////////////////// - // - // Functions that we don't want to appear in doxygen. - // - ///////////////////////////////////////////////////////////////////// - // move constructor CSRMatrix(CSRMatrix &&other) - : n_rows(other.n_rows), n_cols(other.n_cols), own_memory(other.own_memory), index_base(other.index_base) { - this->nnz = other.nnz; - std::swap(this->colidxs, other.colidxs); - std::swap(this->rowptr , other.rowptr ); - std::swap(this->vals , other.vals ); - this->_can_reserve = other._can_reserve; + : n_rows(other.n_rows), n_cols(other.n_cols), own_memory(other.own_memory), nnz(0), index_base(other.index_base), + vals(nullptr), rowptr(nullptr), colidxs(nullptr) { + nnz = other.nnz; + std::swap(colidxs, other.colidxs); + std::swap(rowptr , other.rowptr ); + std::swap(vals , other.vals ); other.nnz = 0; }; @@ -192,6 +160,22 @@ static_assert(SparseMatrix>); static_assert(SparseMatrix>); #endif + +template +void reserve(int64_t nnz, CSRMatrix &M) { + randblas_require(M.own_memory); + if (M.rowptr == nullptr) + M.rowptr = new sint_t[M.n_rows + 1]{0}; + M.nnz = nnz; + if (nnz > 0) { + randblas_require(M.colidxs == nullptr); + randblas_require(M.vals == nullptr); + M.colidxs = new sint_t[nnz]{0}; + M.vals = new T[nnz]{0.0}; + } + return; +} + } // end namespace RandBLAS::sparse_data namespace RandBLAS::sparse_data::csr { @@ -202,7 +186,7 @@ using blas::Layout; template void csr_to_dense(const CSRMatrix &spmat, int64_t stride_row, int64_t stride_col, T *mat) { randblas_require(spmat.index_base == IndexBase::Zero); - auto rowptr = spmat.rowptr; + auto rowptr = spmat.rowptr; auto colidxs = spmat.colidxs; auto vals = spmat.vals; #define MAT(_i, _j) mat[(_i) * stride_row + (_j) * stride_col] @@ -240,7 +224,7 @@ void dense_to_csr(int64_t stride_row, int64_t stride_col, T *mat, T abs_tol, CSR // Step 1: count the number of entries with absolute value at least abstol int64_t nnz = nnz_in_dense(n_rows, n_cols, stride_row, stride_col, mat, abs_tol); // Step 2: allocate memory needed by the sparse matrix - spmat.reserve(nnz); + reserve(nnz, spmat); // Step 3: traverse the dense matrix again, populating the sparse matrix as we go nnz = 0; spmat.rowptr[0] = 0; diff --git a/RandBLAS/sparse_data/csr_spmm_impl.hh b/RandBLAS/sparse_data/csr_spmm_impl.hh index 1665c6ec..2958b283 100644 --- a/RandBLAS/sparse_data/csr_spmm_impl.hh +++ b/RandBLAS/sparse_data/csr_spmm_impl.hh @@ -42,7 +42,9 @@ namespace RandBLAS::sparse_data::csr { -template +using RandBLAS::SignedInteger; + +template static void apply_csr_to_vector_from_left_ik( // CSR-format data const T *vals, @@ -66,7 +68,7 @@ static void apply_csr_to_vector_from_left_ik( } } -template +template static void apply_csr_left_jik_p11( T alpha, blas::Layout layout_B, @@ -119,7 +121,7 @@ static void apply_csr_left_jik_p11( return; } -template +template static void apply_csr_left_ikb_rowmajor( T alpha, int64_t d, diff --git a/examples/sparse-low-rank-approx/qrcp_matrixmarket.cc b/examples/sparse-low-rank-approx/qrcp_matrixmarket.cc index 7e42059f..1576d95e 100644 --- a/examples/sparse-low-rank-approx/qrcp_matrixmarket.cc +++ b/examples/sparse-low-rank-approx/qrcp_matrixmarket.cc @@ -80,7 +80,7 @@ COOMatrix from_matrix_market(std::string fn) { ); COOMatrix out(n_rows, n_cols); - out.reserve(vals.size()); + reserve(vals.size(),out); for (int i = 0; i < out.nnz; ++i) { out.rows[i] = rows[i]; out.cols[i] = cols[i]; diff --git a/examples/sparse-low-rank-approx/svd_matrixmarket.cc b/examples/sparse-low-rank-approx/svd_matrixmarket.cc index e441a188..35d2de1b 100644 --- a/examples/sparse-low-rank-approx/svd_matrixmarket.cc +++ b/examples/sparse-low-rank-approx/svd_matrixmarket.cc @@ -77,7 +77,7 @@ COOMatrix from_matrix_market(std::string fn) { ); COOMatrix out(n_rows, n_cols); - out.reserve(vals.size()); + reserve(vals.size(), out); for (int i = 0; i < out.nnz; ++i) { out.rows[i] = rows[i]; out.cols[i] = cols[i]; diff --git a/examples/sparse-low-rank-approx/svd_rank1_plus_noise.cc b/examples/sparse-low-rank-approx/svd_rank1_plus_noise.cc index ba9d655e..bc56f5b2 100644 --- a/examples/sparse-low-rank-approx/svd_rank1_plus_noise.cc +++ b/examples/sparse-low-rank-approx/svd_rank1_plus_noise.cc @@ -131,7 +131,7 @@ SpMat sum_of_coo_matrices(SpMat &A, SpMat &B) { } SpMat C(A.n_rows, A.n_cols); - C.reserve(c_dict.size()); + reserve(c_dict.size(),C); int64_t ell = 0; for (auto iter : c_dict) { Tuple t = iter.first; @@ -151,7 +151,7 @@ void make_signal_matrix(double signal_scale, double* u, int64_t m, double* v, in using sint_t = typename SpMat::index_t; constexpr bool valid_type = std::is_same_v>; randblas_require(valid_type); - signal_sparse.reserve(vec_nnz * vec_nnz); + reserve(vec_nnz * vec_nnz, signal_sparse); // populate signal_dense and signal_sparse. RandBLAS::RNGState u_state(0); @@ -162,8 +162,8 @@ void make_signal_matrix(double signal_scale, double* u, int64_t m, double* v, in double uv_scale = 1.0 / std::sqrt((double) vec_nnz); - auto v_state = RandBLAS::repeated_fisher_yates(u_state, vec_nnz, m, 1, work_idxs, trash, work_vals); - auto next_state = RandBLAS::repeated_fisher_yates(v_state, vec_nnz, n, 1, work_idxs+vec_nnz, trash, work_vals+vec_nnz); + auto v_state = RandBLAS::sparse::repeated_fisher_yates(u_state, vec_nnz, m, 1, work_idxs, trash, work_vals); + auto next_state = RandBLAS::sparse::repeated_fisher_yates(v_state, vec_nnz, n, 1, work_idxs+vec_nnz, trash, work_vals+vec_nnz); for (int j = 0; j < vec_nnz; ++j) { for (int i = 0; i < vec_nnz; ++i) { int temp = i + j*vec_nnz; diff --git a/test/test_datastructures/test_spmats/common.hh b/test/test_datastructures/test_spmats/common.hh index c41b8735..be053fdb 100644 --- a/test/test_datastructures/test_spmats/common.hh +++ b/test/test_datastructures/test_spmats/common.hh @@ -108,7 +108,7 @@ void coo_from_diag( int64_t offset, RandBLAS::sparse_data::COOMatrix &spmat ) { - spmat.reserve(nnz); + reserve(nnz, spmat); int64_t ell = 0; if (offset >= 0) { randblas_require(nnz <= spmat.n_rows); diff --git a/test/test_datastructures/test_spmats/test_csr.cc b/test/test_datastructures/test_spmats/test_csr.cc index 294cb0f2..7f64f168 100644 --- a/test/test_datastructures/test_spmats/test_csr.cc +++ b/test/test_datastructures/test_spmats/test_csr.cc @@ -51,7 +51,7 @@ class TestCSR_Conversions : public ::testing::Test template static void test_csr_to_dense_diagonal(int64_t n) { CSRMatrix A(n, n, IndexBase::Zero); - A.reserve(n); + reserve(n, A); for (int i = 0; i < n; ++i) { A.vals[i] = 1.0 + (T) i; A.rowptr[i] = i;