10 #ifndef EIGEN_RANDOMSETTER_H
11 #define EIGEN_RANDOMSETTER_H
13 #if defined(EIGEN_GOOGLEHASH_SUPPORT)
30 typedef std::map<KeyType,Scalar>
Type;
45 typedef std::unordered_map<KeyType,Scalar>
Type;
53 #if defined(EIGEN_GOOGLEHASH_SUPPORT)
59 using namespace ::google;
61 template<
typename KeyType,
typename Scalar>
63 typedef dense_hash_map<KeyType, Scalar> type;
66 template<
typename KeyType,
typename Scalar>
67 struct SparseHashMap {
68 typedef sparse_hash_map<KeyType, Scalar> type;
77 template<
typename Scalar>
struct GoogleDenseHashMapTraits
80 typedef typename google::DenseHashMap<KeyType,Scalar>::type
Type;
85 static void setInvalidKey(
Type& map,
const KeyType& k)
86 { map.set_empty_key(k); }
93 template<
typename Scalar>
struct GoogleSparseHashMapTraits
96 typedef typename google::SparseHashMap<KeyType,Scalar>::type
Type;
101 static void setInvalidKey(
Type&,
const KeyType&) {}
154 template<
typename SparseMatrixType,
155 template <
typename T>
class MapTraits =
156 #if defined(EIGEN_GOOGLEHASH_SUPPORT)
157 GoogleDenseHashMapTraits
159 StdUnorderedMapTraits
161 ,
int OuterPacketBits = 6>
164 typedef typename SparseMatrixType::Scalar
Scalar;
172 typedef typename MapTraits<ScalarWrapper>::KeyType
KeyType;
192 const Index outerSize =
SwapStorage ? target.innerSize() : target.outerSize();
193 const Index innerSize =
SwapStorage ? target.outerSize() : target.innerSize();
199 Index aux = innerSize - 1;
208 MapTraits<ScalarWrapper>::setInvalidKey(
m_hashmaps[k],ik);
212 for (
typename SparseMatrixType::InnerIterator it(*
mp_target,
j); it; ++it)
225 Index prevOuter = -1;
228 const Index outerOffset = (1<<OuterPacketBits) * k;
230 for (
typename HashMapType::iterator it =
m_hashmaps[k].begin(); it!=
end; ++it)
233 const Index inner = it->first & keyBitsMask;
234 if (prevOuter!=outer)
236 for (
Index j=prevOuter+1;
j<=outer;++
j)
240 mp_target->insertBackByOuterInner(outer, inner) = it->second.value;
253 for (
typename HashMapType::iterator it =
m_hashmaps[k].begin(); it!=
end; ++it)
255 const Index outer = it->first & keyBitsMask;
265 positions[
j] = count;
274 const Index outerOffset = (1<<OuterPacketBits) * k;
276 for (
typename HashMapType::iterator it =
m_hashmaps[k].begin(); it!=
end; ++it)
279 const Index outer = it->first & keyBitsMask;
285 Index i = (positions[outer]++) - 1;
286 while ( (
i >= posStart) && (
mp_target->innerIndexPtr()[
i] > inner) )
292 mp_target->innerIndexPtr()[
i+1] = internal::convert_index<StorageIndex>(inner);
293 mp_target->valuePtr()[
i+1] = it->second.value;
305 const Index outerMajor = outer >> OuterPacketBits;
RowXpr row(Index i) const
ColXpr col(Index i) const
Matrix< Scalar_, Rows_, Cols_, Options_, MaxRows_, MaxCols_ > & setZero(Index rows, Index cols)
The RandomSetter is a wrapper object allowing to set/update a sparse matrix with random access.
MapTraits< ScalarWrapper >::KeyType KeyType
RandomSetter(SparseMatrixType &target)
Scalar & operator()(Index row, Index col)
unsigned char m_keyBitsOffset
MapTraits< ScalarWrapper >::Type HashMapType
SparseMatrixType::StorageIndex StorageIndex
SparseMatrixType::Scalar Scalar
static constexpr int OuterPacketMask
SparseMatrixType * mp_target
static const lastp1_t end
const unsigned int RowMajorBit
: TensorContractionSycl.h, provides various tensor contraction kernel for SYCL backend
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
std::map< KeyType, Scalar > Type
static void setInvalidKey(Type &, const KeyType &)
static void setInvalidKey(Type &, const KeyType &)
std::unordered_map< KeyType, Scalar > Type