Re: [eigen] [PATCH] prod() / rowwise().prod() / colwise().prod()

[ Thread Index | Date Index | More Archives ]


thanks for the patch,

however it would be much better to improve the Redux framework on the
model of Sum (and now Prod !) such that any reduction operation is
seamlessly vectorized. Then MatrixBase::prod() could simply be
implemented as "return redux(ei_scalar_prod_op())". Same for sum(). In
practice this also requires to extend the respective functors
(ei_scalar_sum_op, prod, min, max, etc.) with the following function:
inline Scalar redux(const PacketScalar& p);
For instance, for ei_scalar_sum_op, this function would simply be
"return ei_predux(p)". For the other functors we need to add the
respective arch depended redux operations (eg, ei_predux_mul(),
ei_predux_min, etc.). I think they can all be generated using a macro
based of ei_predux() (not 100% sure for all, especially min/max for

This also remind me that we should add a big arch-dependent structure
to specify, for each scalar type, which operation is vectorized, and
what is the approximate cost. This kind of compile time data base
would be used by the functor traits.

Perhaps the ei_packet_traits could be used for that purpose, example
in arch/SSE/:

ei_default_SSE_packet_traits {
enum {
   Mul = 1,  MulCost = 1,
   Add = 1,  AddCost = 1,
   Min = 1,  MinCost = 1,
   // ...

template<> ei_packet_traits<float> : ei_default_SSE_packet_traits
    typedef _m128   type;
    enum {size = 4};

template<> ei_packet_traits<int> : ei_default_SSE_packet_traits
    typedef _m128i   type;
    enum {size = 4};
    // specialization of supported operations
    enum {
       Min = 1,  MinCost = 4, // their is no native SSE min for integers
       Max = 1, MaxCost = 4,

the main goal is to avoid to have to add some arch dependent #if #else
#endif in the definition of the functors, and perhaps, in the future
to propagate two "CoeffCost" values: one with vectorization, and one
without and check at the evaluation whether the vectorization is
really worth it (just a thought).


On Tue, Feb 10, 2009 at 4:30 PM, Ricard Marxer Piñón
<email@xxxxxxxxxxxxxxxx> wrote:
> Hi,
> Here is a patch that implements prod() for MatrixBase and PartialRedux.
> Prod is an expression representing the product of all the coefficients.
> The numpy equivalent is
> --
> ricard

Mail converted by MHonArc 2.6.19+