The RandomSetter is a wrapper object allowing to set/update a sparse matrix with random access.
| 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:
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 the Google's hash_map implementation. To enable the support for them, you have two options:
Definition at line 168 of file SparseExtra.
Classes | |
| struct | ScalarWrapper |
Public Member Functions | |
| RandomSetter (SparseMatrixType &target) | |
| Constructs a random setter object from the sparse matrix target. | |
| ~RandomSetter () | |
| Destructor updating back the sparse matrix target. | |
| Scalar & | operator() (Index row, Index col) |
| Index | nonZeros () const |
Protected Attributes | |
| HashMapType * | m_hashmaps |
| SparseMatrixType * | mp_target |
| Index | m_outerPackets |
| unsigned char | m_keyBitsOffset |
Private Types | |
| enum | { SwapStorage = 1 - MapTraits<ScalarWrapper>::IsSorted, TargetRowMajor = (SparseMatrixType::Flags & RowMajorBit) ? 1 : 0, SetterRowMajor = SwapStorage ? 1-TargetRowMajor : TargetRowMajor, IsUpper = SparseMatrixType::Flags & Upper, IsLower = SparseMatrixType::Flags & Lower } |
| typedef SparseMatrixType::Scalar | Scalar |
| typedef SparseMatrixType::Index | Index |
| typedef MapTraits < ScalarWrapper >::KeyType | KeyType |
| typedef MapTraits < ScalarWrapper >::Type | HashMapType |
Static Private Attributes | |
| static const int | OuterPacketMask = (1 << OuterPacketBits) - 1 |
typedef MapTraits<ScalarWrapper>::Type Eigen::RandomSetter< SparseMatrixType, MapTraits, OuterPacketBits >::HashMapType [private] |
Definition at line 179 of file SparseExtra.
typedef SparseMatrixType::Index Eigen::RandomSetter< SparseMatrixType, MapTraits, OuterPacketBits >::Index [private] |
Definition at line 171 of file SparseExtra.
typedef MapTraits<ScalarWrapper>::KeyType Eigen::RandomSetter< SparseMatrixType, MapTraits, OuterPacketBits >::KeyType [private] |
Definition at line 178 of file SparseExtra.
typedef SparseMatrixType::Scalar Eigen::RandomSetter< SparseMatrixType, MapTraits, OuterPacketBits >::Scalar [private] |
Definition at line 170 of file SparseExtra.
anonymous enum [private] |
Definition at line 181 of file SparseExtra.
| 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 197 of file SparseExtra.
| Eigen::RandomSetter< SparseMatrixType, MapTraits, OuterPacketBits >::~RandomSetter | ( | ) | [inline] |
Destructor updating back the sparse matrix target.
Definition at line 225 of file SparseExtra.
| Index Eigen::RandomSetter< SparseMatrixType, MapTraits, OuterPacketBits >::nonZeros | ( | ) | const [inline] |
Definition at line 324 of file SparseExtra.
| Scalar& Eigen::RandomSetter< SparseMatrixType, MapTraits, OuterPacketBits >::operator() | ( | Index | row, |
| Index | col | ||
| ) | [inline] |
Definition at line 307 of file SparseExtra.
HashMapType* Eigen::RandomSetter< SparseMatrixType, MapTraits, OuterPacketBits >::m_hashmaps [protected] |
Definition at line 335 of file SparseExtra.
unsigned char Eigen::RandomSetter< SparseMatrixType, MapTraits, OuterPacketBits >::m_keyBitsOffset [protected] |
Definition at line 338 of file SparseExtra.
Index Eigen::RandomSetter< SparseMatrixType, MapTraits, OuterPacketBits >::m_outerPackets [protected] |
Definition at line 337 of file SparseExtra.
SparseMatrixType* Eigen::RandomSetter< SparseMatrixType, MapTraits, OuterPacketBits >::mp_target [protected] |
Definition at line 336 of file SparseExtra.
const int Eigen::RandomSetter< SparseMatrixType, MapTraits, OuterPacketBits >::OuterPacketMask = (1 << OuterPacketBits) - 1 [static, private] |
Definition at line 180 of file SparseExtra.
| Page generated by Doxygen 1.7.4 for MRPT 0.9.5 SVN:2717 at Sun Oct 16 16:08:03 PDT 2011 | Hosted on: |