This bugzilla service is closed. All entries have been migrated to

Bug 572

Summary: Differentiate the two usage of Index types
Product: Eigen Reporter: Gael Guennebaud <gael.guennebaud>
Component: GeneralAssignee: Nobody <eigen.nobody>
Severity: API Change CC: chtz, gael.guennebaud, jacob.benoit.1
Priority: Normal    
Version: 3.3 (current stable)   
Hardware: All   
OS: All   
Bug Depends on:    
Bug Blocks: 331, 877    

Description Gael Guennebaud 2013-03-21 15:46:58 UTC
Currently, the Index type appear in different contexts:

1 - For classic dense expression, Index refers to the integer type used for storing and returning sizes, for coefficient indexes, etc. In this context it is always equal to DenseIndex (=ptrdiff_t).

2 - For PermutationMatrix, Transpositions and Sparse expression, it is used for the same purpose as above, but it also corresponds to the value type used to store all the indices. It defined through a template parameter and most of the time it is equal to 'int' for compactness purpose.

This results in a lot of conflicting conversions from 64 bits integers to 32 bits ints, and so a huge amount of legitimate warnings when such warnings are detected.

In my opinion, in the 2nd case all the sizes, coefficient indexes, loop counters, etc. should keep using the globally defined DenseIndex type (poorly named), and the templated Index type should only be used for the internal storage and for method that explicitly and directly returns such indices. Concretely, this would means that PermutationMatrix::rows() would always return a DenseIndex, PermutationMatrix::operator()(i) would always take a DenseIndex, but it would return the Index type defined from its template parameter.

The problem is that would slightly change the API since some method would now take/return long int instead of int. On the other
Comment 1 Christoph Hertzberg 2014-11-03 00:35:31 UTC
This does not strictly block bug 877, but removing typedef Index from all classes would partially simplify resolving that.
Agreement for bug 877 was to add a global Index typedef, and explicitly use that in the interface (where it makes a difference).
For now, I would suggest to still return the actually used Index type for methods like rows(), cols() in order to avoid conversion warnings if users store their result as int (for SparseMatrix<..., int>).
Comment 2 Christoph Hertzberg 2014-12-02 19:33:37 UTC
See bug 877 comment 20 for an update on this.
Comment 3 Gael Guennebaud 2015-02-16 15:31:13 UTC
Fixed through this merge:
Comment 4 Nobody 2019-12-04 12:11:37 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: