Apply Expressions
[The Class MArray]

Apply a function object (any object that defines operator()) to all elements of an MArray or Expression.

For array expression E and function object F

A = ltl::apply( F, E ); // elementwise apply F.operator() to E.
A = ltl::apply( G, A, B ); // same, with a binary functor: apply G.operator() to A,B

The functor F has to define

 typedef typename F::value_type

and if it is to be used in LTL_USE_SIMD mode, it has to provide

 enum { isVectorizable = 0/1 }

to indicate if it is vectorizable or not. If it is vectorizable, it has to provide

 operator()( VEC_TYPE(parameter_type) )

which will be used during evaluation.

Here's an example:

struct functor
{
   typedef float value_type;
   enum { isVectorizable = 0 };

   value_type operator()( float a )
   {
      return a*a;
   }
};

struct binary_functor
{
   typedef float value_type;
   enum { isVectorizable = 0 };

   value_type operator()( float a, float b )
   {
      return a+b;
   }
};

Here's the implementation of the above unary functor in a vectorizable version:

struct functor
{
   typedef float value_type;
   enum { isVectorizable = 1 };

   float operator()( float a )
   {
      return a*a;
   }

   // SSE implementation of float multiply:
   VEC_TYPE(float) operator()( VEC_TYPE(float) a )
   {
      return _mm_mul_ps(a,a);
   }
};

Generated on 19 Feb 2015 for LTL by  doxygen 1.6.1