Re: [eigen] Re: Raising double to integer powers

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


On Mon, 10 May 2021, Ian Bell wrote:

Of course, shortly after having sent this message I figured it out, but it
doesn't actually result in an increase in my throughput sadly. For
posterity:

#include <Eigen/Dense>
#include <iostream>

using namespace Eigen;

struct myUnaryFunctor {
 const double m_base;
 myUnaryFunctor(double base): m_base(base) {};
 typedef double result_type;
 result_type operator()(const int &e) const
 {
     return pow(m_base, e);
 }
};

int main()
{
   auto e = Eigen::ArrayXi::LinSpaced(11, 0, 10).eval();
   double base = 2.9;
   std::cout << e.unaryExpr(myUnaryFunctor(base));
}

Assuming pow is actually your own function and does the usual repeated squaring, unlike std::pow, this may do a lot of redundant computation (in particular base*base is computed many times). Do you know anything about the integers? In particular, are they always small? I assume the LinSpaced example doesn't look like the true data. Does your pow function already cache some results?

--
Marc Glisse



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