Crash in ConjugateGradient::solve() when expression is given.
Submitted by Vladimir
Assigned to Nobody
Link to original bugzilla bug (#527)
Version: 3.1
Operating system: Windows
Description
Created attachment 304
callstack1
Here is the code snippet (part of the function body):
void solve(const VectorXd& initial_alpha) {
typedef Eigen::SparseMatrix<double, Eigen::RowMajor> SparseMatrixType;
typedef Eigen::Triplet<double> DoubleTriplet;
SparseMatrixType laplacian;
fill_laplacian(laplacian);
/* laplacian's size is 2450x2450, it is symmetric, positive definite */
SparseMatrixType D(laplacian.rows(), laplacian.cols());
vector<DoubleTriplet> D_triplets;
const double lambda = 0.1;
for(int i = 0; i < laplacian.rows(); ++i) {
double value = /* calculated value */;
D_triplets.push_back(DoubleTriplet(i, i, value));
}
D.setFromTriplets(D_triplets.begin(), D_triplets.end());
VectorXd b = ;
ConjugateGradient<SparseMatrixType, Upper> cg;
cg.setTolerance(1e-15);
cg.setMaxIterations(500);
cg.compute(laplacian + lambda * D);
VectorXd alpha = cg.solve(lambda * D * initial_alpha); // <- crash
}
I've observed 2 types of crashes.
- When both cg.compute() and cg.solve() are called with expressions, visual studio gives Access violation reading location <some address>.
Crash is in the file Eigen/src/SparseCore/SparseMatrix.h, line 950, method
SparseMatrix<Scalar,_Options,_Index>::InnerIterator::index()
m_id = -544149818
Call stack is in the attached file callstack1.txt
-
If I replace an argument of solve() with pre-calculated variable:
VectorXd b = lambda * D * initial_alpha;
cg.compute(laplacian + lambda * D);
VectorXd alpha = cg.solve(lambda * D * initial_alpha); // <- crash
then I've got failed Eigen assertion:
Assertion failed:
(i>=0) &&
(
((BlockRows==1) && (BlockCols==XprType::ColsAtCompileTime) && i<xpr.rows()) ||
((BlockRows==XprType::RowsAtCompileTime) && (BlockCols==1) && i<xpr.cols())
), file c:\eigen\eigen\src/Core/Block.h, line 280
here i = 1007402692;
xpr.rows() return 2450, xpr.cols() returns 1.
Call stack is in the attached file callstack2.txt
- If I replace an argument of cg.compute() with precalculated variable, everything works fine:
SparseMatrixType A = laplacian + lambda * D;
cg.compute(A);
alpha = cg.solve(lambda * D * initial_alpha);
I can attach text files with concrete matrices, if needed.
Attachment 304, "callstack1":
callstack1.txt