This bugzilla service is closed. All entries have been migrated to https://gitlab.com/libeigen/eigen
Bug 1370 - Wrong Index type of Eigen::SparseMatrix
Summary: Wrong Index type of Eigen::SparseMatrix
Status: RESOLVED FIXED
Alias: None
Product: Eigen
Classification: Unclassified
Component: Sparse (show other bugs)
Version: 3.3 (current stable)
Hardware: All All
: Normal Documentation
Assignee: Nobody
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-12-31 15:57 UTC by citibeth
Modified: 2019-12-04 16:41 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
Comment 6 Nobody 2019-12-04 16:41:35 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/1370.

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