This bugzilla service is closed. All entries have been migrated to
Bug 1105 - SparseMatrix::coeffRef() throws std::bad_alloc
Summary: SparseMatrix::coeffRef() throws std::bad_alloc
Alias: None
Product: Eigen
Classification: Unclassified
Component: Sparse (show other bugs)
Version: 3.3 (current stable)
Hardware: x86 - 64-bit Windows
: Normal Crash
Assignee: Nobody
Depends on:
Reported: 2015-11-06 12:31 UTC by Herr Bert
Modified: 2019-12-04 15:08 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
Comment 2 Nobody 2019-12-04 15:08:28 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance:

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