New user self-registration is currently disabled. Please email eigen-core-team @ lists.tuxfamily.org if you need an account.
Bug 1370 - Wrong Index type of Eigen::SparseMatrix
Wrong Index type of Eigen::SparseMatrix
Status: RESOLVED FIXED
Product: Eigen
Classification: Unclassified
Component: Sparse
3.3 (current stable)
All All
: Normal Documentation
Assigned To: Nobody
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2016-12-31 15:57 UTC by citibeth
Modified: 2017-01-03 10:26 UTC (History)
2 users (show)



Attachments

Description citibeth 2016-12-31 15:57:33 UTC
I'm looking at: https://eigen.tuxfamily.org/dox/classEigen_1_1SparseMatrix.html
I'm using Eigen 3.3.1.  Consider the following test program:

void take_int(int *ix) {}
void take_long(long *ix) {}
void test_eigen()
{
    // Test 1
    typename Eigen::SparseMatrix<double,0,int>::Index ix_int;
    take_int(&ix_int);    // Error here
    take_long(&ix_int);

    // Test 2
    typename Eigen::SparseMatrix<double,0,long>::Index ix_long;
    take_int(&ix_long);    // Error here
    take_long(&ix_long);
}

The docs indicate that EigenSparseMatrix::Index should be int in Test1 and long in Test2.  However, trying to compile this indicates that it is long in both times; and that the _Index template argument to Eigen::SparseMatrix seems to be ignored.
Comment 1 citibeth 2016-12-31 15:58:25 UTC
This is different from the behavior of Eigen 3.2.10, which works according to the documentation.
Comment 2 Christoph Hertzberg 2016-12-31 16:22:40 UTC
Starting from Eigen 3.3 you should use SparseMatrix<...>::StorageIndex.
SparseMatrix<...>::Index is an alias for Eigen::Index (which is ptr_diff_t by default) and should usually not be used.

Can you link to where you found 
  typename Eigen::SparseMatrix<double,0,int>::Index
in the documentation, so that this can be fixed?
Comment 3 citibeth 2016-12-31 16:29:41 UTC
See here:

https://eigen.tuxfamily.org/dox/classEigen_1_1SparseMatrix.htm

The docs don't tell you explicitly to use `SparseMatrix<...>::Index`.  But they're unfortunately sparse (no pun intended); one then infers the use of `SparseMatrix<...>::Index` based on the name and description of the `_Index` argument to the `SparseMatrix` template.

I would suggest the following two courses of action:

1. Rename the `_Index` template argument to `_SparseIndex`.

2. Add an explanation in the docs of which typedefs inside `SparseMatrix<..>` should be used by the user, and what for.
Comment 4 Gael Guennebaud 2017-01-03 10:07:04 UTC
For the record, this issue was mentioned in the release summary: http://eigen.tuxfamily.org/index.php?title=3.3#Index_typedef

but since there are so many novelties, it's easy to miss it, and we should reproduce it in the SparseMatrix doc.

(In reply to citibeth from comment #3)
> See here:
> 
> https://eigen.tuxfamily.org/dox/classEigen_1_1SparseMatrix.htm
> 
> The docs don't tell you explicitly to use `SparseMatrix<...>::Index`.  But
> they're unfortunately sparse (no pun intended); 

You're not the first doing that one ;)

> one then infers the use of
> `SparseMatrix<...>::Index` based on the name and description of the `_Index`
> argument to the `SparseMatrix` template.

ah, that's bad indeed. I really thought it was already renamed "_StorageIndex", as everywhere else (hopefully).
Comment 5 Gael Guennebaud 2017-01-03 10:26:19 UTC
https://bitbucket.org/eigen/eigen/commits/aa7dbdf1cebe/
Summary:     Bug 1370: rename _Index to _StorageIndex in SparseMatrix, and add a warning in the doc regarding the 3.2 to 3.3 change of SparseMatrix::Index

https://bitbucket.org/eigen/eigen/commits/5fb2cc115cce/
Summary:     Bug 1370: add doc for StorageIndex

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