New user self-registration is currently disabled. Please email eigen-core-team @ if you need an account.
Bug 1105 - SparseMatrix::coeffRef() throws std::bad_alloc
SparseMatrix::coeffRef() throws std::bad_alloc
Product: Eigen
Classification: Unclassified
Component: Sparse
3.3 (current stable)
x86 - 64-bit Windows
: Normal Crash
Assigned To: Nobody
Depends on:
  Show dependency treegraph
Reported: 2015-11-06 12:31 UTC by Herr Bert
Modified: 2015-11-06 14:07 UTC (History)
2 users (show)


Description Herr Bert 2015-11-06 12:31:49 UTC
#include <Eigen/Sparse>
#include <complex>

int main()
	Eigen::SparseMatrix<std::complex<double>> mat(177858, 177858);
	std::complex<double> val;

	mat.coeffRef(0, 0) = val;
	mat.coeffRef(1, 1) = val;
	mat.coeffRef(2, 2) = val;
	mat.coeffRef(3, 0) = val; // bad_alloc!

Above code throws std::bad_alloc in Memory.h:666.
Culprit seems to be SparseMatrix.h:1183:

this->reserveInnerVectors(Array<StorageIndex,Dynamic,1>::Constant(2*m_outerSize, convert_index(m_outerSize)));

This leads to a count(SparseMatrix.h:340) of 1568874950 and finaly to a

new T[1568874950] // T being std::complex<double>?

in Memory.h.

Changing SparseMatrix.h:1183: to

this->reserveInnerVectors(Array<StorageIndex,Dynamic,1>::Constant(2*m_outerSize, 2));

seemingly solved my Problem.

eigen 3.3-alpha1 (eigen-09a8e2186610)
Comment 1 Gael Guennebaud 2015-11-06 14:07:17 UTC
ooch, that line was twice wrong! (2*m_outerSize instead of 2, and wrong parameter order)
Summary:     Bug 1105: fix default preallocation when moving from compressed to uncompressed mode

Note You need to log in before you can comment on or make changes to this bug.