Classes | Public Member Functions | Protected Attributes | Private Types | Static Private Attributes | List of all members
Eigen::RandomSetter< SparseMatrixType, MapTraits, OuterPacketBits > Class Template Reference

The RandomSetter is a wrapper object allowing to set/update a sparse matrix with random access. More...

#include <RandomSetter.h>

Classes

struct  ScalarWrapper
 

Public Member Functions

Index nonZeros () const
 
Scalaroperator() (Index row, Index col)
 
 RandomSetter (SparseMatrixType &target)
 
 ~RandomSetter ()
 

Protected Attributes

HashMapTypem_hashmaps
 
unsigned char m_keyBitsOffset
 
Index m_outerPackets
 
SparseMatrixType * mp_target
 

Private Types

enum  { SwapStorage = 1 - MapTraits<ScalarWrapper>::IsSorted, TargetRowMajor = (SparseMatrixType::Flags & RowMajorBit) ? 1 : 0, SetterRowMajor = SwapStorage ? 1-TargetRowMajor : TargetRowMajor }
 
typedef MapTraits< ScalarWrapper >::Type HashMapType
 
typedef MapTraits< ScalarWrapper >::KeyType KeyType
 
typedef SparseMatrixType::Scalar Scalar
 
typedef SparseMatrixType::StorageIndex StorageIndex
 

Static Private Attributes

static const int OuterPacketMask = (1 << OuterPacketBits) - 1
 

Detailed Description

template<typename SparseMatrixType, template< typename T > class MapTraits = StdMapTraits, 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
SparseMatrixTypethe type of the sparse matrix we are updating
MapTraitsa traits class representing the map implementation used for the temporary sparse storage. Its default value depends on the system.
OuterPacketBitsdefines 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:

SparseMatrix<double> m(rows,cols);
{
RandomSetter<SparseMatrix<double> > w(m);
// don't use m but w instead with read/write random access to the coefficients:
for(;;)
w(rand(),rand()) = rand;
}
// when w is deleted, the data are copied back to m
// and m is ready to use.

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:

The default map implementation depends on the availability, and the preferred order is: GoogleSparseHashMapTraits, GnuHashMapTraits, 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 176 of file RandomSetter.h.

Member Typedef Documentation

◆ HashMapType

template<typename SparseMatrixType, template< typename T > class MapTraits = StdMapTraits, int OuterPacketBits = 6>
typedef MapTraits<ScalarWrapper>::Type Eigen::RandomSetter< SparseMatrixType, MapTraits, OuterPacketBits >::HashMapType
private

Definition at line 187 of file RandomSetter.h.

◆ KeyType

template<typename SparseMatrixType, template< typename T > class MapTraits = StdMapTraits, int OuterPacketBits = 6>
typedef MapTraits<ScalarWrapper>::KeyType Eigen::RandomSetter< SparseMatrixType, MapTraits, OuterPacketBits >::KeyType
private

Definition at line 186 of file RandomSetter.h.

◆ Scalar

template<typename SparseMatrixType, template< typename T > class MapTraits = StdMapTraits, int OuterPacketBits = 6>
typedef SparseMatrixType::Scalar Eigen::RandomSetter< SparseMatrixType, MapTraits, OuterPacketBits >::Scalar
private

Definition at line 178 of file RandomSetter.h.

◆ StorageIndex

template<typename SparseMatrixType, template< typename T > class MapTraits = StdMapTraits, int OuterPacketBits = 6>
typedef SparseMatrixType::StorageIndex Eigen::RandomSetter< SparseMatrixType, MapTraits, OuterPacketBits >::StorageIndex
private

Definition at line 179 of file RandomSetter.h.

Member Enumeration Documentation

◆ anonymous enum

template<typename SparseMatrixType, template< typename T > class MapTraits = StdMapTraits, int OuterPacketBits = 6>
anonymous enum
private
Enumerator
SwapStorage 
TargetRowMajor 
SetterRowMajor 

Definition at line 189 of file RandomSetter.h.

Constructor & Destructor Documentation

◆ RandomSetter()

template<typename SparseMatrixType, template< typename T > class MapTraits = StdMapTraits, int OuterPacketBits = 6>
Eigen::RandomSetter< SparseMatrixType, MapTraits, OuterPacketBits >::RandomSetter ( SparseMatrixType &  target)
inline

Constructs a random setter object from the sparse matrix target

Note that the initial value of target are imported. If you want to re-set a sparse matrix from scratch, then you must set it to zero first using the setZero() function.

Definition at line 203 of file RandomSetter.h.

◆ ~RandomSetter()

template<typename SparseMatrixType, template< typename T > class MapTraits = StdMapTraits, int OuterPacketBits = 6>
Eigen::RandomSetter< SparseMatrixType, MapTraits, OuterPacketBits >::~RandomSetter ( )
inline

Destructor updating back the sparse matrix target

Definition at line 231 of file RandomSetter.h.

Member Function Documentation

◆ nonZeros()

template<typename SparseMatrixType, template< typename T > class MapTraits = StdMapTraits, int OuterPacketBits = 6>
Index Eigen::RandomSetter< SparseMatrixType, MapTraits, OuterPacketBits >::nonZeros ( ) const
inline
Returns
the number of non zero coefficients
Note
According to the underlying map/hash_map implementation, this function might be quite expensive.

Definition at line 330 of file RandomSetter.h.

◆ operator()()

template<typename SparseMatrixType, template< typename T > class MapTraits = StdMapTraits, int OuterPacketBits = 6>
Scalar& Eigen::RandomSetter< SparseMatrixType, MapTraits, OuterPacketBits >::operator() ( Index  row,
Index  col 
)
inline
Returns
a reference to the coefficient at given coordinates row, col

Definition at line 315 of file RandomSetter.h.

Member Data Documentation

◆ m_hashmaps

template<typename SparseMatrixType, template< typename T > class MapTraits = StdMapTraits, int OuterPacketBits = 6>
HashMapType* Eigen::RandomSetter< SparseMatrixType, MapTraits, OuterPacketBits >::m_hashmaps
protected

Definition at line 341 of file RandomSetter.h.

◆ m_keyBitsOffset

template<typename SparseMatrixType, template< typename T > class MapTraits = StdMapTraits, int OuterPacketBits = 6>
unsigned char Eigen::RandomSetter< SparseMatrixType, MapTraits, OuterPacketBits >::m_keyBitsOffset
protected

Definition at line 344 of file RandomSetter.h.

◆ m_outerPackets

template<typename SparseMatrixType, template< typename T > class MapTraits = StdMapTraits, int OuterPacketBits = 6>
Index Eigen::RandomSetter< SparseMatrixType, MapTraits, OuterPacketBits >::m_outerPackets
protected

Definition at line 343 of file RandomSetter.h.

◆ mp_target

template<typename SparseMatrixType, template< typename T > class MapTraits = StdMapTraits, int OuterPacketBits = 6>
SparseMatrixType* Eigen::RandomSetter< SparseMatrixType, MapTraits, OuterPacketBits >::mp_target
protected

Definition at line 342 of file RandomSetter.h.

◆ OuterPacketMask

template<typename SparseMatrixType, template< typename T > class MapTraits = StdMapTraits, int OuterPacketBits = 6>
const int Eigen::RandomSetter< SparseMatrixType, MapTraits, OuterPacketBits >::OuterPacketMask = (1 << OuterPacketBits) - 1
staticprivate

Definition at line 188 of file RandomSetter.h.


The documentation for this class was generated from the following file:


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:43:03