diff options
Diffstat (limited to 'Eigen/src/Core/CwiseUnaryOp.h')
-rw-r--r-- | Eigen/src/Core/CwiseUnaryOp.h | 123 |
1 files changed, 69 insertions, 54 deletions
diff --git a/Eigen/src/Core/CwiseUnaryOp.h b/Eigen/src/Core/CwiseUnaryOp.h index d3cc6ad30..548d500a1 100644 --- a/Eigen/src/Core/CwiseUnaryOp.h +++ b/Eigen/src/Core/CwiseUnaryOp.h @@ -50,7 +50,8 @@ struct ei_traits<CwiseUnaryOp<UnaryOp, MatrixType> > ColsAtCompileTime = MatrixType::ColsAtCompileTime, MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime, MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime, - Flags = MatrixType::Flags + Flags = MatrixType::Flags, + CoeffReadCost = MatrixType::CoeffReadCost + UnaryOp::Cost }; }; @@ -103,17 +104,18 @@ MatrixBase<Derived>::cwise(const CustomUnaryOp& func) const * * \sa class CwiseUnaryOp, MatrixBase::operator- */ -struct ei_scalar_opposite_op EIGEN_EMPTY_STRUCT { - template<typename Scalar> Scalar operator() (const Scalar& a) const { return -a; } +template<typename Scalar> struct ei_scalar_opposite_op EIGEN_EMPTY_STRUCT { + const Scalar operator() (const Scalar& a) const { return -a; } + enum { Cost = NumTraits<Scalar>::AddCost }; }; /** \returns an expression of the opposite of \c *this */ template<typename Derived> -const CwiseUnaryOp<ei_scalar_opposite_op,Derived> +const CwiseUnaryOp<ei_scalar_opposite_op<typename ei_traits<Derived>::Scalar>,Derived> MatrixBase<Derived>::operator-() const { - return CwiseUnaryOp<ei_scalar_opposite_op, Derived>(derived()); + return CwiseUnaryOp<ei_scalar_opposite_op<Scalar>, Derived>(derived()); } /** \internal @@ -121,17 +123,18 @@ MatrixBase<Derived>::operator-() const * * \sa class CwiseUnaryOp, MatrixBase::cwiseAbs */ -struct ei_scalar_abs_op EIGEN_EMPTY_STRUCT { - template<typename Scalar> Scalar operator() (const Scalar& a) const { return ei_abs(a); } +template<typename Scalar> struct ei_scalar_abs_op EIGEN_EMPTY_STRUCT { + const Scalar operator() (const Scalar& a) const { return ei_abs(a); } + enum { Cost = NumTraits<Scalar>::AddCost }; }; /** \returns an expression of the coefficient-wise absolute value of \c *this */ template<typename Derived> -const CwiseUnaryOp<ei_scalar_abs_op,Derived> +const CwiseUnaryOp<ei_scalar_abs_op<typename ei_traits<Derived>::Scalar>,Derived> MatrixBase<Derived>::cwiseAbs() const { - return CwiseUnaryOp<ei_scalar_abs_op,Derived>(derived()); + return CwiseUnaryOp<ei_scalar_abs_op<Scalar>,Derived>(derived()); } /** \internal @@ -139,17 +142,18 @@ MatrixBase<Derived>::cwiseAbs() const * * \sa class CwiseUnaryOp, MatrixBase::cwiseAbs2 */ -struct ei_scalar_abs2_op EIGEN_EMPTY_STRUCT { - template<typename Scalar> Scalar operator() (const Scalar& a) const { return ei_abs2(a); } +template<typename Scalar> struct ei_scalar_abs2_op EIGEN_EMPTY_STRUCT { + const Scalar operator() (const Scalar& a) const { return ei_abs2(a); } + enum { Cost = NumTraits<Scalar>::MulCost }; }; /** \returns an expression of the coefficient-wise squared absolute value of \c *this */ template<typename Derived> -const CwiseUnaryOp<ei_scalar_abs2_op,Derived> +const CwiseUnaryOp<ei_scalar_abs2_op<typename ei_traits<Derived>::Scalar>,Derived> MatrixBase<Derived>::cwiseAbs2() const { - return CwiseUnaryOp<ei_scalar_abs2_op,Derived>(derived()); + return CwiseUnaryOp<ei_scalar_abs2_op<Scalar>,Derived>(derived()); } /** \internal @@ -157,18 +161,19 @@ MatrixBase<Derived>::cwiseAbs2() const * * \sa class CwiseUnaryOp, MatrixBase::conjugate() */ -struct ei_scalar_conjugate_op EIGEN_EMPTY_STRUCT { - template<typename Scalar> Scalar operator() (const Scalar& a) const { return ei_conj(a); } +template<typename Scalar> struct ei_scalar_conjugate_op EIGEN_EMPTY_STRUCT { + const Scalar operator() (const Scalar& a) const { return ei_conj(a); } + enum { Cost = NumTraits<Scalar>::IsComplex ? NumTraits<Scalar>::AddCost : 0 }; }; /** \returns an expression of the complex conjugate of *this. * * \sa adjoint() */ template<typename Derived> -const CwiseUnaryOp<ei_scalar_conjugate_op, Derived> +const CwiseUnaryOp<ei_scalar_conjugate_op<typename ei_traits<Derived>::Scalar>, Derived> MatrixBase<Derived>::conjugate() const { - return CwiseUnaryOp<ei_scalar_conjugate_op, Derived>(derived()); + return CwiseUnaryOp<ei_scalar_conjugate_op<Scalar>, Derived>(derived()); } /** \internal @@ -176,10 +181,11 @@ MatrixBase<Derived>::conjugate() const * * \sa class CwiseUnaryOp, MatrixBase::cast() */ -template<typename NewType> +template<typename Scalar, typename NewType> struct ei_scalar_cast_op EIGEN_EMPTY_STRUCT { - typedef NewType result_type; - template<typename Scalar> NewType operator() (const Scalar& a) const { return static_cast<NewType>(a); } + typedef NewType result_type; + const NewType operator() (const Scalar& a) const { return static_cast<NewType>(a); } + enum { Cost = ei_is_same_type<Scalar, NewType>::ret ? 0 : NumTraits<NewType>::AddCost }; }; /** \returns an expression of *this with the \a Scalar type casted to @@ -191,10 +197,10 @@ struct ei_scalar_cast_op EIGEN_EMPTY_STRUCT { */ template<typename Derived> template<typename NewType> -const CwiseUnaryOp<ei_scalar_cast_op<NewType>, Derived> +const CwiseUnaryOp<ei_scalar_cast_op<typename ei_traits<Derived>::Scalar, NewType>, Derived> MatrixBase<Derived>::cast() const { - return CwiseUnaryOp<ei_scalar_cast_op<NewType>, Derived>(derived()); + return CwiseUnaryOp<ei_scalar_cast_op<Scalar, NewType>, Derived>(derived()); } /** \internal @@ -204,23 +210,26 @@ MatrixBase<Derived>::cast() const */ template<typename Scalar> struct ei_scalar_multiple_op { - ei_scalar_multiple_op(const Scalar& other) : m_other(other) {} - Scalar operator() (const Scalar& a) const { return a * m_other; } - const Scalar m_other; + ei_scalar_multiple_op(const Scalar& other) : m_other(other) {} + Scalar operator() (const Scalar& a) const { return a * m_other; } + const Scalar m_other; + enum { Cost = NumTraits<Scalar>::MulCost }; }; template<typename Scalar, bool HasFloatingPoint> struct ei_scalar_quotient1_impl { - ei_scalar_quotient1_impl(const Scalar& other) : m_other(static_cast<Scalar>(1) / other) {} - Scalar operator() (const Scalar& a) const { return a * m_other; } - const Scalar m_other; + ei_scalar_quotient1_impl(const Scalar& other) : m_other(static_cast<Scalar>(1) / other) {} + Scalar operator() (const Scalar& a) const { return a * m_other; } + const Scalar m_other; + enum { Cost = NumTraits<Scalar>::MulCost }; }; template<typename Scalar> struct ei_scalar_quotient1_impl<Scalar,false> { - ei_scalar_quotient1_impl(const Scalar& other) : m_other(other) {} - Scalar operator() (const Scalar& a) const { return a / m_other; } - const Scalar m_other; + ei_scalar_quotient1_impl(const Scalar& other) : m_other(other) {} + Scalar operator() (const Scalar& a) const { return a / m_other; } + const Scalar m_other; + enum { Cost = 2 * NumTraits<Scalar>::MulCost }; }; /** \internal @@ -274,16 +283,17 @@ MatrixBase<Derived>::operator/=(const Scalar& other) * * \sa class CwiseUnaryOp, MatrixBase::cwiseSqrt() */ -struct ei_scalar_sqrt_op EIGEN_EMPTY_STRUCT { - template<typename Scalar> Scalar operator() (const Scalar& a) const { return ei_sqrt(a); } +template<typename Scalar> struct ei_scalar_sqrt_op EIGEN_EMPTY_STRUCT { + const Scalar operator() (const Scalar& a) const { return ei_sqrt(a); } + enum { Cost = 5 * NumTraits<Scalar>::MulCost }; }; /** \returns an expression of the coefficient-wise square root of *this. */ template<typename Derived> -const CwiseUnaryOp<ei_scalar_sqrt_op, Derived> +const CwiseUnaryOp<ei_scalar_sqrt_op<typename ei_traits<Derived>::Scalar>, Derived> MatrixBase<Derived>::cwiseSqrt() const { - return CwiseUnaryOp<ei_scalar_sqrt_op, Derived>(derived()); + return CwiseUnaryOp<ei_scalar_sqrt_op<Scalar>, Derived>(derived()); } /** \internal @@ -291,16 +301,17 @@ MatrixBase<Derived>::cwiseSqrt() const * * \sa class CwiseUnaryOp, MatrixBase::cwiseExp() */ -struct ei_scalar_exp_op EIGEN_EMPTY_STRUCT { - template<typename Scalar> Scalar operator() (const Scalar& a) const { return ei_exp(a); } +template<typename Scalar> struct ei_scalar_exp_op EIGEN_EMPTY_STRUCT { + const Scalar operator() (const Scalar& a) const { return ei_exp(a); } + enum { Cost = 5 * NumTraits<Scalar>::MulCost }; }; /** \returns an expression of the coefficient-wise exponential of *this. */ template<typename Derived> -const CwiseUnaryOp<ei_scalar_exp_op, Derived> +const CwiseUnaryOp<ei_scalar_exp_op<typename ei_traits<Derived>::Scalar>, Derived> MatrixBase<Derived>::cwiseExp() const { - return CwiseUnaryOp<ei_scalar_exp_op, Derived>(derived()); + return CwiseUnaryOp<ei_scalar_exp_op<Scalar>, Derived>(derived()); } /** \internal @@ -308,16 +319,17 @@ MatrixBase<Derived>::cwiseExp() const * * \sa class CwiseUnaryOp, MatrixBase::cwiseLog() */ -struct ei_scalar_log_op EIGEN_EMPTY_STRUCT { - template<typename Scalar> Scalar operator() (const Scalar& a) const { return ei_log(a); } +template<typename Scalar> struct ei_scalar_log_op EIGEN_EMPTY_STRUCT { + const Scalar operator() (const Scalar& a) const { return ei_log(a); } + enum { Cost = 5 * NumTraits<Scalar>::MulCost }; }; /** \returns an expression of the coefficient-wise logarithm of *this. */ template<typename Derived> -const CwiseUnaryOp<ei_scalar_log_op, Derived> +const CwiseUnaryOp<ei_scalar_log_op<typename ei_traits<Derived>::Scalar>, Derived> MatrixBase<Derived>::cwiseLog() const { - return CwiseUnaryOp<ei_scalar_log_op, Derived>(derived()); + return CwiseUnaryOp<ei_scalar_log_op<Scalar>, Derived>(derived()); } /** \internal @@ -325,16 +337,17 @@ MatrixBase<Derived>::cwiseLog() const * * \sa class CwiseUnaryOp, MatrixBase::cwiseCos() */ -struct ei_scalar_cos_op EIGEN_EMPTY_STRUCT { - template<typename Scalar> Scalar operator() (const Scalar& a) const { return ei_cos(a); } +template<typename Scalar> struct ei_scalar_cos_op EIGEN_EMPTY_STRUCT { + const Scalar operator() (const Scalar& a) const { return ei_cos(a); } + enum { Cost = 5 * NumTraits<Scalar>::MulCost }; }; /** \returns an expression of the coefficient-wise cosine of *this. */ template<typename Derived> -const CwiseUnaryOp<ei_scalar_cos_op, Derived> +const CwiseUnaryOp<ei_scalar_cos_op<typename ei_traits<Derived>::Scalar>, Derived> MatrixBase<Derived>::cwiseCos() const { - return CwiseUnaryOp<ei_scalar_cos_op, Derived>(derived()); + return CwiseUnaryOp<ei_scalar_cos_op<Scalar>, Derived>(derived()); } /** \internal @@ -342,16 +355,17 @@ MatrixBase<Derived>::cwiseCos() const * * \sa class CwiseUnaryOp, MatrixBase::cwiseSin() */ -struct ei_scalar_sin_op EIGEN_EMPTY_STRUCT { - template<typename Scalar> Scalar operator() (const Scalar& a) const { return ei_sin(a); } +template<typename Scalar> struct ei_scalar_sin_op EIGEN_EMPTY_STRUCT { + const Scalar operator() (const Scalar& a) const { return ei_sin(a); } + enum { Cost = 5 * NumTraits<Scalar>::MulCost }; }; /** \returns an expression of the coefficient-wise sine of *this. */ template<typename Derived> -const CwiseUnaryOp<ei_scalar_sin_op, Derived> +const CwiseUnaryOp<ei_scalar_sin_op<typename ei_traits<Derived>::Scalar>, Derived> MatrixBase<Derived>::cwiseSin() const { - return CwiseUnaryOp<ei_scalar_sin_op, Derived>(derived()); + return CwiseUnaryOp<ei_scalar_sin_op<Scalar>, Derived>(derived()); } /** \internal @@ -361,9 +375,10 @@ MatrixBase<Derived>::cwiseSin() const */ template<typename Scalar> struct ei_scalar_pow_op { - ei_scalar_pow_op(const Scalar& exponent) : m_exponent(exponent) {} - Scalar operator() (const Scalar& a) const { return ei_pow(a, m_exponent); } - const Scalar m_exponent; + ei_scalar_pow_op(const Scalar& exponent) : m_exponent(exponent) {} + Scalar operator() (const Scalar& a) const { return ei_pow(a, m_exponent); } + const Scalar m_exponent; + enum { Cost = 5 * NumTraits<Scalar>::MulCost }; }; /** \relates MatrixBase */ |