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

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




On Thu, Jan 5, 2017 at 3:07 PM, Massimiliano Janes <max.jns@xxxxxxxxx> wrote:
On 5 Jan 2017, at 12:06, Gael Guennebaud <gael.guennebaud@xxxxxxxxx> wrote:

Finally, these examples also reveal that the "_expression_-based" API outperforms all other alternatives, in all cases. 

moreover, that api looks much more composable than alternatives; for example, one could overload && || to mean
disjunction and union resp., to write things like

A( 5 <= iota <= 9 && iota*2+1 ) // all odd numbers between 5 and 9

this improves decoupling of subexpressions in a meaningful way ( at the cost of more metaprogramming to translate common
forms into the underlying optimal ’slicing’ logic ).

\o/ finally someone is commenting on this experiments, thanks!

Intersection and union look pretty tricky to implement efficiently as the result is not guaranteed to be an arithmetic progression anymore. So I guess we should be careful in how we design this API, but it certainly can be extended in numerous way.

Regarding your example, it actually boils down to:

A( 5 <= iota*2+1 <= 9 ) // all odd numbers between 5 and 9 inclusive

Perhaps I should have better explained this notation. With 'lo <= expr <= hi', the generated values are the one produced by 'expr' that matches the given bounds. Omitted bounds are implicitly implied by the underlying vector/matrix. In 'Iota*2+1', the symbol 'Iota' is just a mean to say enumerate all integers in ascending order. '-Iota' == same but in descending order. Here 0-based indexing is very welcome because in -Iota the first element remains the same, otherwise it would be a complete mess!
 

as a side note, concerning ic<N> and friends, why not using something ala std::placeholders: ?

iota * _2 + _1

( sorry if it has already been suggested :) )

this only works with literals, does not work with, e.g.,  template<int Dim> ..... then pass Dim as compile-time


gael
 



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