.. default-domain:: chpl .. module:: Sparse :synopsis: Support for Linear Algebra routines involving sparse data. Sparse ====== **Usage** .. code-block:: chapel use LinearAlgebra.Sparse; or .. code-block:: chapel import LinearAlgebra.Sparse; Support for Linear Algebra routines involving sparse data. A high-level interface to linear algebra operations and procedures for sparse matrices (2D arrays). Sparse matrices are represented as 2D arrays domain-mapped to a sparse *layout*. All sparse operations support the CSR layout (``LayoutCS.CS(compressRows=true)``) and some operations support COO layout (default sparse array layout). See the :ref:`Sparse Primer ` for more information about working with sparse domains and arrays in Chapel. Sparse Linear Algebra Interface ------------------------------- ``LinearAlgebra.Sparse`` follows the same conventions and interface choices as the parent module, ``LinearAlgebra``, with few exceptions. These exceptions are detailed below. **Sparse Domains** In Chapel, changes to the index set of a sparse array must be made directly on the sparse domain. When working with sparse arrays that will require index modification, it is necessary to maintain access to their sparse domains as well. As a result of this, the sparse linear algebra interface provides helper functions for creating both sparse domains and sparse arrays. A common usage of this interface might look like this: .. code-block:: chapel // Create an empty 3x3 CSR domain var D = CSRDomain(3,3); // Create a CSR matrix over this domain var A = CSRMatrix(D, int); // The above is equivalent to: // var A: [D] int; // Add indices to the sparse domain along the diagonal D += (0,0); D += (1,1); D += (2,2); // Set all nonzero indices to the value of 1 A = 1; // A is now a 3x3 sparse identity matrix writeln(A); .. note:: This is an early prototype package submodule. As a result, interfaces may change over the next release. .. function:: proc CSRDomain(rows) where isIntegral(rows) Return an empty CSR domain over parent domain: ``{0..