diff options
author | Gael Guennebaud <g.gael@free.fr> | 2009-11-20 18:20:55 +0100 |
---|---|---|
committer | Gael Guennebaud <g.gael@free.fr> | 2009-11-20 18:20:55 +0100 |
commit | 80ebeae48d7b56500d9ebc8abd2789061af145e1 (patch) | |
tree | d6ff3642865c3a5778370edc65aa719790be7c01 /Eigen/src/Core | |
parent | 4af1753b6fa83e2c0013f38e6d9e8538896d9d3c (diff) |
Add the concept of base class plugins, and started to write the ArrayBase class.
Sorry for this messy commit but I have to commit it...
Diffstat (limited to 'Eigen/src/Core')
-rw-r--r-- | Eigen/src/Core/CwiseBinaryOp.h | 4 | ||||
-rw-r--r-- | Eigen/src/Core/CwiseBinaryOps.h | 139 | ||||
-rw-r--r-- | Eigen/src/Core/CwiseUnaryOp.h | 7 | ||||
-rw-r--r-- | Eigen/src/Core/CwiseUnaryOps.h | 221 | ||||
-rw-r--r-- | Eigen/src/Core/MatrixBase.h | 8 |
5 files changed, 13 insertions, 366 deletions
diff --git a/Eigen/src/Core/CwiseBinaryOp.h b/Eigen/src/Core/CwiseBinaryOp.h index 401d57ee5..0b45261ae 100644 --- a/Eigen/src/Core/CwiseBinaryOp.h +++ b/Eigen/src/Core/CwiseBinaryOp.h @@ -1,7 +1,7 @@ // This file is part of Eigen, a lightweight C++ template library // for linear algebra. // -// Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr> +// Copyright (C) 2008-2009 Gael Guennebaud <g.gael@free.fr> // Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com> // // Eigen is free software; you can redistribute it and/or @@ -135,7 +135,7 @@ class CwiseBinaryOp : ei_no_assignment_operator, template<typename BinaryOp, typename Lhs, typename Rhs> class CwiseBinaryOpImpl<BinaryOp, Lhs, Rhs, Dense> - : public MatrixBase<CwiseBinaryOp<BinaryOp, Lhs, Rhs> > + : public Lhs::template MakeBase< CwiseBinaryOp<BinaryOp, Lhs, Rhs> >::Type { public: diff --git a/Eigen/src/Core/CwiseBinaryOps.h b/Eigen/src/Core/CwiseBinaryOps.h deleted file mode 100644 index 0b7fa2d8b..000000000 --- a/Eigen/src/Core/CwiseBinaryOps.h +++ /dev/null @@ -1,139 +0,0 @@ -/** \returns an expression of the difference of \c *this and \a other - * - * \note If you want to substract a given scalar from all coefficients, see Cwise::operator-(). - * - * \sa class CwiseBinaryOp, MatrixBase::operator-=() - */ -template<typename OtherDerived> -EIGEN_STRONG_INLINE const CwiseBinaryOp<ei_scalar_difference_op<typename ei_traits<Derived>::Scalar>, - Derived, OtherDerived> -operator-(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const -{ - return CwiseBinaryOp<ei_scalar_difference_op<Scalar>, - Derived, OtherDerived>(derived(), other.derived()); -} - -/** \returns an expression of the sum of \c *this and \a other - * - * \note If you want to add a given scalar to all coefficients, see Cwise::operator+(). - * - * \sa class CwiseBinaryOp, MatrixBase::operator+=() - */ -template<typename OtherDerived> -EIGEN_STRONG_INLINE const CwiseBinaryOp<ei_scalar_sum_op<typename ei_traits<Derived>::Scalar>, Derived, OtherDerived> -operator+(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const -{ - return CwiseBinaryOp<ei_scalar_sum_op<Scalar>, Derived, OtherDerived>(derived(), other.derived()); -} - -/** \returns an expression of a custom coefficient-wise operator \a func of *this and \a other - * - * The template parameter \a CustomBinaryOp is the type of the functor - * of the custom operator (see class CwiseBinaryOp for an example) - * - * Here is an example illustrating the use of custom functors: - * \include class_CwiseBinaryOp.cpp - * Output: \verbinclude class_CwiseBinaryOp.out - * - * \sa class CwiseBinaryOp, MatrixBase::operator+, MatrixBase::operator-, MatrixBase::cwiseProduct - */ -template<typename CustomBinaryOp, typename OtherDerived> -EIGEN_STRONG_INLINE const CwiseBinaryOp<CustomBinaryOp, Derived, OtherDerived> -binaryExpr(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other, const CustomBinaryOp& func = CustomBinaryOp()) const -{ - return CwiseBinaryOp<CustomBinaryOp, Derived, OtherDerived>(derived(), other.derived(), func); -} - -/** \returns an expression of the Schur product (coefficient wise product) of *this and \a other - * - * Example: \include MatrixBase_cwiseProduct.cpp - * Output: \verbinclude MatrixBase_cwiseProduct.out - * - * \sa class CwiseBinaryOp, cwiseAbs2 - */ -template<typename OtherDerived> -EIGEN_STRONG_INLINE const CwiseBinaryOp<ei_scalar_product_op<Scalar>, Derived, OtherDerived> -cwiseProduct(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const -{ - return CwiseBinaryOp<ei_scalar_product_op<Scalar>, Derived, OtherDerived>(derived(), other.derived()); -} - -/** \returns an expression of the coefficient-wise == operator of *this and \a other - * - * \warning this performs an exact comparison, which is generally a bad idea with floating-point types. - * In order to check for equality between two vectors or matrices with floating-point coefficients, it is - * generally a far better idea to use a fuzzy comparison as provided by MatrixBase::isApprox() and - * MatrixBase::isMuchSmallerThan(). - * - * Example: \include MatrixBase_cwiseEqual.cpp - * Output: \verbinclude MatrixBase_cwiseEqual.out - * - * \sa MatrixBase::cwiseNotEqual(), MatrixBase::isApprox(), MatrixBase::isMuchSmallerThan() - */ -template<typename OtherDerived> -inline const CwiseBinaryOp<std::equal_to<Scalar>, Derived, OtherDerived> -cwiseEqual(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const -{ - return CwiseBinaryOp<std::equal_to<Scalar>, Derived, OtherDerived>(derived(), other.derived()); -} - -/** \returns an expression of the coefficient-wise != operator of *this and \a other - * - * \warning this performs an exact comparison, which is generally a bad idea with floating-point types. - * In order to check for equality between two vectors or matrices with floating-point coefficients, it is - * generally a far better idea to use a fuzzy comparison as provided by MatrixBase::isApprox() and - * MatrixBase::isMuchSmallerThan(). - * - * Example: \include MatrixBase_cwiseNotEqual.cpp - * Output: \verbinclude MatrixBase_cwiseNotEqual.out - * - * \sa MatrixBase::cwiseEqual(), MatrixBase::isApprox(), MatrixBase::isMuchSmallerThan() - */ -template<typename OtherDerived> -inline const CwiseBinaryOp<std::not_equal_to<Scalar>, Derived, OtherDerived> -cwiseNotEqual(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const -{ - return CwiseBinaryOp<std::not_equal_to<Scalar>, Derived, OtherDerived>(derived(), other.derived()); -} - -/** \returns an expression of the coefficient-wise min of *this and \a other - * - * Example: \include MatrixBase_cwiseMin.cpp - * Output: \verbinclude MatrixBase_cwiseMin.out - * - * \sa class CwiseBinaryOp, max() - */ -template<typename OtherDerived> -EIGEN_STRONG_INLINE const CwiseBinaryOp<ei_scalar_min_op<Scalar>, Derived, OtherDerived> -cwiseMin(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const -{ - return CwiseBinaryOp<ei_scalar_min_op<Scalar>, Derived, OtherDerived>(derived(), other.derived()); -} - -/** \returns an expression of the coefficient-wise max of *this and \a other - * - * Example: \include MatrixBase_cwiseMax.cpp - * Output: \verbinclude MatrixBase_cwiseMax.out - * - * \sa class CwiseBinaryOp, min() - */ -template<typename OtherDerived> -EIGEN_STRONG_INLINE const CwiseBinaryOp<ei_scalar_max_op<Scalar>, Derived, OtherDerived> -cwiseMax(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const -{ - return CwiseBinaryOp<ei_scalar_max_op<Scalar>, Derived, OtherDerived>(derived(), other.derived()); -} - -/** \returns an expression of the coefficient-wise quotient of *this and \a other - * - * Example: \include MatrixBase_cwiseQuotient.cpp - * Output: \verbinclude MatrixBase_cwiseQuotient.out - * - * \sa class CwiseBinaryOp, cwiseProduct(), cwiseInverse() - */ -template<typename OtherDerived> -EIGEN_STRONG_INLINE const CwiseBinaryOp<ei_scalar_quotient_op<Scalar>, Derived, OtherDerived> -cwiseQuotient(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const -{ - return CwiseBinaryOp<ei_scalar_quotient_op<Scalar>, Derived, OtherDerived>(derived(), other.derived()); -} diff --git a/Eigen/src/Core/CwiseUnaryOp.h b/Eigen/src/Core/CwiseUnaryOp.h index 55f965b4e..abece413b 100644 --- a/Eigen/src/Core/CwiseUnaryOp.h +++ b/Eigen/src/Core/CwiseUnaryOp.h @@ -92,9 +92,12 @@ class CwiseUnaryOp : ei_no_assignment_operator, const UnaryOp m_functor; }; +// This is the generic implementation for dense storage. +// It can be used for any matrix types implementing the dense concept. template<typename UnaryOp, typename MatrixType> -class CwiseUnaryOpImpl<UnaryOp,MatrixType,Dense> : public MatrixBase<CwiseUnaryOp<UnaryOp, MatrixType> > -{ +class CwiseUnaryOpImpl<UnaryOp,MatrixType,Dense> + : public MatrixType::template MakeBase< CwiseUnaryOp<UnaryOp, MatrixType> >::Type + { const typename ei_cleantype<typename MatrixType::Nested>::type& matrix() const { return derived().nestedExpression(); } typename ei_cleantype<typename MatrixType::Nested>::type& matrix() diff --git a/Eigen/src/Core/CwiseUnaryOps.h b/Eigen/src/Core/CwiseUnaryOps.h deleted file mode 100644 index a7acd0036..000000000 --- a/Eigen/src/Core/CwiseUnaryOps.h +++ /dev/null @@ -1,221 +0,0 @@ - -#ifndef EIGEN_PARSED_BY_DOXYGEN - -/** \internal Represents a scalar multiple of a matrix */ -typedef CwiseUnaryOp<ei_scalar_multiple_op<Scalar>, Derived> ScalarMultipleReturnType; -/** \internal Represents a quotient of a matrix by a scalar*/ -typedef CwiseUnaryOp<ei_scalar_quotient1_op<Scalar>, Derived> ScalarQuotient1ReturnType; -/** \internal the return type of MatrixBase::conjugate() */ -typedef typename ei_meta_if<NumTraits<Scalar>::IsComplex, - const CwiseUnaryOp<ei_scalar_conjugate_op<Scalar>, Derived>, - const Derived& - >::ret ConjugateReturnType; -/** \internal the return type of MatrixBase::real() const */ -typedef typename ei_meta_if<NumTraits<Scalar>::IsComplex, - const CwiseUnaryOp<ei_scalar_real_op<Scalar>, Derived>, - const Derived& - >::ret RealReturnType; -/** \internal the return type of MatrixBase::real() */ -typedef typename ei_meta_if<NumTraits<Scalar>::IsComplex, - CwiseUnaryView<ei_scalar_real_op<Scalar>, Derived>, - Derived& - >::ret NonConstRealReturnType; -/** \internal the return type of MatrixBase::imag() const */ -typedef CwiseUnaryOp<ei_scalar_imag_op<Scalar>, Derived> ImagReturnType; -/** \internal the return type of MatrixBase::imag() */ -typedef CwiseUnaryView<ei_scalar_imag_op<Scalar>, Derived> NonConstImagReturnType; - -#endif // not EIGEN_PARSED_BY_DOXYGEN - -/** \returns an expression of the opposite of \c *this - */ -EIGEN_STRONG_INLINE const CwiseUnaryOp<ei_scalar_opposite_op<typename ei_traits<Derived>::Scalar>,Derived> -operator-() const { return derived(); } - -EIGEN_STRONG_INLINE Derived& operator*=(const Scalar& other) -{ - SelfCwiseBinaryOp<ei_scalar_product_op<Scalar>, Derived> tmp(derived()); - tmp = PlainMatrixType::Constant(rows(),cols(),other); - return derived(); -} -EIGEN_STRONG_INLINE Derived& operator/=(const Scalar& other) -{ - SelfCwiseBinaryOp<typename ei_meta_if<NumTraits<Scalar>::HasFloatingPoint,ei_scalar_product_op<Scalar>,ei_scalar_quotient_op<Scalar> >::ret, Derived> tmp(derived()); - tmp = PlainMatrixType::Constant(rows(),cols(), NumTraits<Scalar>::HasFloatingPoint ? Scalar(1)/other : other); - return derived(); -} - -/** \returns an expression of \c *this scaled by the scalar factor \a scalar */ -EIGEN_STRONG_INLINE const ScalarMultipleReturnType -operator*(const Scalar& scalar) const -{ - return CwiseUnaryOp<ei_scalar_multiple_op<Scalar>, Derived> - (derived(), ei_scalar_multiple_op<Scalar>(scalar)); -} - -#ifdef EIGEN_PARSED_BY_DOXYGEN -const ScalarMultipleReturnType operator*(const RealScalar& scalar) const; -#endif - -/** \returns an expression of \c *this divided by the scalar value \a scalar */ -EIGEN_STRONG_INLINE const CwiseUnaryOp<ei_scalar_quotient1_op<typename ei_traits<Derived>::Scalar>, Derived> -operator/(const Scalar& scalar) const -{ - return CwiseUnaryOp<ei_scalar_quotient1_op<Scalar>, Derived> - (derived(), ei_scalar_quotient1_op<Scalar>(scalar)); -} - -/** Overloaded for efficient real matrix times complex scalar value */ -EIGEN_STRONG_INLINE const CwiseUnaryOp<ei_scalar_multiple2_op<Scalar,std::complex<Scalar> >, Derived> -operator*(const std::complex<Scalar>& scalar) const -{ - return CwiseUnaryOp<ei_scalar_multiple2_op<Scalar,std::complex<Scalar> >, Derived> - (*static_cast<const Derived*>(this), ei_scalar_multiple2_op<Scalar,std::complex<Scalar> >(scalar)); -} - -inline friend const ScalarMultipleReturnType -operator*(const Scalar& scalar, const StorageBaseType& matrix) -{ return matrix*scalar; } - -inline friend const CwiseUnaryOp<ei_scalar_multiple2_op<Scalar,std::complex<Scalar> >, Derived> -operator*(const std::complex<Scalar>& scalar, const StorageBaseType& matrix) -{ return matrix*scalar; } - -/** \returns an expression of *this with the \a Scalar type casted to - * \a NewScalar. - * - * The template parameter \a NewScalar is the type we are casting the scalars to. - * - * \sa class CwiseUnaryOp - */ -template<typename NewType> -typename ei_cast_return_type<Derived,const CwiseUnaryOp<ei_scalar_cast_op<typename ei_traits<Derived>::Scalar, NewType>, Derived> >::type -cast() const -{ - return derived(); -} - -/** \returns an expression of the complex conjugate of \c *this. - * - * \sa adjoint() */ -EIGEN_STRONG_INLINE ConjugateReturnType -conjugate() const -{ - return ConjugateReturnType(derived()); -} - -/** \returns a read-only expression of the real part of \c *this. - * - * \sa imag() */ -EIGEN_STRONG_INLINE RealReturnType -real() const { return derived(); } - -/** \returns an read-only expression of the imaginary part of \c *this. - * - * \sa real() */ -EIGEN_STRONG_INLINE const ImagReturnType -imag() const { return derived(); } - -/** \returns an expression of a custom coefficient-wise unary operator \a func of *this - * - * The template parameter \a CustomUnaryOp is the type of the functor - * of the custom unary operator. - * - * Example: - * \include class_CwiseUnaryOp.cpp - * Output: \verbinclude class_CwiseUnaryOp.out - * - * \sa class CwiseUnaryOp, class CwiseBinarOp, MatrixBase::operator-, Cwise::abs - */ -template<typename CustomUnaryOp> -EIGEN_STRONG_INLINE const CwiseUnaryOp<CustomUnaryOp, Derived> -unaryExpr(const CustomUnaryOp& func = CustomUnaryOp()) const -{ - return CwiseUnaryOp<CustomUnaryOp, Derived>(derived(), func); -} - -/** \returns an expression of a custom coefficient-wise unary operator \a func of *this - * - * The template parameter \a CustomUnaryOp is the type of the functor - * of the custom unary operator. - * - * Example: - * \include class_CwiseUnaryOp.cpp - * Output: \verbinclude class_CwiseUnaryOp.out - * - * \sa class CwiseUnaryOp, class CwiseBinarOp, MatrixBase::operator-, Cwise::abs - */ -template<typename CustomViewOp> -EIGEN_STRONG_INLINE const CwiseUnaryView<CustomViewOp, Derived> -unaryViewExpr(const CustomViewOp& func = CustomViewOp()) const -{ - return CwiseUnaryView<CustomViewOp, Derived>(derived(), func); -} - -/** \returns a non const expression of the real part of \c *this. - * - * \sa imag() */ -EIGEN_STRONG_INLINE NonConstRealReturnType -real() { return derived(); } - -/** \returns a non const expression of the imaginary part of \c *this. - * - * \sa real() */ -EIGEN_STRONG_INLINE NonConstImagReturnType -imag() { return derived(); } - -/** \returns an expression of the coefficient-wise absolute value of \c *this - * - * Example: \include MatrixBase_cwiseAbs.cpp - * Output: \verbinclude MatrixBase_cwiseAbs.out - * - * \sa cwiseAbs2() - */ -EIGEN_STRONG_INLINE const CwiseUnaryOp<ei_scalar_abs_op<Scalar>,Derived> -cwiseAbs() const { return derived(); } - -/** \returns an expression of the coefficient-wise squared absolute value of \c *this - * - * Example: \include MatrixBase_cwiseAbs2.cpp - * Output: \verbinclude MatrixBase_cwiseAbs2.out - * - * \sa cwiseAbs() - */ -EIGEN_STRONG_INLINE const CwiseUnaryOp<ei_scalar_abs2_op<Scalar>,Derived> -cwiseAbs2() const { return derived(); } - -/** \returns an expression of the coefficient-wise square root of *this. - * - * Example: \include MatrixBase_cwiseSqrt.cpp - * Output: \verbinclude MatrixBase_cwiseSqrt.out - * - * \sa cwisePow(), cwiseSquare() - */ -inline const CwiseUnaryOp<ei_scalar_sqrt_op<Scalar>,Derived> -cwiseSqrt() const { return derived(); } - -/** \returns an expression of the coefficient-wise inverse of *this. - * - * Example: \include MatrixBase_cwiseInverse.cpp - * Output: \verbinclude MatrixBase_cwiseInverse.out - * - * \sa cwiseProduct() - */ -inline const CwiseUnaryOp<ei_scalar_inverse_op<Scalar>,Derived> -cwiseInverse() const { return derived(); } - -/** \returns an expression of the coefficient-wise == operator of \c *this and a scalar \a s - * - * \warning this performs an exact comparison, which is generally a bad idea with floating-point types. - * In order to check for equality between two vectors or matrices with floating-point coefficients, it is - * generally a far better idea to use a fuzzy comparison as provided by MatrixBase::isApprox() and - * MatrixBase::isMuchSmallerThan(). - * - * \sa cwiseEqual(const MatrixBase<OtherDerived> &) const - */ -inline const CwiseUnaryOp<std::binder1st<std::equal_to<Scalar> >,Derived> -cwiseEqual(Scalar s) const -{ - return CwiseUnaryOp<std::binder1st<std::equal_to<Scalar> >,Derived> - (derived(), std::bind1st(std::equal_to<Scalar>(), s)); -} diff --git a/Eigen/src/Core/MatrixBase.h b/Eigen/src/Core/MatrixBase.h index 8bfda6595..08d404f87 100644 --- a/Eigen/src/Core/MatrixBase.h +++ b/Eigen/src/Core/MatrixBase.h @@ -61,6 +61,8 @@ template<typename Derived> class MatrixBase #ifndef EIGEN_PARSED_BY_DOXYGEN /** The base class for a given storage type. */ typedef MatrixBase StorageBaseType; + /** Construct the base class type for the derived class OtherDerived */ + template <typename OtherDerived> struct MakeBase { typedef MatrixBase<OtherDerived> Type; }; using ei_special_scalar_op_base<Derived,typename ei_traits<Derived>::Scalar, typename NumTraits<typename ei_traits<Derived>::Scalar>::Real>::operator*; @@ -246,8 +248,10 @@ template<typename Derived> class MatrixBase #endif // not EIGEN_PARSED_BY_DOXYGEN #define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::MatrixBase - #include "CwiseUnaryOps.h" - #include "CwiseBinaryOps.h" + #include "../plugins/CommonCwiseUnaryOps.h" + #include "../plugins/MatrixCwiseUnaryOps.h" + #include "../plugins/CommonCwiseBinaryOps.h" + #include "../plugins/MatrixCwiseBinaryOps.h" #undef EIGEN_CURRENT_STORAGE_BASE_CLASS /** Copies \a other into *this. \returns a reference to *this. */ |