|
irlba
A C++ library for IRLBA
|
Sparse matrix with customizable parallelization. More...
#include <sparse.hpp>


Public Types | |
| typedef I< decltype(std::declval< PointerArray_ >()[0])> | PointerType |
Public Member Functions | |
| ParallelSparseMatrix () | |
| ParallelSparseMatrix (Eigen::Index nrow, Eigen::Index ncol, ValueArray_ x, IndexArray_ i, PointerArray_ p, bool column_major, int num_threads) | |
| Eigen::Index | rows () const |
| Eigen::Index | cols () const |
| const ValueArray_ & | get_values () const |
| const IndexArray_ & | get_indices () const |
| const PointerArray_ & | get_pointers () const |
| const std::vector< Eigen::Index > & | get_primary_boundaries () const |
| const std::vector< Eigen::Index > & | get_secondary_boundaries () const |
| const std::vector< std::vector< PointerType > > & | get_secondary_nonzero_boundaries () const |
| std::unique_ptr< Workspace< EigenVector_ > > | new_workspace () const |
| std::unique_ptr< AdjointWorkspace< EigenVector_ > > | new_adjoint_workspace () const |
| std::unique_ptr< RealizeWorkspace< EigenMatrix_ > > | new_realize_workspace () const |
| auto | new_known_workspace () const |
| auto | new_known_adjoint_workspace () const |
| auto | new_known_realize_workspace () const |
Public Member Functions inherited from irlba::Matrix< EigenVector_, EigenMatrix_ > | |
| std::unique_ptr< Workspace< EigenVector_ > > | new_known_workspace () const |
| std::unique_ptr< AdjointWorkspace< EigenVector_ > > | new_known_adjoint_workspace () const |
| std::unique_ptr< RealizeWorkspace< EigenMatrix_ > > | new_known_realize_workspace () const |
Sparse matrix with customizable parallelization.
This provides an alternative to Eigen::SparseMatrix for parallelized multiplication of compressed sparse matrices. Unlike Eigen's sparse matrix, this implementation is able to parallelize when the multiplication does not align well with the storage layout, e.g., multiplication of a compressed sparse column matrix by a dense vector on the right hand side. On construction, it also pre-allocates the rows and/or columns to each thread, aiming to balance the number of non-zero elements that each thread needs to process. All subsequent multiplications can then use these allocations, which is useful for compute() where the cost of pre-allocation is abrogated by repeated multiplication calls.
Some cursory testing indicates that the performance of this implementation is comparable to Eigen for OpenMP-based parallelization. However, the real purpose of this class is to support custom parallelization schemes in cases where OpenMP is not available. This is achieved by defining IRLBA_CUSTOM_PARALLEL macro to the name of a function implementing a custom scheme. Such a function should accept two arguments - an integer specifying the number of threads, and a lambda that accepts a thread number. It should then loop over the number of threads and launch one job for each thread via the lambda. Once all threads are complete, the function should return.
| EigenVector_ | A floating-point Eigen::Vector to be used as input/output of multiplication operations. |
| EigenMatrix_ | A dense floating-point Eigen::Matrix in which to store the realized matrix. Typically of the same scalar type as EigenVector_. |
| ValueArray_ | Array class containing numeric values for the non-zero values. Should support a read-only [] operator. |
| IndexArray_ | Array class containing integer values for the indices of the non-zero values. Should support a read-only [] operator. |
| PointerArray_ | Array class containing integer values for the pointers to the row/column boundaries. Should support a read-only [] operator. |
| I<decltype(std::declval<PointerArray_>()[0])> irlba::ParallelSparseMatrix< EigenVector_, EigenMatrix_, ValueArray_, IndexArray_, PointerArray_ >::PointerType |
Type of the elements inside a PointerArray_.
|
inline |
Default constructor. This object cannot be used for any operations.
|
inline |
| nrow | Number of rows. |
| ncol | Number of columns. |
| x | Values of non-zero elements. |
| i | Indices of non-zero elements. Each entry corresponds to a value in x, so i should be an array of length equal to x. If column_major = true, i should contain row indices; otherwise it should contain column indices. |
| p | Pointers to the start of each column (if column_major = true) or row (otherwise). This should be an ordered array of length equal to the number of columns or rows plus 1. |
| column_major | Whether the matrix should be in compressed sparse column format. If false, this is assumed to be in row-major format. |
| num_threads | Number of threads to be used for multiplication. |
x, i and p represent the typical components of a compressed sparse column/row matrix. Thus, entries in i should be sorted within each column/row, where the boundaries between columns/rows are defined by p.
|
inlinevirtual |
Implements irlba::Matrix< EigenVector_, EigenMatrix_ >.
|
inline |
i in the constructor. These are row or column indices for compressed sparse row or column format, respectively, depending on column_major.
|
inline |
p in the constructor.
|
inline |
This should only be called if num_threads > 1 in the constructor, otherwise it will not be initialized.
t-th and t + 1-th entries specifies the first and one-past-the-last elements along the primary dimension (e.g., column for column_major = true) that each thread operates on.
|
inline |
This should only be called if num_threads > 1 in the constructor, otherwise it will not be initialized.
t-th and t + 1-th entries specifies the first and one-past-the-last elements along the secondary dimension (e.g., row for column_major = true) that each thread operates on.
|
inline |
This should only be called if num_threads > 1 in the constructor, otherwise it will not be initialized.
column_major = true). For thread t, secondary_nonzero_boundaries[t][i] is the first non-zero element to be processed by this thread in the primary dimension element i, while boundaries[t + 1][i] is one-past-the-last non-zero element to be processed. This is guaranteed to contain all and only non-zero elements with indices i where secondary_boundaries[t] <= i < secondary_boundaries[t + 1].
|
inline |
x in the constructor.
|
inlinevirtual |
Matrix. Implements irlba::Matrix< EigenVector_, EigenMatrix_ >.
|
inline |
Overrides Matrix::new_adjoint_workspace() to enable devirtualization.
|
inline |
Overrides Matrix::new_realize_workspace() to enable devirtualization.
|
inline |
Overrides Matrix::new_workspace() to enable devirtualization.
|
inlinevirtual |
Matrix. Implements irlba::Matrix< EigenVector_, EigenMatrix_ >.
|
inlinevirtual |
Matrix. Implements irlba::Matrix< EigenVector_, EigenMatrix_ >.
|
inlinevirtual |
Implements irlba::Matrix< EigenVector_, EigenMatrix_ >.