Public Member Functions | |
int | nonZeros () const |
Scalar & | operator() (int row, int col) |
RandomSetter (SparseMatrixType &target) | |
~RandomSetter () | |
Protected Attributes | |
HashMapType * | m_hashmaps |
unsigned char | m_keyBitsOffset |
int | m_outerPackets |
SparseMatrixType * | mp_target |
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. |
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:
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.
~RandomSetter | ( | ) | [inline] |
Destructor updating back the sparse matrix target
int nonZeros | ( | ) | const [inline] |
Scalar& operator() | ( | int | row, | |
int | col | |||
) | [inline] |