Re: [eigen] On a flexible API for submatrices, slicing, indexing, masking, etc.

[ Thread Index | Date Index | More Archives ]

On Thu, Jan 5, 2017 at 6:06 AM, Gael Guennebaud <gael.guennebaud@xxxxxxxxx> wrote:

I added a list of examples comparing aseq (inclusive), aseqn, a aseqX version with exclusive upper-bound, python, and the experimental "_expression_-based" API:

From these examples, having aseq inclusive still seems to be more handy, and the size-based aseqn function is still there for some simple cases for which an exclusive upper-bound is more handy.

They also show that having both a end and last "keyword" might be handy, but not mandatory.

Finally, these examples also reveal that the "_expression_-based" API outperforms all other alternatives, in all cases. For instance, can you guess the intent from the following python code:

A[:-(k-1)*s-2:-s] ?????

compared to:



The solution is: "pick k elements from the last one with step s in descending order".

For the record, the aseq-based version is:


​Interesting. Note the identity

aseqn(a, n, d) == ​a + iota(n) * d

So the ideal way to write what you have, one uses aseqn:

A(aseqn(last, k, -s))

This also means that iota easily covers usage case of aseqn. And this iota based _expression_ is not that more complex than aseqn.

On the other hand, aseq is not so easily implemented by iota, since iota requires the length to be known.

In the wiki, you seem to write

aseq(a, b, d) = a + iota * d <= b when (d > 0)

I am actually confused how you parse this. a + iota * d = [a, a + d, a + 2d, ....]. When you compare that with b, you get a boolean mask, no? By a + iota* d <= b, you really mean

x[x <= b] where x = (a + iota * d)

Is this iota comparison syntax standard in APL or elsewhere?

Mail converted by MHonArc 2.6.19+