181 const Index outerSize = SwapStorage ? target.innerSize() : target.outerSize();
182 const Index innerSize = SwapStorage ? target.outerSize() : target.innerSize();
183 m_outerPackets = outerSize >> OuterPacketBits;
184 if (outerSize & OuterPacketMask) m_outerPackets += 1;
185 m_hashmaps =
new HashMapType[m_outerPackets];
187 Index aux = innerSize - 1;
193 KeyType ik = (1 << (OuterPacketBits + m_keyBitsOffset));
194 for (
Index k = 0; k < m_outerPackets; ++k) MapTraits<ScalarWrapper>::setInvalidKey(m_hashmaps[k], ik);
197 for (
Index j = 0; j < mp_target->outerSize(); ++j)
198 for (
typename SparseMatrixType::InnerIterator it(*mp_target, j); it; ++it)
199 (*this)(TargetRowMajor ? j : it.index(), TargetRowMajor ? it.index() : j) = it.value();
204 KeyType keyBitsMask = (1 << m_keyBitsOffset) - 1;
207 mp_target->setZero();
208 mp_target->makeCompressed();
210 Index prevOuter = -1;
211 for (
Index k = 0; k < m_outerPackets; ++k) {
212 const Index outerOffset = (1 << OuterPacketBits) * k;
213 typename HashMapType::iterator end = m_hashmaps[k].end();
214 for (
typename HashMapType::iterator it = m_hashmaps[k].begin(); it != end; ++it) {
215 const Index outer = (it->first >> m_keyBitsOffset) + outerOffset;
216 const Index inner = it->first & keyBitsMask;
217 if (prevOuter != outer) {
218 for (
Index j = prevOuter + 1; j <= outer; ++j) mp_target->startVec(j);
221 mp_target->insertBackByOuterInner(outer, inner) = it->second.value;
224 mp_target->finalize();
226 VectorXi positions(mp_target->outerSize());
229 for (
Index k = 0; k < m_outerPackets; ++k) {
230 typename HashMapType::iterator end = m_hashmaps[k].end();
231 for (
typename HashMapType::iterator it = m_hashmaps[k].begin(); it != end; ++it) {
232 const Index outer = it->first & keyBitsMask;
237 StorageIndex count = 0;
238 for (
Index j = 0; j < mp_target->outerSize(); ++j) {
239 StorageIndex tmp = positions[j];
240 mp_target->outerIndexPtr()[j] = count;
241 positions[j] = count;
244 mp_target->makeCompressed();
245 mp_target->outerIndexPtr()[mp_target->outerSize()] = count;
246 mp_target->resizeNonZeros(count);
248 for (
Index k = 0; k < m_outerPackets; ++k) {
249 const Index outerOffset = (1 << OuterPacketBits) * k;
250 typename HashMapType::iterator end = m_hashmaps[k].end();
251 for (
typename HashMapType::iterator it = m_hashmaps[k].begin(); it != end; ++it) {
252 const Index inner = (it->first >> m_keyBitsOffset) + outerOffset;
253 const Index outer = it->first & keyBitsMask;
258 Index posStart = mp_target->outerIndexPtr()[outer];
259 Index i = (positions[outer]++) - 1;
260 while ((i >= posStart) && (mp_target->innerIndexPtr()[i] > inner)) {
261 mp_target->valuePtr()[i + 1] = mp_target->valuePtr()[i];
262 mp_target->innerIndexPtr()[i + 1] = mp_target->innerIndexPtr()[i];
265 mp_target->innerIndexPtr()[i + 1] = internal::convert_index<StorageIndex>(inner);
266 mp_target->valuePtr()[i + 1] = it->second.value;
275 const Index outer = SetterRowMajor ? row : col;
276 const Index inner = SetterRowMajor ? col : row;
277 const Index outerMajor = outer >> OuterPacketBits;
278 const Index outerMinor = outer & OuterPacketMask;
279 const KeyType key = internal::convert_index<KeyType>((outerMinor << m_keyBitsOffset) | inner);
280 return m_hashmaps[outerMajor][key].value;