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 );
A = ltl::apply( G, 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;
}
VEC_TYPE(float) operator()( VEC_TYPE(float) a )
{
return _mm_mul_ps(a,a);
}
};