Repository navigation
Conversation
SparseLinOp built its view of the matrix, and row_block, col_block and submatrix built theirs, with the default zero index base, whatever the matrix's index_base. A one-based matrix (IndexBase::One) was therefore silently misread by every product: its row or column indices were read one too high, so entries moved and the last index fell outside the matrix. The views now keep the matrix's index base. RandBLAS's sparse-dense products take zero-based matrices only, so on a one-based matrix they now throw. The sparse-sparse products reject a one-based operator up front, since the sparse-dense product they end with would. MKL's spgemm reads every matrix as zero-based, so the sparse-sparse products use it only for a zero-based B_sp, and the sketch with a sparse S only for a zero-based matrix; otherwise they take their fallback, as builds without MKL do. The fallbacks densify through sparse_to_dense, which reads a one-based COO matrix and rejects a one-based CSR or CSC one, so they now reject a one-based CSR or CSC matrix before allocating anything: the sketch with a sparse S of a one-based COO operator works, and so does a product with a one-based COO B_sp. materialize reads a one-based COO operator and throws on a one-based CSR or CSC one. The cross-direction blocks (a CSR col_block, a CSC row_block) select their range in zero-based terms and keep the base. A COO operator may sit on the leading n_rows x n_cols window of a larger matrix, which the sparse-dense products (and the sketch with a dense S, which goes through them) read as that window. Every other path reads the whole matrix: the sketch with a sparse S (spgemm, or a densified copy in a buffer of the operator's size), the sparse-sparse products, materialize (sparse_to_dense) and fro_nrm. They now require the operator's dimensions to equal its matrix's, and the sparse-sparse products also require B_sp's stored dimensions to be those the product infers from (m, n, k) and trans_B, since the fallback densifies it into a buffer of that size. All of these checks run before anything is allocated. A sparse-sparse product with a leading block of op(A) now takes the fallback instead of MKL's spgemm, which multiplied all of A_sp into the caller's smaller C; it then behaves as the sparse-dense product (COO multiplies the block, CSR and CSC throw). The temporaries that a throwing call could leak are now std::unique_ptr: the dense copies in the sketch and sparse-sparse fallbacks, materialize's copy for a padded ldb, and the operand copies of materialize's CompositeOperator overload. The class note describes the routing and the window rule; the sketch's doc says it reads the whole matrix with a sparse S; the pointer offset in csr_row_block and csc_col_block is renamed from base to offset; the make_view example in devnotes/idioms.md shows the index base and COO. Em-dashes in the touched files are swept. Tests: one-based CSR, CSC and COO operators keep the base, and their sparse-dense products throw; the row, column and submatrix blocks of one-based CSR and CSC operators keep the base and equal the zero-based blocks with indices raised by one; the sketch with a sparse S of a one-based COO operator matches the zero-based one, and a one-based CSR operator's throws; Side::Left and Side::Right (trans_A == NoTrans) products with a one-based COO B_sp match the zero-based ones, and a one-based CSR B_sp or a one-based operator throws; materialize reads a one-based COO operator and throws on one-based CSR and CSC ones, with and without a padded ldb. Each rejection is checked to name the index base. A COO operator on the leading window of a larger matrix applies as that window, while its sketch with a sparse S (zero- or one-based), its sparse-sparse product, materialize and fro_nrm throw. Sparse-sparse products with a leading block of a full-size operator, on both sides, match a dense reference for COO and throw for CSR.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes SparseLinOp silently misreading one-based sparse matrices (
IndexBase::One). Its views of the matrix, and of its blocks, were always zero-based, so every product read a one-based matrix's indices one too high. The views now keep the index base, so a one-based matrix either works or throws, and nowhere gives a wrong answer. While here, the paths that read an operator's whole matrix stop writing past their buffers when the operator is a leading window of a larger COO matrix, and when a sparse-sparse product asks for a leading block.Changes
linops/rl_sparse_views.hh,linops/rl_sparse_linop.hh:make_viewand the four block views keepindex_base; the cross-direction blocks filter byindex - base.spgemm(which assumes zero-based) is used only for zero-based matrices, otherwise the fallback runs, as without MKL;materialize); one-based CSR and CSC throw there.materializeandfro_nrmread the whole matrix, so they now require the operator's dimensions to equal its matrix's (a COO window is still supported by the sparse-dense products);spgemm, which multiplied all of A_sp into the caller's smaller C.std::unique_ptr.make_viewexample indevnotes/idioms.md.TestSparseLinOpIndexBasetests on genuinely one-based CSR, CSC and COO matrices (views and blocks keep the base; each path works or throws as listed, with the index base named in the message), COO windows, and partial sparse-sparse products on both sides. RandLAPACK_tests 731/731, extras 176/176, benchmark tree builds.