Re: [eigen] cwise / array

[ Thread Index | Date Index | More Archives ]


On Thu, Jul 3, 2008 at 9:06 AM, Benoît Jacob <jacob@xxxxxxxxxxxxxxx> wrote:
> Hi,
> I'd like to harmonize a bit the API for coefficient-wise operations. Currently

good idea.

> I propose to do:
> * rename cwise(functor) to fromUnary(functor) and fromBinary(functor)

hm... I don't really like the "from" which could likely be interpreted
as a "set from". What about apply*()  or maybe just unary(), binary()
? or even unaryExpr(), binaryExpr() ??
(I like the latter ones with "Expr")

> * rename create(functor) to fromNullary(functor)

this one a static member. BTW, what about naming static members with a
upper case for the first letter: MyMatrix::Random(), MyMatrix::Zero(),
etc. My point is that currently you can write:
Matrix3f a, b;
b =;
this would work but it not clear what you're really doing especially with:
b = a.fromNullary(functor);
With an upper case:
b = a.Zero();
it is immedialtely clear that you're doing something insane. I know
this is a quite common coding rule though Qt does not use it (don't
known about KDE). Moreover it works pretty well here because then you
would write Matrix3f::Zero() which might give you the feeling that
Matrix3f::Zero is a nested struct, that is wrong, but pretty close to
what actually does Zero(), i.e., creating a "zero" expression.

about fromNullary(functor), again it could be simply ::nullary(),
::Nullary(), ::nullaryExpr() or ::NullaryExpr()  ....

> * rename array() to cwise()

why not.

> * move all the cwiseSomeMethod() to cwise() so that instead of doing
> matrixbase.cwiseSomeMethod() one always does matrixbase.cwise().someMethod()


> * move the Cwise (formerly Array) proxy class to the Core module, but leave
> most of the methods in Array module -- just like the MatrixBase class is in
> Core but has methods in other modules.

yes, the previous point implies this one

> * it then becomes possible to use more operator notation e.g.
> matrixbase.cwiseProduct(other) becomes matrixbase.cwise() * other.


> I also plan to add square() and cube() functors. square() is the same as abs2
> () in the real case but has a nicer name when it's what's really meant (like
> in mandelbrot) and is different in the complex case. cube() is useful at
> least in the VDW example so it wouldn't be needed anymore to write a 12-th
> power functor, one could just do:
> m.cwise().square()
>  .cwise().square()
>  .cwise().cube()

excellent, I have to say that writing .abs2() sounded a bit strange to
me while what I wanted is really a cwise square !


Mail converted by MHonArc 2.6.19+