This bugzilla service is closed. All entries have been migrated to https://gitlab.com/libeigen/eigen

Bug 1754

Summary: sparseView returns invalid sparse matrix
Product: Eigen Reporter: Xinya Zhang <xinyazhang>
Component: SparseAssignee: Nobody <eigen.nobody>
Status: NEW ---    
Severity: Wrong Result CC: chtz, gael.guennebaud
Priority: Normal    
Version: 3.3 (current stable)   
Hardware: x86 - general   
OS: Windows   
Whiteboard:
Attachments:
Description Flags
Package of code, build script (under Visual Studio Developer Command Prompt), and built x64 binaries none

Description Xinya Zhang 2019-10-09 04:01:00 UTC
Created attachment 955 [details]
Package of code, build script (under Visual Studio Developer Command Prompt), and built x64 binaries

The following code fails on VS 2017/2019, Eigen 3.3.7/TIP (323c052e1731/70e55a287bfe), x86/x64
Expected behavior: exit without showing anything.
Actual behavior: Assertion failed: it.row() < xm, file test_case.cc, line 17
Note: cannot reproduce on Linux. GCC works fine.

#include "assert.h"
#include <vector>

#include <Eigen/Core>
#include <Eigen/SparseCore>

constexpr int K = 4;
typedef Eigen::Triplet<double> Tri;

void iter(const Eigen::SparseMatrix<double>& X)
{
	int xm = X.rows();
	int xn = X.cols();
	for (int k = 0; k < X.outerSize(); ++k) {
		for (typename Eigen::SparseMatrix<double>::InnerIterator it(X, k); it; ++it) {
			assert(it.row() >= 0);
			assert(it.row() < xm);
			assert(it.col() >= 0);
			assert(it.col() < xn);
		}
	}
}

int main()
{
	Eigen::SparseMatrix<double> M(K, K);
	std::vector<Tri> tris;
	tris.reserve(K);
	for (int i = 0; i < K; i++)
		tris.emplace_back(i, i, 1.0);
	M.setFromTriplets(tris.begin(), tris.end());
	const Eigen::SparseMatrix<double> Aeq = M.diagonal().transpose().sparseView();
	iter(Aeq);

	return 0;
}
Comment 1 Nobody 2019-12-04 18:49:15 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to gitlab.com'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: https://gitlab.com/libeigen/eigen/issues/1754.