Registered Member
|
Hi,
I'm doing particle simulations and my current bottleneck are 1/sqrt(x) and 1/x operations. Is there a way to make Eigen use the SSE intrinsic estimates "rsqrtps" and "rcpps" for the former two operations? Thanks, Mikael |
Moderator
|
Be aware that these two instructions are very imprecise, and they require one or two Newton iterations for accuracy. Nevertheless it is very easy to add support for such instruction in Eigen. The first thing to do is to implement the appropriate functor. Here is an example:
and then you can do: (a+b).unaryExpr(fastinvsqrt_func()) and/or add a global shortcut such that you can do: fastinvsqrt(a+b); and/or add a fastinvsqrt member function to ArrayBase (or even DenseBase if you wish) using our plugin mechanism, see: http://eigen.tuxfamily.org/dox-devel/To ... MatrixBase |
Registered Member
|
|
Registered Member
|
Hi again,
I tried the above suggestion, but - see code snippet below - I obviously didn't quite get it. The program compiles but prints 1,2,..10. Any help?
|
Moderator
|
unaryExpr returns an expression, so you should assign it:
v = v.unaryExpr( Eigen::fastinvsqrt_func<float>() ); |
Registered Member
|
ahh, silly me. It's working now - thanks a lot. I attach the final snippet, should anyone be interested.
|
Registered users: bartoloni, Bing [Bot], Evergrowing, Google [Bot], ourcraft