Re: [eigen] Custom expression type API stability |

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

*To*: eigen@xxxxxxxxxxxxxxxxxxx*Subject*: Re: [eigen] Custom expression type API stability*From*: Dan Čermák <dan.cermak@xxxxxxxxxxxxxxxxxxx>*Date*: Fri, 19 Feb 2016 00:07:01 +0100

On Thursday, February 18, 2016 06:57:42 PM Gael Guennebaud wrote: > On Thu, Feb 18, 2016 at 1:46 PM, Dan Čermák <dan.cermak@xxxxxxxxxxxxxxxxxxx> > wrote: > > I need basically two different expressions: > > > > 1. given two vectors: > > cond_vec and choice_vec -> result(i) = choice_vec(i) if > > > > cond_vec(i) > 0 > > > > else choice_vec(i+1) > > this is rather simple and maybe doable otherwise (and I have already > > managed > > that using the 3.3 development version, although it's probably ugly) > > what about: > > choice_vec.head(n-1) = (cond_vec>0).select(choice_vec.head(n-1) , > choice_vec.tail(n-1)); That is exactly what I need, thanks! Maybe a small follow-up to that, is it possible to append/prepend a value to (cond_vec>0).select(choice_vec.head(n-1), choice_vec.tail(n-1)) ? I want to extend this vector of length n-1 to length n, but not create an additional vector along the way, so not something like this: new_vec << 1, (cond_vec>0).select(choice_vec.head(n-1), choice_vec.tail(n-1)) Actually its a tad more complicated than that, since I want to take the choice result, put it into head(n-1) add subtract it from tail(n-1) and add values to the first and last element (while doing the same again with another expression). Is there an elegant/efficient way how to do this? Or would it be best to give the function a reference to a result vector where to write the values into? > > > 2. calculate reductions of 3d matrices times 2d matrices (they are not > > stored > > fully, since they can be calculated fairly easily from e.g. a matrix and a > > vector, or are highly sparse): result(i) = Sum_j,k M_ijk * K_jk (as a full > > reduction) or result(i,j) = Sum_k M_ikj * K_kj > > I would like to create some abstraction where I only need to provide a > > function which calculates the elements or row/col of the contraction > > result. > > Since M and K are not even Eigen matrices, then you can workaround with a > nullary-functor, e.g.: > > res = MatrixXd::NullaryExpr(rows,cols,your_fancy_functor(M,K)); > > where your_fancy_functor has to implement an operator()(Index i, Index j) > method. > > See: > http://eigen.tuxfamily.org/dox-devel/classEigen_1_1DenseBase.html#a5a75198ed > ac1ad62205648445ee30d34 > > And of course you can hide the construction of the nullary-expression using > a free function, so that you simply has to call: > > res = fancy_product(M,K); This seems to be again exactly what I need, thanks for pointing me to the respective classes. Cheers, Dan > > gael > > > Cheers, > > > > Dan > > > > On Thursday 18 February 2016 12:10:07 Gael Guennebaud wrote: > > > Indeed, writing custom expressions still requires to play with > > > Eigen::internal, meaning that it is subject to change in the future. As > > > > you > > > > > noticed, the current 3.2 way is different than the future 3.3 way.. If > > > you > > > tell us a bit more about your need for a custom expression we might be > > > > able > > > > > to guide you towards the best approach. Maybe you don't need a new one > > > at > > > all, maybe ReturnByValue if good for, etc. > > > > > > cheers, > > > gael > > > > > > On Thu, Feb 18, 2016 at 11:06 AM, Dan Čermák < > > > > dan.cermak@xxxxxxxxxxxxxxxxxxx > > > > > > wrote: > > > > > > > > Hi Folks, > > > > > > > > I have a question concerning adding custom expression types as > > > > described > > > > > > here: > > > > http://eigen.tuxfamily.org/dox-devel/TopicNewExpressionType.html . I > > > > am > > > > > > currently developing a program that would require some custom > > > > expression > > > > > > types > > > > to be efficient. > > > > Is the way how they are implemented expected to change during the next > > > > versions? Since I could not compile the example with Eigen 3.2.7 and > > > > 3.2.8, > > > > only with the latest snapshot from mercurial. > > > > > > > > > > > > Cheers, > > > > > > > > Dan

**Follow-Ups**:**Re: [eigen] Custom expression type API stability***From:*Gael Guennebaud

**References**:**[eigen] Custom expression type API stability***From:*Dan Čermák

**Re: [eigen] Custom expression type API stability***From:*Dan Čermák

**Re: [eigen] Custom expression type API stability***From:*Gael Guennebaud

**Messages sorted by:**[ date | thread ]- Prev by Date:
**Re: [eigen] Custom expression type API stability** - Next by Date:
**Re: [eigen] Custom expression type API stability** - Previous by thread:
**Re: [eigen] Custom expression type API stability** - Next by thread:
**Re: [eigen] Custom expression type API stability**

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