This bugzilla service is closed. All entries have been migrated to
Bug 37 - sparse row-major multiplication crashes depending on matrix sizes
Summary: sparse row-major multiplication crashes depending on matrix sizes
Alias: None
Product: Eigen
Classification: Unclassified
Component: Sparse (show other bugs)
Version: 3.0
Hardware: x86 - 64-bit Linux
: --- Unknown
Assignee: Gael Guennebaud
Depends on:
Reported: 2010-10-10 01:00 UTC by Evan Herbst
Modified: 2019-12-04 09:35 UTC (History)
1 user (show)

test driver (751 bytes, text/x-c++src)
2010-10-10 01:00 UTC, Evan Herbst
no flags Details
Test Case (1004 bytes, text/x-c++src)
2011-03-07 21:50 UTC, Oliver Ruepp
no flags Details
Solution hack... (14.13 KB, text/x-chdr)
2011-03-07 21:52 UTC, Oliver Ruepp
no flags Details
Patch for src/Sparse/SparseSparseProduct.h (630 bytes, patch)
2011-03-08 11:37 UTC, Oliver Ruepp
no flags Details | Diff

Description Evan Herbst 2010-10-10 01:00:56 UTC
Created attachment 8 [details]
test driver

When multiplying an mxn SparseMatrix by an nxp, iff m > p I get

Eigen3/src/Sparse/SparseMatrix.h:190: void Eigen3::SparseMatrix<_Scalar, _Flags, _Index>::startVec(typename Eigen3::ei_traits<Eigen3::SparseMatrix<_Scalar, _Options, _Index> >::Index) [with _Scalar = double, int _Options = 1, _Index = int]: Assertion `m_outerIndex[outer+1]==0 && "You must call startVec for each inner vector sequentially"' failed.

Column-major matrices don't have this problem. Haven't tried mixed.

I attach a test program:

$ testEigenSparseRowMajorProduct m n n p
Comment 1 Oliver Ruepp 2011-03-07 21:50:32 UTC
Created attachment 130 [details]
Test Case
Comment 2 Oliver Ruepp 2011-03-07 21:51:14 UTC
I also recently ran into this problem (I am using Eigen 3 Beta 4). It seems that its cause is the res.resize() instruction in function sparse_product_impl, line 136 in file src/Sparse/SparseSparseProduct.h. 

I was able to get things running by replacing said line with this ugly hack: 

  res.resize(rows, cols);
  if (res.innerSize() != rows || res.outerSize() != cols)
    res.resize(cols, rows);

I've tested this with: 
- ColMajor ColMajor ColMajor
- ColMajor ColMajor RowMajor
- RowMajor RowMajor RowMajor

The problem thus seems to be that resizing should happen according to inner/outer size of res, not according to rows/cols of res. 
I'm attaching the patched SparseSparseProduct.h and another test case.
Comment 3 Oliver Ruepp 2011-03-07 21:52:20 UTC
Created attachment 131 [details]
Solution hack...
Comment 4 Oliver Ruepp 2011-03-08 11:36:02 UTC
Silly me... A clean solution seems to be simply checking for ResultType::IsRowMajor. I'm attaching a patch that should be usable.
Comment 5 Oliver Ruepp 2011-03-08 11:37:23 UTC
Created attachment 133 [details]
Patch for src/Sparse/SparseSparseProduct.h
Comment 6 Gael Guennebaud 2011-03-08 16:23:21 UTC

thanks for the patch. I'm currently extending the unit tests and I'll apply your patch soon...
Comment 7 Nobody 2019-12-04 09:35:51 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.