10#ifndef EIGEN_RANDOMSETTER_H
11#define EIGEN_RANDOMSETTER_H
13#if defined(EIGEN_GOOGLEHASH_SUPPORT)
28 typedef std::map<KeyType,Scalar>
Type;
36#ifdef EIGEN_UNORDERED_MAP_SUPPORT
53template<
typename Scalar>
struct StdUnorderedMapTraits
56 typedef std::unordered_map<KeyType,Scalar> Type;
61 static void setInvalidKey(Type&,
const KeyType&) {}
65#if defined(EIGEN_GOOGLEHASH_SUPPORT)
71using namespace ::google;
73template<
typename KeyType,
typename Scalar>
75 typedef dense_hash_map<KeyType, Scalar> type;
78template<
typename KeyType,
typename Scalar>
80 typedef sparse_hash_map<KeyType, Scalar> type;
89template<
typename Scalar>
struct GoogleDenseHashMapTraits
92 typedef typename google::DenseHashMap<KeyType,Scalar>::type
Type;
97 static void setInvalidKey(Type& map,
const KeyType& k)
98 { map.set_empty_key(k); }
105template<
typename Scalar>
struct GoogleSparseHashMapTraits
108 typedef typename google::SparseHashMap<KeyType,Scalar>::type
Type;
113 static void setInvalidKey(Type&,
const KeyType&) {}
166template<
typename SparseMatrixType,
167 template <
typename T>
class MapTraits =
168#if defined(EIGEN_GOOGLEHASH_SUPPORT)
169 GoogleDenseHashMapTraits
170#elif defined(_HASH_MAP)
175 ,
int OuterPacketBits = 6>
178 typedef typename SparseMatrixType::Scalar Scalar;
179 typedef typename SparseMatrixType::StorageIndex StorageIndex;
183 ScalarWrapper() : value(0) {}
186 typedef typename MapTraits<ScalarWrapper>::KeyType KeyType;
187 typedef typename MapTraits<ScalarWrapper>::Type HashMapType;
188 static const int OuterPacketMask = (1 << OuterPacketBits) - 1;
190 SwapStorage = 1 - MapTraits<ScalarWrapper>::IsSorted,
191 TargetRowMajor = (SparseMatrixType::Flags &
RowMajorBit) ? 1 : 0,
192 SetterRowMajor = SwapStorage ? 1-TargetRowMajor : TargetRowMajor
206 const Index outerSize = SwapStorage ? target.innerSize() : target.outerSize();
207 const Index innerSize = SwapStorage ? target.outerSize() : target.innerSize();
209 if (outerSize&OuterPacketMask)
213 Index aux = innerSize - 1;
222 MapTraits<ScalarWrapper>::setInvalidKey(
m_hashmaps[k],ik);
226 for (
typename SparseMatrixType::InnerIterator it(*
mp_target,
j); it; ++it)
227 (*
this)(TargetRowMajor?
j:it.index(), TargetRowMajor?it.index():
j) = it.value();
239 Index prevOuter = -1;
242 const Index outerOffset = (1<<OuterPacketBits) * k;
243 typename HashMapType::iterator end =
m_hashmaps[k].end();
244 for (
typename HashMapType::iterator it =
m_hashmaps[k].begin(); it!=end; ++it)
247 const Index inner = it->first & keyBitsMask;
248 if (prevOuter!=outer)
250 for (
Index j=prevOuter+1;
j<=outer;++
j)
254 mp_target->insertBackByOuterInner(outer, inner) = it->second.value;
261 VectorXi positions(
mp_target->outerSize());
266 typename HashMapType::iterator end =
m_hashmaps[k].end();
267 for (
typename HashMapType::iterator it =
m_hashmaps[k].begin(); it!=end; ++it)
269 const Index outer = it->first & keyBitsMask;
274 StorageIndex
count = 0;
277 StorageIndex tmp = positions[
j];
288 const Index outerOffset = (1<<OuterPacketBits) * k;
289 typename HashMapType::iterator end =
m_hashmaps[k].end();
290 for (
typename HashMapType::iterator it =
m_hashmaps[k].begin(); it!=end; ++it)
293 const Index outer = it->first & keyBitsMask;
299 Index i = (positions[outer]++) - 1;
300 while ( (
i >= posStart) && (
mp_target->innerIndexPtr()[
i] > inner) )
307 mp_target->valuePtr()[
i+1] = it->second.value;
319 const Index outerMajor = outer >> OuterPacketBits;
320 const Index outerMinor = outer & OuterPacketMask;
int i
Definition BiCGSTAB_step_by_step.cpp:9
Scalar Scalar int size
Definition benchVecAdd.cpp:17
The RandomSetter is a wrapper object allowing to set/update a sparse matrix with random access.
Definition RandomSetter.h:177
Index m_outerPackets
Definition RandomSetter.h:343
~RandomSetter()
Definition RandomSetter.h:231
RandomSetter(SparseMatrixType &target)
Definition RandomSetter.h:203
Scalar & operator()(Index row, Index col)
Definition RandomSetter.h:315
unsigned char m_keyBitsOffset
Definition RandomSetter.h:344
HashMapType * m_hashmaps
Definition RandomSetter.h:341
Index nonZeros() const
Definition RandomSetter.h:330
SparseMatrixType * mp_target
Definition RandomSetter.h:342
const unsigned int RowMajorBit
Definition Constants.h:66
Type
Definition Constants.h:471
Namespace containing all symbols from the Eigen library.
Definition bench_norm.cpp:85
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:74
uint8_t count
Definition ref_serial.h:256
Definition RandomSetter.h:26
std::map< KeyType, Scalar > Type
Definition RandomSetter.h:28
@ IsSorted
Definition RandomSetter.h:30
int KeyType
Definition RandomSetter.h:27
static void setInvalidKey(Type &, const KeyType &)
Definition RandomSetter.h:33
Definition ForwardDeclarations.h:17
std::ptrdiff_t j
Definition tut_arithmetic_redux_minmax.cpp:2