Re: [eigen] On the implementation of STL iterator for Eigen::Matrix

[ Thread Index | Date Index | More Archives ]

On Tue, Oct 2, 2018 at 2:53 PM Gael Guennebaud <gael.guennebaud@xxxxxxxxx> wrote:
On my side, I'm rather reading it as "iterate over all elements of A in row-major order", which is unfortunate as if I'm not alone with such an interpretation, then we need to come up with new names. Since rows()/cols() are already taken, we could think of:

for(auto x : A.allRows()) { ... }
for(auto x : A.rowSet()) { ... }

After a bit more thoughts, abusing rowwise()/colwise() is perhaps not that bad if we redefine the return type of A.rowwise() as "a view of the 2D matrix A as a linear collection of row-vectors with vector-wise broadcasting facilities". With such a definition, partial reductions and broadcasting sill make sense:

A.rowwise() - some_row_vector

and this open the doors for new usages, e.g.:

auto row_list = A.rowwise();

for (auto row : row_list) { .... }
auto it = find_if( row_list.begin(), row_list.end(), [](auto row) { return row.squaredNorm()==0; } );

but also, provided we add operator[] and size() members:

for (int i=0; i<row_list.size(); ++i) { auto row = row_list[i]; ... }

In an ideal world I would rename the current rows()/cols() methods to nrows()/ncols(), and rename rowwise()/colwise() to rows()/cols(), but that cannot happen ;)


Mail converted by MHonArc 2.6.19+