| 295 | protected: |
| 296 | template<class SizesType> |
| 297 | inline void reserveInnerVectors(const SizesType& reserveSizes) |
| 298 | { |
| 299 | if(isCompressed()) |
| 300 | { |
| 301 | Index totalReserveSize = 0; |
| 302 | // turn the matrix into non-compressed mode |
| 303 | m_innerNonZeros = static_cast<StorageIndex*>(std::malloc(m_outerSize * sizeof(StorageIndex))); |
| 304 | if (!m_innerNonZeros) internal::throw_std_bad_alloc(); |
| 305 | |
| 306 | // temporarily use m_innerSizes to hold the new starting points. |
| 307 | StorageIndex* newOuterIndex = m_innerNonZeros; |
| 308 | |
| 309 | StorageIndex count = 0; |
| 310 | for(Index j=0; j<m_outerSize; ++j) |
| 311 | { |
| 312 | newOuterIndex[j] = count; |
| 313 | count += reserveSizes[j] + (m_outerIndex[j+1]-m_outerIndex[j]); |
| 314 | totalReserveSize += reserveSizes[j]; |
| 315 | } |
| 316 | m_data.reserve(totalReserveSize); |
| 317 | StorageIndex previousOuterIndex = m_outerIndex[m_outerSize]; |
| 318 | for(Index j=m_outerSize-1; j>=0; --j) |
| 319 | { |
| 320 | StorageIndex innerNNZ = previousOuterIndex - m_outerIndex[j]; |
| 321 | for(Index i=innerNNZ-1; i>=0; --i) |
| 322 | { |
| 323 | m_data.index(newOuterIndex[j]+i) = m_data.index(m_outerIndex[j]+i); |
| 324 | m_data.value(newOuterIndex[j]+i) = m_data.value(m_outerIndex[j]+i); |
| 325 | } |
| 326 | previousOuterIndex = m_outerIndex[j]; |
| 327 | m_outerIndex[j] = newOuterIndex[j]; |
| 328 | m_innerNonZeros[j] = innerNNZ; |
| 329 | } |
| 330 | m_outerIndex[m_outerSize] = m_outerIndex[m_outerSize-1] + m_innerNonZeros[m_outerSize-1] + reserveSizes[m_outerSize-1]; |
| 331 | |
| 332 | m_data.resize(m_outerIndex[m_outerSize]); |
| 333 | } |
| 334 | else |
| 335 | { |
| 336 | StorageIndex* newOuterIndex = static_cast<StorageIndex*>(std::malloc((m_outerSize+1)*sizeof(StorageIndex))); |
| 337 | if (!newOuterIndex) internal::throw_std_bad_alloc(); |
| 338 | |
| 339 | StorageIndex count = 0; |
| 340 | for(Index j=0; j<m_outerSize; ++j) |
| 341 | { |
| 342 | newOuterIndex[j] = count; |
| 343 | StorageIndex alreadyReserved = (m_outerIndex[j+1]-m_outerIndex[j]) - m_innerNonZeros[j]; |
| 344 | StorageIndex toReserve = std::max<StorageIndex>(reserveSizes[j], alreadyReserved); |
| 345 | count += toReserve + m_innerNonZeros[j]; |
| 346 | } |
| 347 | newOuterIndex[m_outerSize] = count; |
| 348 | |
| 349 | m_data.resize(count); |
| 350 | for(Index j=m_outerSize-1; j>=0; --j) |
| 351 | { |
| 352 | Index offset = newOuterIndex[j] - m_outerIndex[j]; |
| 353 | if(offset>0) |
| 354 | { |
no test coverage detected