diff options
author | 2008-04-24 18:35:39 +0000 | |
---|---|---|
committer | 2008-04-24 18:35:39 +0000 | |
commit | 9385793f71f2a606b0527df8ea1d2153c3e70e11 (patch) | |
tree | 7881ba4e88218c356465609d44c6b43ab17491b1 /Eigen/src/Core/Functors.h | |
parent | 6ae037dfb5b340d2d545ccbb4135b04903a2e44f (diff) |
Fix a couple of issue with the vectorization. In particular, default ei_p* functions
are provided to handle not suported types seemlessly.
Added a generic null-ary expression with null-ary functors. They replace
Zero, Ones, Identity and Random.
Diffstat (limited to 'Eigen/src/Core/Functors.h')
-rw-r--r-- | Eigen/src/Core/Functors.h | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/Eigen/src/Core/Functors.h b/Eigen/src/Core/Functors.h index d0f5151bc..bb4b8bb54 100644 --- a/Eigen/src/Core/Functors.h +++ b/Eigen/src/Core/Functors.h @@ -340,6 +340,46 @@ template<typename Scalar> struct ei_functor_traits<ei_scalar_pow_op<Scalar> > { enum { Cost = 5 * NumTraits<Scalar>::MulCost, IsVectorizable = false }; }; +// nullary functors + +template<typename Scalar, bool IsVectorizable = (int(ei_packet_traits<Scalar>::size)>1?true:false) > struct ei_scalar_constant_op; + +template<typename Scalar> +struct ei_scalar_constant_op<Scalar,true> { + typedef typename ei_packet_traits<Scalar>::type PacketScalar; + ei_scalar_constant_op(const Scalar& other) : m_other(ei_pset1(other)) { } + Scalar operator() (int, int) const { return ei_pfirst(m_other); } + PacketScalar packetOp() const + { return m_other; } + const PacketScalar m_other; +}; +template<typename Scalar> +struct ei_scalar_constant_op<Scalar,false> { + ei_scalar_constant_op(const Scalar& other) : m_other(other) { } + Scalar operator() (int, int) const { return m_other; } + const Scalar m_other; +}; +template<typename Scalar> +struct ei_functor_traits<ei_scalar_constant_op<Scalar> > +{ enum { Cost = 1, IsVectorizable = ei_packet_traits<Scalar>::size>1, IsRepeatable = true }; }; + + +template<typename Scalar> struct ei_scalar_random_op EIGEN_EMPTY_STRUCT { + ei_scalar_random_op(void) {} + Scalar operator() (int, int) const { return ei_random<Scalar>(); } +}; +template<typename Scalar> +struct ei_functor_traits<ei_scalar_random_op<Scalar> > +{ enum { Cost = 5 * NumTraits<Scalar>::MulCost, IsVectorizable = false, IsRepeatable = false }; }; + + +template<typename Scalar> struct ei_scalar_identity_op EIGEN_EMPTY_STRUCT { + ei_scalar_identity_op(void) {} + Scalar operator() (int row, int col) const { return row==col ? Scalar(1) : Scalar(0); } +}; +template<typename Scalar> +struct ei_functor_traits<ei_scalar_identity_op<Scalar> > +{ enum { Cost = NumTraits<Scalar>::AddCost, IsVectorizable = false, IsRepeatable = true }; }; // default ei_functor_traits for STL functors: |