From f0c8dcf1e2f01fb200a8e48463d9f73c77bc1436 Mon Sep 17 00:00:00 2001 From: Hauke Heibel Date: Sat, 20 Feb 2010 15:26:02 +0100 Subject: Renamed AnyMatrixBase to EigenBase. --- Eigen/src/Core/AnyMatrixBase.h | 162 ------------------------------ Eigen/src/Core/BandMatrix.h | 2 +- Eigen/src/Core/DenseBase.h | 12 +-- Eigen/src/Core/DenseStorageBase.h | 8 +- Eigen/src/Core/DiagonalMatrix.h | 2 +- Eigen/src/Core/EigenBase.h | 162 ++++++++++++++++++++++++++++++ Eigen/src/Core/Matrix.h | 8 +- Eigen/src/Core/MatrixBase.h | 6 +- Eigen/src/Core/PermutationMatrix.h | 4 +- Eigen/src/Core/TriangularMatrix.h | 2 +- Eigen/src/Core/util/ForwardDeclarations.h | 2 +- Eigen/src/Core/util/XprHelper.h | 26 ++++- 12 files changed, 209 insertions(+), 187 deletions(-) delete mode 100644 Eigen/src/Core/AnyMatrixBase.h create mode 100644 Eigen/src/Core/EigenBase.h (limited to 'Eigen/src/Core') diff --git a/Eigen/src/Core/AnyMatrixBase.h b/Eigen/src/Core/AnyMatrixBase.h deleted file mode 100644 index a5d1cfe9f..000000000 --- a/Eigen/src/Core/AnyMatrixBase.h +++ /dev/null @@ -1,162 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. -// -// Copyright (C) 2009 Benoit Jacob -// Copyright (C) 2009 Gael Guennebaud -// -// Eigen is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 3 of the License, or (at your option) any later version. -// -// Alternatively, you can redistribute it and/or -// modify it under the terms of the GNU General Public License as -// published by the Free Software Foundation; either version 2 of -// the License, or (at your option) any later version. -// -// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY -// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License and a copy of the GNU General Public License along with -// Eigen. If not, see . - -#ifndef EIGEN_ANYMATRIXBASE_H -#define EIGEN_ANYMATRIXBASE_H - - -/** Common base class for all classes T such that MatrixBase has an operator=(T) and a constructor MatrixBase(T). - * - * In other words, an AnyMatrixBase object is an object that can be copied into a MatrixBase. - * - * Besides MatrixBase-derived classes, this also includes special matrix classes such as diagonal matrices, etc. - * - * Notice that this class is trivial, it is only used to disambiguate overloaded functions. - */ -template struct AnyMatrixBase -{ -// typedef typename ei_plain_matrix_type::type PlainMatrixType; - - /** \returns a reference to the derived object */ - Derived& derived() { return *static_cast(this); } - /** \returns a const reference to the derived object */ - const Derived& derived() const { return *static_cast(this); } - - inline Derived& const_cast_derived() const - { return *static_cast(const_cast(this)); } - - /** \returns the number of rows. \sa cols(), RowsAtCompileTime */ - inline int rows() const { return derived().rows(); } - /** \returns the number of columns. \sa rows(), ColsAtCompileTime*/ - inline int cols() const { return derived().cols(); } - - /** \internal Don't use it, but do the equivalent: \code dst = *this; \endcode */ - template inline void evalTo(Dest& dst) const - { derived().evalTo(dst); } - - /** \internal Don't use it, but do the equivalent: \code dst += *this; \endcode */ - template inline void addTo(Dest& dst) const - { - // This is the default implementation, - // derived class can reimplement it in a more optimized way. - typename Dest::PlainMatrixType res(rows(),cols()); - evalTo(res); - dst += res; - } - - /** \internal Don't use it, but do the equivalent: \code dst -= *this; \endcode */ - template inline void subTo(Dest& dst) const - { - // This is the default implementation, - // derived class can reimplement it in a more optimized way. - typename Dest::PlainMatrixType res(rows(),cols()); - evalTo(res); - dst -= res; - } - - /** \internal Don't use it, but do the equivalent: \code dst.applyOnTheRight(*this); \endcode */ - template inline void applyThisOnTheRight(Dest& dst) const - { - // This is the default implementation, - // derived class can reimplement it in a more optimized way. - dst = dst * this->derived(); - } - - /** \internal Don't use it, but do the equivalent: \code dst.applyOnTheLeft(*this); \endcode */ - template inline void applyThisOnTheLeft(Dest& dst) const - { - // This is the default implementation, - // derived class can reimplement it in a more optimized way. - dst = this->derived() * dst; - } - -}; - -/*************************************************************************** -* Implementation of matrix base methods -***************************************************************************/ - -/** \brief Copies the generic expression \a other into *this. - * - * \details The expression must provide a (templated) evalTo(Derived& dst) const - * function which does the actual job. In practice, this allows any user to write - * its own special matrix without having to modify MatrixBase - * - * \returns a reference to *this. - */ -template -template -Derived& DenseBase::operator=(const AnyMatrixBase &other) -{ - other.derived().evalTo(derived()); - return derived(); -} - -template -template -Derived& DenseBase::operator+=(const AnyMatrixBase &other) -{ - other.derived().addTo(derived()); - return derived(); -} - -template -template -Derived& DenseBase::operator-=(const AnyMatrixBase &other) -{ - other.derived().subTo(derived()); - return derived(); -} - -/** replaces \c *this by \c *this * \a other. - * - * \returns a reference to \c *this - */ -template -template -inline Derived& -MatrixBase::operator*=(const AnyMatrixBase &other) -{ - other.derived().applyThisOnTheRight(derived()); - return derived(); -} - -/** replaces \c *this by \c *this * \a other. It is equivalent to MatrixBase::operator*=() */ -template -template -inline void MatrixBase::applyOnTheRight(const AnyMatrixBase &other) -{ - other.derived().applyThisOnTheRight(derived()); -} - -/** replaces \c *this by \c *this * \a other. */ -template -template -inline void MatrixBase::applyOnTheLeft(const AnyMatrixBase &other) -{ - other.derived().applyThisOnTheLeft(derived()); -} - -#endif // EIGEN_ANYMATRIXBASE_H diff --git a/Eigen/src/Core/BandMatrix.h b/Eigen/src/Core/BandMatrix.h index 538e6dd76..432df0b34 100644 --- a/Eigen/src/Core/BandMatrix.h +++ b/Eigen/src/Core/BandMatrix.h @@ -57,7 +57,7 @@ struct ei_traits > }; template -class BandMatrix : public AnyMatrixBase > +class BandMatrix : public EigenBase > { public: diff --git a/Eigen/src/Core/DenseBase.h b/Eigen/src/Core/DenseBase.h index 21d792f49..2850c60cb 100644 --- a/Eigen/src/Core/DenseBase.h +++ b/Eigen/src/Core/DenseBase.h @@ -40,7 +40,7 @@ template class DenseBase : public ei_special_scalar_op_base::Scalar, typename NumTraits::Scalar>::Real> #else - : public AnyMatrixBase + : public EigenBase #endif // not EIGEN_PARSED_BY_DOXYGEN { public: @@ -53,8 +53,8 @@ template class DenseBase typedef typename ei_traits::Scalar Scalar; typedef typename ei_packet_traits::type PacketScalar; - using AnyMatrixBase::derived; - using AnyMatrixBase::const_cast_derived; + using EigenBase::derived; + using EigenBase::const_cast_derived; #endif // not EIGEN_PARSED_BY_DOXYGEN enum { @@ -214,13 +214,13 @@ template class DenseBase Derived& operator=(const DenseBase& other); template - Derived& operator=(const AnyMatrixBase &other); + Derived& operator=(const EigenBase &other); template - Derived& operator+=(const AnyMatrixBase &other); + Derived& operator+=(const EigenBase &other); template - Derived& operator-=(const AnyMatrixBase &other); + Derived& operator-=(const EigenBase &other); template Derived& operator=(const ReturnByValue& func); diff --git a/Eigen/src/Core/DenseStorageBase.h b/Eigen/src/Core/DenseStorageBase.h index 5c8e48768..530ddcd07 100644 --- a/Eigen/src/Core/DenseStorageBase.h +++ b/Eigen/src/Core/DenseStorageBase.h @@ -355,19 +355,19 @@ class DenseStorageBase : public _Base // EIGEN_INITIALIZE_BY_ZERO_IF_THAT_OPTION_IS_ENABLED } - /** \copydoc MatrixBase::operator=(const AnyMatrixBase&) + /** \copydoc MatrixBase::operator=(const EigenBase&) */ template - EIGEN_STRONG_INLINE Derived& operator=(const AnyMatrixBase &other) + EIGEN_STRONG_INLINE Derived& operator=(const EigenBase &other) { resize(other.derived().rows(), other.derived().cols()); Base::operator=(other.derived()); return this->derived(); } - /** \sa MatrixBase::operator=(const AnyMatrixBase&) */ + /** \sa MatrixBase::operator=(const EigenBase&) */ template - EIGEN_STRONG_INLINE DenseStorageBase(const AnyMatrixBase &other) + EIGEN_STRONG_INLINE DenseStorageBase(const EigenBase &other) : m_storage(other.derived().rows() * other.derived().cols(), other.derived().rows(), other.derived().cols()) { _check_template_params(); diff --git a/Eigen/src/Core/DiagonalMatrix.h b/Eigen/src/Core/DiagonalMatrix.h index 08c046611..774b0d7ae 100644 --- a/Eigen/src/Core/DiagonalMatrix.h +++ b/Eigen/src/Core/DiagonalMatrix.h @@ -28,7 +28,7 @@ #ifndef EIGEN_PARSED_BY_DOXYGEN template -class DiagonalBase : public AnyMatrixBase +class DiagonalBase : public EigenBase { public: typedef typename ei_traits::DiagonalVectorType DiagonalVectorType; diff --git a/Eigen/src/Core/EigenBase.h b/Eigen/src/Core/EigenBase.h new file mode 100644 index 000000000..8b302b663 --- /dev/null +++ b/Eigen/src/Core/EigenBase.h @@ -0,0 +1,162 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2009 Benoit Jacob +// Copyright (C) 2009 Gael Guennebaud +// +// Eigen is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// Alternatively, you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of +// the License, or (at your option) any later version. +// +// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License and a copy of the GNU General Public License along with +// Eigen. If not, see . + +#ifndef EIGEN_EIGENBASE_H +#define EIGEN_EIGENBASE_H + + +/** Common base class for all classes T such that MatrixBase has an operator=(T) and a constructor MatrixBase(T). + * + * In other words, an EigenBase object is an object that can be copied into a MatrixBase. + * + * Besides MatrixBase-derived classes, this also includes special matrix classes such as diagonal matrices, etc. + * + * Notice that this class is trivial, it is only used to disambiguate overloaded functions. + */ +template struct EigenBase +{ +// typedef typename ei_plain_matrix_type::type PlainMatrixType; + + /** \returns a reference to the derived object */ + Derived& derived() { return *static_cast(this); } + /** \returns a const reference to the derived object */ + const Derived& derived() const { return *static_cast(this); } + + inline Derived& const_cast_derived() const + { return *static_cast(const_cast(this)); } + + /** \returns the number of rows. \sa cols(), RowsAtCompileTime */ + inline int rows() const { return derived().rows(); } + /** \returns the number of columns. \sa rows(), ColsAtCompileTime*/ + inline int cols() const { return derived().cols(); } + + /** \internal Don't use it, but do the equivalent: \code dst = *this; \endcode */ + template inline void evalTo(Dest& dst) const + { derived().evalTo(dst); } + + /** \internal Don't use it, but do the equivalent: \code dst += *this; \endcode */ + template inline void addTo(Dest& dst) const + { + // This is the default implementation, + // derived class can reimplement it in a more optimized way. + typename Dest::PlainMatrixType res(rows(),cols()); + evalTo(res); + dst += res; + } + + /** \internal Don't use it, but do the equivalent: \code dst -= *this; \endcode */ + template inline void subTo(Dest& dst) const + { + // This is the default implementation, + // derived class can reimplement it in a more optimized way. + typename Dest::PlainMatrixType res(rows(),cols()); + evalTo(res); + dst -= res; + } + + /** \internal Don't use it, but do the equivalent: \code dst.applyOnTheRight(*this); \endcode */ + template inline void applyThisOnTheRight(Dest& dst) const + { + // This is the default implementation, + // derived class can reimplement it in a more optimized way. + dst = dst * this->derived(); + } + + /** \internal Don't use it, but do the equivalent: \code dst.applyOnTheLeft(*this); \endcode */ + template inline void applyThisOnTheLeft(Dest& dst) const + { + // This is the default implementation, + // derived class can reimplement it in a more optimized way. + dst = this->derived() * dst; + } + +}; + +/*************************************************************************** +* Implementation of matrix base methods +***************************************************************************/ + +/** \brief Copies the generic expression \a other into *this. + * + * \details The expression must provide a (templated) evalTo(Derived& dst) const + * function which does the actual job. In practice, this allows any user to write + * its own special matrix without having to modify MatrixBase + * + * \returns a reference to *this. + */ +template +template +Derived& DenseBase::operator=(const EigenBase &other) +{ + other.derived().evalTo(derived()); + return derived(); +} + +template +template +Derived& DenseBase::operator+=(const EigenBase &other) +{ + other.derived().addTo(derived()); + return derived(); +} + +template +template +Derived& DenseBase::operator-=(const EigenBase &other) +{ + other.derived().subTo(derived()); + return derived(); +} + +/** replaces \c *this by \c *this * \a other. + * + * \returns a reference to \c *this + */ +template +template +inline Derived& +MatrixBase::operator*=(const EigenBase &other) +{ + other.derived().applyThisOnTheRight(derived()); + return derived(); +} + +/** replaces \c *this by \c *this * \a other. It is equivalent to MatrixBase::operator*=() */ +template +template +inline void MatrixBase::applyOnTheRight(const EigenBase &other) +{ + other.derived().applyThisOnTheRight(derived()); +} + +/** replaces \c *this by \c *this * \a other. */ +template +template +inline void MatrixBase::applyOnTheLeft(const EigenBase &other) +{ + other.derived().applyThisOnTheLeft(derived()); +} + +#endif // EIGEN_EIGENBASE_H diff --git a/Eigen/src/Core/Matrix.h b/Eigen/src/Core/Matrix.h index 6f194ffba..1c43340a6 100644 --- a/Eigen/src/Core/Matrix.h +++ b/Eigen/src/Core/Matrix.h @@ -181,10 +181,10 @@ class Matrix /** * \brief Copies the generic expression \a other into *this. - * \copydetails DenseBase::operator=(const AnyMatrixBase &other) + * \copydetails DenseBase::operator=(const EigenBase &other) */ template - EIGEN_STRONG_INLINE Matrix& operator=(const AnyMatrixBase &other) + EIGEN_STRONG_INLINE Matrix& operator=(const EigenBase &other) { return Base::operator=(other); } @@ -297,10 +297,10 @@ class Matrix } /** \brief Copy constructor for generic expressions. - * \sa MatrixBase::operator=(const AnyMatrixBase&) + * \sa MatrixBase::operator=(const EigenBase&) */ template - EIGEN_STRONG_INLINE Matrix(const AnyMatrixBase &other) + EIGEN_STRONG_INLINE Matrix(const EigenBase &other) : Base(other.derived().rows() * other.derived().cols(), other.derived().rows(), other.derived().cols()) { Base::_check_template_params(); diff --git a/Eigen/src/Core/MatrixBase.h b/Eigen/src/Core/MatrixBase.h index 229195046..122a2271b 100644 --- a/Eigen/src/Core/MatrixBase.h +++ b/Eigen/src/Core/MatrixBase.h @@ -193,13 +193,13 @@ template class MatrixBase lazyProduct(const MatrixBase &other) const; template - Derived& operator*=(const AnyMatrixBase& other); + Derived& operator*=(const EigenBase& other); template - void applyOnTheLeft(const AnyMatrixBase& other); + void applyOnTheLeft(const EigenBase& other); template - void applyOnTheRight(const AnyMatrixBase& other); + void applyOnTheRight(const EigenBase& other); template const DiagonalProduct diff --git a/Eigen/src/Core/PermutationMatrix.h b/Eigen/src/Core/PermutationMatrix.h index 284baf678..2d97c9c38 100644 --- a/Eigen/src/Core/PermutationMatrix.h +++ b/Eigen/src/Core/PermutationMatrix.h @@ -55,7 +55,7 @@ struct ei_traits > {}; template -class PermutationMatrix : public AnyMatrixBase > +class PermutationMatrix : public EigenBase > { public: @@ -144,7 +144,7 @@ class PermutationMatrix : public AnyMatrixBase class TriangularBase : public AnyMatrixBase +template class TriangularBase : public EigenBase { public: diff --git a/Eigen/src/Core/util/ForwardDeclarations.h b/Eigen/src/Core/util/ForwardDeclarations.h index aed0abe6d..a56e4fb84 100644 --- a/Eigen/src/Core/util/ForwardDeclarations.h +++ b/Eigen/src/Core/util/ForwardDeclarations.h @@ -28,7 +28,7 @@ template struct ei_traits; template struct NumTraits; -template struct AnyMatrixBase; +template struct EigenBase; template struct ei_plain_matrix_type_row_major // we should be able to get rid of this one too template struct ei_must_nest_by_value { enum { ret = false }; }; +template +struct ei_is_reference +{ +#ifndef NDEBUG + static void check() { std::cout << typeid(T).name() << std::endl; } +#else + static void check() {} +#endif + enum { ret = false }; +}; + +template +struct ei_is_reference +{ +#ifndef NDEBUG + static void check() { std::cout << typeid(T).name() << "&" << std::endl; } +#else + static void check() {} +#endif + enum { ret = true }; +}; + /** * The reference selector for template expressions. The idea is that we don't * need to use references for expressions since they are light weight proxy @@ -258,7 +280,7 @@ template struct ei_are_flags_consistent * overloads for complex types */ template::ret > -struct ei_special_scalar_op_base : public AnyMatrixBase +struct ei_special_scalar_op_base : public EigenBase { // dummy operator* so that the // "using ei_special_scalar_op_base::operator*" compiles @@ -266,7 +288,7 @@ struct ei_special_scalar_op_base : public AnyMatrixBase }; template -struct ei_special_scalar_op_base : public AnyMatrixBase +struct ei_special_scalar_op_base : public EigenBase { const CwiseUnaryOp, Derived> operator*(const OtherScalar& scalar) const -- cgit v1.2.3