template<typename SparseMatrixType, template< typename T > class MapTraits = StdUnorderedMapTraits, int OuterPacketBits = 6>
class Eigen::RandomSetter< SparseMatrixType, MapTraits, OuterPacketBits >
The RandomSetter is a wrapper object allowing to set/update a sparse matrix with random access.
- Template Parameters
-
SparseMatrixType | the type of the sparse matrix we are updating |
MapTraits | a traits class representing the map implementation used for the temporary sparse storage. Its default value depends on the system. |
OuterPacketBits | defines the number of rows (or columns) manage by a single map object as a power of two exponent. |
This class temporarily represents a sparse matrix object using a generic map implementation allowing for efficient random access. The conversion from the compressed representation to a hash_map object is performed in the RandomSetter constructor, while the sparse matrix is updated back at destruction time. This strategy suggest the use of nested blocks as in this example:
{
RandomSetter<SparseMatrix<double> >
w(m);
for(;;)
}
Since hash_map objects are not fully sorted, representing a full matrix as a single hash_map would involve a big and costly sort to update the compressed matrix back. To overcome this issue, a RandomSetter use multiple hash_map, each representing 2^OuterPacketBits columns or rows according to the storage order. To reach optimal performance, this value should be adjusted according to the average number of nonzeros per rows/columns.
The possible values for the template parameter MapTraits are:
- StdMapTraits: corresponds to std::map. (does not perform very well)
- StdUnorderedMapTraits: corresponds to std::unordered_map
- GoogleDenseHashMapTraits: corresponds to google::dense_hash_map (best efficiency, reasonable memory consumption)
- GoogleSparseHashMapTraits: corresponds to google::sparse_hash_map (best memory consumption, relatively good performance)
The default map implementation depends on the availability, and the preferred order is: GoogleSparseHashMapTraits, StdUnorderedMapTraits, and finally StdMapTraits.
For performance and memory consumption reasons it is highly recommended to use one of Google's hash_map implementations. To enable the support for them, you must define EIGEN_GOOGLEHASH_SUPPORT. This will include both <google/dense_hash_map> and <google/sparse_hash_map> for you.
- See also
- https://github.com/sparsehash/sparsehash
Definition at line 162 of file RandomSetter.h.