Logo Search packages:      
Sourcecode: eigen3 version File versions  Download package

Classes | Public Member Functions | Protected Attributes | Private Types | Static Private Attributes

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>

List of all members.

Classes

struct  ScalarWrapper

Public Member Functions

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

Protected Attributes

HashMapType * m_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, IsUpper = SparseMatrixType::Flags & Upper,
  IsLower = SparseMatrixType::Flags & Lower
}
typedef MapTraits
< ScalarWrapper >::Type 
HashMapType
typedef SparseMatrixType::Index Index
typedef MapTraits
< ScalarWrapper >::KeyType 
KeyType
typedef SparseMatrixType::Scalar Scalar

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 RandomSetter< SparseMatrixType, MapTraits, OuterPacketBits >

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

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 the Google's hash_map implementation. To enable the support for them, you have two options:

See also:
http://code.google.com/p/google-sparsehash/

Definition at line 167 of file RandomSetter.h.


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

Generated by  Doxygen 1.6.0   Back to index