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

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]

*To*: eigen <eigen@xxxxxxxxxxxxxxxxxxx>*Subject*: [eigen] On the implementation of STL iterator for Eigen::Matrix*From*: Gael Guennebaud <gael.guennebaud@xxxxxxxxx>*Date*: Tue, 2 Oct 2018 14:53:49 +0200*Dkim-signature*: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=Mfh/FgRQMRv4jNNhgd/KceI6drUBAgKwvY8IcN+OpAg=; b=qUVfbhYWPfVC29MNqfMyVxxYGj5ZmnK/PtJqgoYTaDo1F5CNA/SwcvscG29qcyMasw 4TEPoS4lHcSBhowQlUrDAz0gHZDUwfffhdT9YaHllvOzPp3Fj71tg+4monWE3RAiNTMv ltivq5inLHKV9/BzzWRWrOIDbtL1lx2xoyfoYWjTqiqn0BPJjYKbYH3p4uGE02/msFcr 3qD+ixGTKhP95mspI8XU0ZWb/H3VXpeq3NwrOV2Yp5kJDXu2ieV1myq0HY0fV7rkUo0m 9U4+68+wmC8ygFW3egl4GhpmislpLdZbKfAH8iFdvUQ8Y0/mRY93i4rTUsLatCXNt2DW G96w==

Hi list,

we're eventually implementing STL iterators to iterator over the coefficients of a vector/matrix as well as over the columns or rows of a matrix, and your inputs might be welcome to help converging to a stable API, see below.

You can watch the WIP in PR 519 [1], and find some background in bug 231 [2]. Basically, to avoid ambiguities, we decided that iterators over coefficients would be defined for 1D _expression_ only, meaning that to iterate over the elements of a 2D Matrix you'll have to explicitly reshape it as a 1D vector first. Some typical examples:

VectorXd v;

MatrixXd A;

for(auto x : v) {...}

for(auto x : A.col(j)) {...}

for(auto x : A.row(i)) {...}

for(auto x : A.reshaped()) {...}

The last line iterate in column-major order regardless of the storage order of A. So far so good. Things get more tricky now.

To iterate over rows or columns, we need to define a proxy telling so. One option is to reuse (abuse?) rowwise()/colwise():

for(auto x : A..rowwise()) { ... }

Is it obvious to everyone that this line is iterating over the rows of A and is thus a synonym for:

for(int i=0;i<A.rows();++i) { auto x = A.row(i); ... }

??

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()) { ... }

?????

Feel free to share your opinion on that question as well as on the other minor issues discussed in the PR.

thanks,

gael

**Follow-Ups**:**Re: [eigen] On the implementation of STL iterator for Eigen::Matrix***From:*Brook Milligan

**Re: [eigen] On the implementation of STL iterator for Eigen::Matrix***From:*Patrik Huber

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

**Re: [eigen] On the implementation of STL iterator for Eigen::Matrix***From:*Joseph Mirabel

**Re: [eigen] On the implementation of STL iterator for Eigen::Matrix***From:*David Tellenbach

**Re: [eigen] On the implementation of STL iterator for Eigen::Matrix***From:*Gael Guennebaud

**Messages sorted by:**[ date | thread ]- Next by Date:
**Re: [eigen] On the implementation of STL iterator for Eigen::Matrix** - Next by thread:
**Re: [eigen] On the implementation of STL iterator for Eigen::Matrix**

Mail converted by MHonArc 2.6.19+ | http://listengine.tuxfamily.org/ |