10 #ifndef EIGEN_RANDOMSETTER_H
11 #define EIGEN_RANDOMSETTER_H
13 #if defined(EIGEN_GOOGLEHASH_SUPPORT)
28 template <
typename Scalar>
31 typedef std::map<KeyType, Scalar>
Type;
40 template <
typename Scalar>
43 typedef std::unordered_map<KeyType, Scalar>
Type;
49 #if defined(EIGEN_GOOGLEHASH_SUPPORT)
55 using namespace ::google;
57 template <
typename KeyType,
typename Scalar>
59 typedef dense_hash_map<KeyType, Scalar>
type;
62 template <
typename KeyType,
typename Scalar>
63 struct SparseHashMap {
64 typedef sparse_hash_map<KeyType, Scalar>
type;
73 template <
typename Scalar>
74 struct GoogleDenseHashMapTraits {
77 enum { IsSorted = 0 };
79 static void setInvalidKey(
Type& map,
const KeyType&
k) { map.set_empty_key(
k); }
86 template <
typename Scalar>
87 struct GoogleSparseHashMapTraits {
90 enum { IsSorted = 0 };
92 static void setInvalidKey(
Type&,
const KeyType&) {}
147 template <
typename SparseMatrixType,
148 template <
typename T>
class MapTraits =
149 #if defined(EIGEN_GOOGLEHASH_SUPPORT)
150 GoogleDenseHashMapTraits
152 StdUnorderedMapTraits
155 int OuterPacketBits = 6>
164 typedef typename MapTraits<ScalarWrapper>::KeyType
KeyType;
181 const Index outerSize =
SwapStorage ? target.innerSize() : target.outerSize();
182 const Index innerSize =
SwapStorage ? target.outerSize() : target.innerSize();
187 Index aux = innerSize - 1;
194 for (
Index k = 0; k < m_outerPackets; ++k) MapTraits<ScalarWrapper>::setInvalidKey(
m_hashmaps[
k], ik);
198 for (
typename SparseMatrixType::InnerIterator it(*
mp_target,
j); it; ++it)
210 Index prevOuter = -1;
212 const Index outerOffset = (1 << OuterPacketBits) *
k;
214 for (
typename HashMapType::iterator it =
m_hashmaps[
k].begin(); it !=
end; ++it) {
216 const Index inner = it->first & keyBitsMask;
217 if (prevOuter != outer) {
221 mp_target->insertBackByOuterInner(outer, inner) = it->second.value;
226 VectorXi positions(
mp_target->outerSize());
231 for (
typename HashMapType::iterator it =
m_hashmaps[
k].begin(); it !=
end; ++it) {
232 const Index outer = it->first & keyBitsMask;
241 positions[
j] = count;
249 const Index outerOffset = (1 << OuterPacketBits) *
k;
251 for (
typename HashMapType::iterator it =
m_hashmaps[
k].begin(); it !=
end; ++it) {
253 const Index outer = it->first & keyBitsMask;
259 Index i = (positions[outer]++) - 1;
260 while ((
i >= posStart) && (
mp_target->innerIndexPtr()[
i] > inner)) {
265 mp_target->innerIndexPtr()[
i + 1] = internal::convert_index<StorageIndex>(inner);
266 mp_target->valuePtr()[
i + 1] = it->second.value;
277 const Index outerMajor = outer >> OuterPacketBits;
int i
Definition: BiCGSTAB_step_by_step.cpp:9
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
SCALAR Scalar
Definition: bench_gemm.cpp:45
The RandomSetter is a wrapper object allowing to set/update a sparse matrix with random access.
Definition: RandomSetter.h:156
Index m_outerPackets
Definition: RandomSetter.h:297
MapTraits< ScalarWrapper >::KeyType KeyType
Definition: RandomSetter.h:164
~RandomSetter()
Definition: RandomSetter.h:203
RandomSetter(SparseMatrixType &target)
Definition: RandomSetter.h:180
Scalar & operator()(Index row, Index col)
Definition: RandomSetter.h:274
@ SwapStorage
Definition: RandomSetter.h:168
@ SetterRowMajor
Definition: RandomSetter.h:170
@ TargetRowMajor
Definition: RandomSetter.h:169
unsigned char m_keyBitsOffset
Definition: RandomSetter.h:298
MapTraits< ScalarWrapper >::Type HashMapType
Definition: RandomSetter.h:165
HashMapType * m_hashmaps
Definition: RandomSetter.h:295
SparseMatrixType::StorageIndex StorageIndex
Definition: RandomSetter.h:158
SparseMatrixType::Scalar Scalar
Definition: RandomSetter.h:157
Index nonZeros() const
Definition: RandomSetter.h:288
static constexpr int OuterPacketMask
Definition: RandomSetter.h:166
SparseMatrixType * mp_target
Definition: RandomSetter.h:296
static constexpr lastp1_t end
Definition: IndexedViewHelper.h:79
const unsigned int RowMajorBit
Definition: Constants.h:70
char char char int int * k
Definition: level2_impl.h:374
Eigen::Matrix< Scalar, Dynamic, Dynamic, ColMajor > tmp
Definition: level3_impl.h:365
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
const unsigned nz
Definition: ConstraintElementsUnitTest.cpp:32
type
Definition: compute_granudrum_aor.py:141
Type
Type of JSON value.
Definition: rapidjson.h:513
Definition: RandomSetter.h:160
Scalar value
Definition: RandomSetter.h:162
ScalarWrapper()
Definition: RandomSetter.h:161
Definition: RandomSetter.h:29
std::map< KeyType, Scalar > Type
Definition: RandomSetter.h:31
int KeyType
Definition: RandomSetter.h:30
@ IsSorted
Definition: RandomSetter.h:32
static void setInvalidKey(Type &, const KeyType &)
Definition: RandomSetter.h:34
Definition: RandomSetter.h:41
static void setInvalidKey(Type &, const KeyType &)
Definition: RandomSetter.h:46
int KeyType
Definition: RandomSetter.h:42
std::unordered_map< KeyType, Scalar > Type
Definition: RandomSetter.h:43
@ IsSorted
Definition: RandomSetter.h:44
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2