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 < m_target->outerSize(); ++j)
198 for (
typename SparseMatrixType::InnerIterator it(*m_target, j); it; ++it)
199 (*this)(TargetRowMajor ? j : it.index(), TargetRowMajor ? it.index() : j) = it.value();
204 KeyType keyBitsMask = (1 << m_keyBitsOffset) - 1;
208 m_target->makeCompressed();
212 Index prevOuter = -1;
213 for (Index k = 0; k < m_outerPackets; ++k) {
214 const Index outerOffset = (1 << OuterPacketBits) * k;
215 typename HashMapType::iterator end = m_hashmaps[k].end();
216 for (
typename HashMapType::iterator it = m_hashmaps[k].begin(); it != end; ++it) {
217 const Index outer = (it->first >> m_keyBitsOffset) + outerOffset;
218 const Index inner = it->first & keyBitsMask;
219 if (prevOuter != outer) {
220 for (Index j = prevOuter + 1; j <= outer; ++j) m_target->startVec(j);
223 m_target->insertBackByOuterInner(outer, inner) = it->second.value;
226 m_target->finalize();
228 VectorXi positions(m_target->outerSize());
231 for (Index k = 0; k < m_outerPackets; ++k) {
232 typename HashMapType::iterator end = m_hashmaps[k].end();
233 for (
typename HashMapType::iterator it = m_hashmaps[k].begin(); it != end; ++it) {
234 const Index outer = it->first & keyBitsMask;
239 StorageIndex count = 0;
240 for (Index j = 0; j < m_target->outerSize(); ++j) {
241 StorageIndex tmp = positions[j];
242 m_target->outerIndexPtr()[j] = count;
243 positions[j] = count;
246 m_target->outerIndexPtr()[m_target->outerSize()] = count;
247 m_target->resizeNonZeros(count);
249 for (Index k = 0; k < m_outerPackets; ++k) {
250 const Index outerOffset = (1 << OuterPacketBits) * k;
251 typename HashMapType::iterator end = m_hashmaps[k].end();
252 for (
typename HashMapType::iterator it = m_hashmaps[k].begin(); it != end; ++it) {
253 const Index inner = (it->first >> m_keyBitsOffset) + outerOffset;
254 const Index outer = it->first & keyBitsMask;
259 Index posStart = m_target->outerIndexPtr()[outer];
260 Index i = (positions[outer]++) - 1;
261 while ((i >= posStart) && (m_target->innerIndexPtr()[i] > inner)) {
262 m_target->valuePtr()[i + 1] = m_target->valuePtr()[i];
263 m_target->innerIndexPtr()[i + 1] = m_target->innerIndexPtr()[i];
266 m_target->innerIndexPtr()[i + 1] = internal::convert_index<StorageIndex>(inner);
267 m_target->valuePtr()[i + 1] = it->second.value;
276 const Index outer = SetterRowMajor ? row : col;
277 const Index inner = SetterRowMajor ? col : row;
278 const Index outerMajor = outer >> OuterPacketBits;
279 const Index outerMinor = outer & OuterPacketMask;
280 const KeyType key = internal::convert_index<KeyType>((outerMinor << m_keyBitsOffset) | inner);
281 return m_hashmaps[outerMajor][key].value;