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
-
| 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:
{
for(;;)
w(rand(),rand()) = rand;
}
The RandomSetter is a wrapper object allowing to set/update a sparse matrix with random access.
Definition RandomSetter.h:155
A versatible sparse matrix representation.
Definition SparseMatrix.h:98
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)
- GnuHashMapTraits: corresponds to __gnu_cxx::hash_map (available only with GCC)
- 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, 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:
- #include <google/dense_hash_map> yourself before Eigen/Sparse header
- define EIGEN_GOOGLEHASH_SUPPORT In the later case the inclusion of <google/dense_hash_map> is made for you.
- See also
- http://code.google.com/p/google-sparsehash/
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.
183 {
184 const Index outerSize =
SwapStorage ? target.innerSize() : target.outerSize();
185 const Index innerSize =
SwapStorage ? target.outerSize() : target.innerSize();
190
191 Index aux = innerSize - 1;
193 while (aux)
194 {
196 aux = aux >> 1;
197 }
200 MapTraits<ScalarWrapper>::setInvalidKey(
m_hashmaps[k],ik);
201
202
204 for (
typename SparseMatrixType::InnerIterator it(*
mp_target,j); it; ++it)
206 }
Index m_outerPackets
Definition RandomSetter.h:321
MapTraits< ScalarWrapper >::KeyType KeyType
Definition RandomSetter.h:164
static const int OuterPacketMask
Definition RandomSetter.h:166
unsigned char m_keyBitsOffset
Definition RandomSetter.h:322
MapTraits< ScalarWrapper >::Type HashMapType
Definition RandomSetter.h:165
HashMapType * m_hashmaps
Definition RandomSetter.h:319
SparseMatrixType * mp_target
Definition RandomSetter.h:320
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:33
References Eigen::RandomSetter< SparseMatrixType, MapTraits, OuterPacketBits >::m_hashmaps, Eigen::RandomSetter< SparseMatrixType, MapTraits, OuterPacketBits >::m_keyBitsOffset, Eigen::RandomSetter< SparseMatrixType, MapTraits, OuterPacketBits >::m_outerPackets, Eigen::RandomSetter< SparseMatrixType, MapTraits, OuterPacketBits >::mp_target, Eigen::RandomSetter< SparseMatrixType, MapTraits, OuterPacketBits >::OuterPacketMask, Eigen::RandomSetter< SparseMatrixType, MapTraits, OuterPacketBits >::SwapStorage, and Eigen::RandomSetter< SparseMatrixType, MapTraits, OuterPacketBits >::TargetRowMajor.
template<typename SparseMatrixType , template< typename T > class MapTraits = StdMapTraits, int OuterPacketBits = 6>
Destructor updating back the sparse matrix target
210 {
213 {
217 Index prevOuter = -1;
219 {
220 const Index outerOffset = (1<<OuterPacketBits) * k;
223 {
225 const Index inner = it->first & keyBitsMask;
226 if (prevOuter!=outer)
227 {
228 for (
Index j=prevOuter+1;j<=outer;++j)
230 prevOuter = outer;
231 }
232 mp_target->insertBackByOuterInner(outer, inner) = it->second.value;
233 }
234 }
236 }
237 else
238 {
239 VectorXi positions(
mp_target->outerSize());
240 positions.setZero();
241
243 {
246 {
247 const Index outer = it->first & keyBitsMask;
248 ++positions[outer];
249 }
250 }
251
254 {
255 Index tmp = positions[j];
257 positions[j] =
count;
259 }
263
265 {
266 const Index outerOffset = (1<<OuterPacketBits) * k;
269 {
271 const Index outer = it->first & keyBitsMask;
272
273
274
275
277 Index i = (positions[outer]++) - 1;
278 while ( (i >= posStart) && (
mp_target->innerIndexPtr()[i] > inner) )
279 {
282 --i;
283 }
285 mp_target->valuePtr()[i+1] = it->second.value;
286 }
287 }
288 }
290 }
Index nonZeros() const
Definition RandomSetter.h:308
T * begin(Slic3r::Mat< N, M, T > &mat)
Definition Point.hpp:605
T * end(Slic3r::Mat< N, M, T > &mat)
Definition Point.hpp:608
IGL_INLINE void count(const Eigen::SparseMatrix< XType > &X, const int dim, Eigen::SparseVector< SType > &S)
Definition count.cpp:12
References Eigen::begin(), Eigen::end(), Eigen::RandomSetter< SparseMatrixType, MapTraits, OuterPacketBits >::m_hashmaps, Eigen::RandomSetter< SparseMatrixType, MapTraits, OuterPacketBits >::m_keyBitsOffset, Eigen::RandomSetter< SparseMatrixType, MapTraits, OuterPacketBits >::m_outerPackets, Eigen::RandomSetter< SparseMatrixType, MapTraits, OuterPacketBits >::mp_target, Eigen::RandomSetter< SparseMatrixType, MapTraits, OuterPacketBits >::nonZeros(), and Eigen::RandomSetter< SparseMatrixType, MapTraits, OuterPacketBits >::SwapStorage.