diff options
author | Benoit Jacob <jacob.benoit.1@gmail.com> | 2008-03-13 20:36:01 +0000 |
---|---|---|
committer | Benoit Jacob <jacob.benoit.1@gmail.com> | 2008-03-13 20:36:01 +0000 |
commit | fe569b060c367d34c83624061fff407738609402 (patch) | |
tree | 767d3aa09bc952e7709503bd5bca2dce81fa3be0 | |
parent | 908a0fbab5725b182afa57b1c3fcb0b6b6912721 (diff) |
get rid of MatrixRef, simplifications.
-rw-r--r-- | Eigen/Core | 1 | ||||
-rw-r--r-- | Eigen/src/Core/Block.h | 70 | ||||
-rw-r--r-- | Eigen/src/Core/Coeffs.h | 8 | ||||
-rw-r--r-- | Eigen/src/Core/CwiseBinaryOp.h | 20 | ||||
-rw-r--r-- | Eigen/src/Core/CwiseUnaryOp.h | 25 | ||||
-rw-r--r-- | Eigen/src/Core/DiagonalCoeffs.h | 14 | ||||
-rw-r--r-- | Eigen/src/Core/DiagonalMatrix.h | 9 | ||||
-rw-r--r-- | Eigen/src/Core/ForwardDeclarations.h | 6 | ||||
-rw-r--r-- | Eigen/src/Core/Identity.h | 2 | ||||
-rw-r--r-- | Eigen/src/Core/Map.h | 1 | ||||
-rw-r--r-- | Eigen/src/Core/Matrix.h | 4 | ||||
-rw-r--r-- | Eigen/src/Core/MatrixBase.h | 19 | ||||
-rw-r--r-- | Eigen/src/Core/MatrixRef.h | 72 | ||||
-rw-r--r-- | Eigen/src/Core/Minor.h | 13 | ||||
-rw-r--r-- | Eigen/src/Core/Ones.h | 1 | ||||
-rw-r--r-- | Eigen/src/Core/Product.h | 17 | ||||
-rw-r--r-- | Eigen/src/Core/Random.h | 4 | ||||
-rw-r--r-- | Eigen/src/Core/Transpose.h | 13 | ||||
-rw-r--r-- | Eigen/src/Core/Util.h | 3 | ||||
-rw-r--r-- | Eigen/src/Core/Zero.h | 1 | ||||
-rw-r--r-- | bench/benchmark.cpp | 2 | ||||
-rw-r--r-- | doc/examples/class_Block.cpp | 4 | ||||
-rw-r--r-- | doc/examples/class_Column.cpp | 4 | ||||
-rw-r--r-- | doc/examples/class_CwiseBinaryOp.cpp | 2 | ||||
-rw-r--r-- | doc/examples/class_FixedBlock.cpp | 4 | ||||
-rw-r--r-- | doc/examples/class_Row.cpp | 4 |
26 files changed, 107 insertions, 216 deletions
diff --git a/Eigen/Core b/Eigen/Core index 68a1e5e5c..a3dc23b2e 100644 --- a/Eigen/Core +++ b/Eigen/Core @@ -15,7 +15,6 @@ namespace Eigen { #include "src/Core/MatrixBase.h" #include "src/Core/Coeffs.h" #include "src/Core/OperatorEquals.h" -#include "src/Core/MatrixRef.h" #include "src/Core/MatrixStorage.h" #include "src/Core/Matrix.h" #include "src/Core/Eval.h" diff --git a/Eigen/src/Core/Block.h b/Eigen/src/Core/Block.h index 7b504239a..c83cdc0de 100644 --- a/Eigen/src/Core/Block.h +++ b/Eigen/src/Core/Block.h @@ -77,11 +77,9 @@ template<typename MatrixType, int BlockRows, int BlockCols> class Block EIGEN_GENERIC_PUBLIC_INTERFACE(Block) - typedef typename MatrixType::AsArg MatRef; - /** Column or Row constructor */ - Block(const MatRef& matrix, int i) + Block(const MatrixType& matrix, int i) : m_matrix(matrix), // It is a row if and only if BlockRows==1 and BlockCols==MatrixType::ColsAtCompileTime, // and it is a column if and only if BlockRows==MatrixType::RowsAtCompileTime and BlockCols==1, @@ -99,7 +97,7 @@ template<typename MatrixType, int BlockRows, int BlockCols> class Block /** Fixed-size constructor */ - Block(const MatRef& matrix, int startRow, int startCol) + Block(const MatrixType& matrix, int startRow, int startCol) : m_matrix(matrix), m_startRow(startRow), m_startCol(startCol) { assert(RowsAtCompileTime!=Dynamic && RowsAtCompileTime!=Dynamic); @@ -109,7 +107,7 @@ template<typename MatrixType, int BlockRows, int BlockCols> class Block /** Dynamic-size constructor */ - Block(const MatRef& matrix, + Block(const MatrixType& matrix, int startRow, int startCol, int blockRows, int blockCols) : m_matrix(matrix), m_startRow(startRow), m_startCol(startCol), @@ -125,13 +123,13 @@ template<typename MatrixType, int BlockRows, int BlockCols> class Block private: - const Block& _asArg() const { return *this; } int _rows() const { return m_blockRows.value(); } int _cols() const { return m_blockCols.value(); } Scalar& _coeffRef(int row, int col) { - return m_matrix.coeffRef(row + m_startRow.value(), col + m_startCol.value()); + return m_matrix.const_cast_derived() + .coeffRef(row + m_startRow.value(), col + m_startCol.value()); } Scalar _coeff(int row, int col) const @@ -141,7 +139,7 @@ template<typename MatrixType, int BlockRows, int BlockCols> class Block protected: - MatRef m_matrix; + const typename MatrixType::XprCopy m_matrix; ei_int_if_dynamic<MatrixType::RowsAtCompileTime == 1 ? 0 : Dynamic> m_startRow; ei_int_if_dynamic<MatrixType::ColsAtCompileTime == 1 ? 0 : Dynamic> m_startCol; ei_int_if_dynamic<RowsAtCompileTime> m_blockRows; @@ -168,7 +166,7 @@ template<typename Derived> Block<Derived> MatrixBase<Derived> ::block(int startRow, int startCol, int blockRows, int blockCols) { - return Block<Derived>(asArg(), startRow, startCol, blockRows, blockCols); + return Block<Derived>(derived(), startRow, startCol, blockRows, blockCols); } /** This is the const version of block(int,int,int,int). */ @@ -176,7 +174,7 @@ template<typename Derived> const Block<Derived> MatrixBase<Derived> ::block(int startRow, int startCol, int blockRows, int blockCols) const { - return Block<Derived>(asArg(), startRow, startCol, blockRows, blockCols); + return Block<Derived>(derived(), startRow, startCol, blockRows, blockCols); } /** \returns a dynamic-size expression of a block in *this. @@ -200,10 +198,10 @@ Block<Derived> MatrixBase<Derived> ::block(int start, int size) { assert(IsVectorAtCompileTime); - return Block<Derived>(asArg(), RowsAtCompileTime == 1 ? 0 : start, - ColsAtCompileTime == 1 ? 0 : start, - RowsAtCompileTime == 1 ? 1 : size, - ColsAtCompileTime == 1 ? 1 : size); + return Block<Derived>(derived(), RowsAtCompileTime == 1 ? 0 : start, + ColsAtCompileTime == 1 ? 0 : start, + RowsAtCompileTime == 1 ? 1 : size, + ColsAtCompileTime == 1 ? 1 : size); } /** This is the const version of block(int,int).*/ @@ -212,10 +210,10 @@ const Block<Derived> MatrixBase<Derived> ::block(int start, int size) const { assert(IsVectorAtCompileTime); - return Block<Derived>(asArg(), RowsAtCompileTime == 1 ? 0 : start, - ColsAtCompileTime == 1 ? 0 : start, - RowsAtCompileTime == 1 ? 1 : size, - ColsAtCompileTime == 1 ? 1 : size); + return Block<Derived>(derived(), RowsAtCompileTime == 1 ? 0 : start, + ColsAtCompileTime == 1 ? 0 : start, + RowsAtCompileTime == 1 ? 1 : size, + ColsAtCompileTime == 1 ? 1 : size); } /** \returns a dynamic-size expression of the first coefficients of *this. @@ -238,7 +236,7 @@ Block<Derived> MatrixBase<Derived> ::start(int size) { assert(IsVectorAtCompileTime); - return Block<Derived>(asArg(), 0, 0, + return Block<Derived>(derived(), 0, 0, RowsAtCompileTime == 1 ? 1 : size, ColsAtCompileTime == 1 ? 1 : size); } @@ -249,7 +247,7 @@ const Block<Derived> MatrixBase<Derived> ::start(int size) const { assert(IsVectorAtCompileTime); - return Block<Derived>(asArg(), 0, 0, + return Block<Derived>(derived(), 0, 0, RowsAtCompileTime == 1 ? 1 : size, ColsAtCompileTime == 1 ? 1 : size); } @@ -274,7 +272,7 @@ Block<Derived> MatrixBase<Derived> ::end(int size) { assert(IsVectorAtCompileTime); - return Block<Derived>(asArg(), + return Block<Derived>(derived(), RowsAtCompileTime == 1 ? 0 : rows() - size, ColsAtCompileTime == 1 ? 0 : cols() - size, RowsAtCompileTime == 1 ? 1 : size, @@ -287,7 +285,7 @@ const Block<Derived> MatrixBase<Derived> ::end(int size) const { assert(IsVectorAtCompileTime); - return Block<Derived>(asArg(), + return Block<Derived>(derived(), RowsAtCompileTime == 1 ? 0 : rows() - size, ColsAtCompileTime == 1 ? 0 : cols() - size, RowsAtCompileTime == 1 ? 1 : size, @@ -315,13 +313,13 @@ Block<Derived> MatrixBase<Derived> ::corner(CornerType type, int cRows, int cCols) { if(type == TopLeft) - return Block<Derived>(asArg(), 0, 0, cRows, cCols); + return Block<Derived>(derived(), 0, 0, cRows, cCols); else if(type == TopRight) - return Block<Derived>(asArg(), 0, cols() - cCols, cRows, cCols); + return Block<Derived>(derived(), 0, cols() - cCols, cRows, cCols); else if(type == BottomLeft) - return Block<Derived>(asArg(), rows() - cRows, 0, cRows, cCols); + return Block<Derived>(derived(), rows() - cRows, 0, cRows, cCols); else - return Block<Derived>(asArg(), rows() - cRows, cols() - cCols, cRows, cCols); + return Block<Derived>(derived(), rows() - cRows, cols() - cCols, cRows, cCols); } /** This is the const version of corner(CornerType, int, int).*/ @@ -330,13 +328,13 @@ const Block<Derived> MatrixBase<Derived> ::corner(CornerType type, int cRows, int cCols) const { if(type == TopLeft) - return Block<Derived>(asArg(), 0, 0, cRows, cCols); + return Block<Derived>(derived(), 0, 0, cRows, cCols); else if(type == TopRight) - return Block<Derived>(asArg(), 0, cols() - cCols, cRows, cCols); + return Block<Derived>(derived(), 0, cols() - cCols, cRows, cCols); else if(type == BottomLeft) - return Block<Derived>(asArg(), rows() - cRows, 0, cRows, cCols); + return Block<Derived>(derived(), rows() - cRows, 0, cRows, cCols); else - return Block<Derived>(asArg(), rows() - cRows, cols() - cCols, cRows, cCols); + return Block<Derived>(derived(), rows() - cRows, cols() - cCols, cRows, cCols); } /** \returns a fixed-size expression of a block in *this. @@ -360,7 +358,7 @@ template<int BlockRows, int BlockCols> Block<Derived, BlockRows, BlockCols> MatrixBase<Derived> ::block(int startRow, int startCol) { - return Block<Derived, BlockRows, BlockCols>(asArg(), startRow, startCol); + return Block<Derived, BlockRows, BlockCols>(derived(), startRow, startCol); } /** This is the const version of block<>(int, int). */ @@ -369,7 +367,7 @@ template<int BlockRows, int BlockCols> const Block<Derived, BlockRows, BlockCols> MatrixBase<Derived> ::block(int startRow, int startCol) const { - return Block<Derived, BlockRows, BlockCols>(asArg(), startRow, startCol); + return Block<Derived, BlockRows, BlockCols>(derived(), startRow, startCol); } /** \returns an expression of the \a i-th column of *this. Note that the numbering starts at 0. @@ -382,7 +380,7 @@ template<typename Derived> Block<Derived, ei_traits<Derived>::RowsAtCompileTime, 1> MatrixBase<Derived>::col(int i) { - return Block<Derived, ei_traits<Derived>::RowsAtCompileTime, 1>(asArg(), i); + return Block<Derived, ei_traits<Derived>::RowsAtCompileTime, 1>(derived(), i); } /** This is the const version of col(). */ @@ -390,7 +388,7 @@ template<typename Derived> const Block<Derived, ei_traits<Derived>::RowsAtCompileTime, 1> MatrixBase<Derived>::col(int i) const { - return Block<Derived, ei_traits<Derived>::RowsAtCompileTime, 1>(asArg(), i); + return Block<Derived, ei_traits<Derived>::RowsAtCompileTime, 1>(derived(), i); } /** \returns an expression of the \a i-th row of *this. Note that the numbering starts at 0. @@ -403,7 +401,7 @@ template<typename Derived> Block<Derived, 1, ei_traits<Derived>::ColsAtCompileTime> MatrixBase<Derived>::row(int i) { - return Block<Derived, 1, ei_traits<Derived>::ColsAtCompileTime>(asArg(), i); + return Block<Derived, 1, ei_traits<Derived>::ColsAtCompileTime>(derived(), i); } /** This is the const version of row(). */ @@ -411,7 +409,7 @@ template<typename Derived> const Block<Derived, 1, ei_traits<Derived>::ColsAtCompileTime> MatrixBase<Derived>::row(int i) const { - return Block<Derived, 1, ei_traits<Derived>::ColsAtCompileTime>(asArg(), i); + return Block<Derived, 1, ei_traits<Derived>::ColsAtCompileTime>(derived(), i); } #endif // EIGEN_BLOCK_H diff --git a/Eigen/src/Core/Coeffs.h b/Eigen/src/Core/Coeffs.h index bbaa3d33a..905093f7b 100644 --- a/Eigen/src/Core/Coeffs.h +++ b/Eigen/src/Core/Coeffs.h @@ -45,7 +45,7 @@ typename ei_traits<Derived>::Scalar MatrixBase<Derived> { eigen_internal_assert(row >= 0 && row < rows() && col >= 0 && col < cols()); - return static_cast<const Derived *>(this)->_coeff(row, col); + return derived()._coeff(row, col); } /** \returns the coefficient at given the given row and column. @@ -58,7 +58,7 @@ typename ei_traits<Derived>::Scalar MatrixBase<Derived> { assert(row >= 0 && row < rows() && col >= 0 && col < cols()); - return static_cast<const Derived *>(this)->_coeff(row, col); + return derived()._coeff(row, col); } /** Short version: don't use this function, use @@ -81,7 +81,7 @@ typename ei_traits<Derived>::Scalar& MatrixBase<Derived> { eigen_internal_assert(row >= 0 && row < rows() && col >= 0 && col < cols()); - return static_cast<Derived *>(this)->_coeffRef(row, col); + return derived()._coeffRef(row, col); } /** \returns a reference to the coefficient at given the given row and column. @@ -94,7 +94,7 @@ typename ei_traits<Derived>::Scalar& MatrixBase<Derived> { assert(row >= 0 && row < rows() && col >= 0 && col < cols()); - return static_cast<Derived *>(this)->_coeffRef(row, col); + return derived()._coeffRef(row, col); } /** Short version: don't use this function, use diff --git a/Eigen/src/Core/CwiseBinaryOp.h b/Eigen/src/Core/CwiseBinaryOp.h index 7478f6256..76e4f0659 100644 --- a/Eigen/src/Core/CwiseBinaryOp.h +++ b/Eigen/src/Core/CwiseBinaryOp.h @@ -71,10 +71,7 @@ class CwiseBinaryOp : ei_no_assignment_operator, EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseBinaryOp) - typedef typename Lhs::AsArg LhsRef; - typedef typename Rhs::AsArg RhsRef; - - CwiseBinaryOp(const LhsRef& lhs, const RhsRef& rhs, const BinaryOp& func = BinaryOp()) + CwiseBinaryOp(const Lhs& lhs, const Rhs& rhs, const BinaryOp& func = BinaryOp()) : m_lhs(lhs), m_rhs(rhs), m_functor(func) { assert(lhs.rows() == rhs.rows() && lhs.cols() == rhs.cols()); @@ -82,7 +79,6 @@ class CwiseBinaryOp : ei_no_assignment_operator, private: - const CwiseBinaryOp& _asArg() const { return *this; } int _rows() const { return m_lhs.rows(); } int _cols() const { return m_lhs.cols(); } @@ -92,8 +88,8 @@ class CwiseBinaryOp : ei_no_assignment_operator, } protected: - const LhsRef m_lhs; - const RhsRef m_rhs; + const typename Lhs::XprCopy m_lhs; + const typename Rhs::XprCopy m_rhs; const BinaryOp m_functor; }; @@ -143,7 +139,7 @@ template<typename Derived1, typename Derived2> const CwiseBinaryOp<ei_scalar_difference_op, Derived1, Derived2> operator-(const MatrixBase<Derived1> &mat1, const MatrixBase<Derived2> &mat2) { - return CwiseBinaryOp<ei_scalar_difference_op, Derived1, Derived2>(mat1.asArg(), mat2.asArg()); + return CwiseBinaryOp<ei_scalar_difference_op, Derived1, Derived2>(mat1.derived(), mat2.derived()); } /** replaces \c *this by \c *this - \a other. @@ -168,7 +164,7 @@ template<typename Derived1, typename Derived2> const CwiseBinaryOp<ei_scalar_sum_op, Derived1, Derived2> operator+(const MatrixBase<Derived1> &mat1, const MatrixBase<Derived2> &mat2) { - return CwiseBinaryOp<ei_scalar_sum_op, Derived1, Derived2>(mat1.asArg(), mat2.asArg()); + return CwiseBinaryOp<ei_scalar_sum_op, Derived1, Derived2>(mat1.derived(), mat2.derived()); } /** replaces \c *this by \c *this + \a other. @@ -192,7 +188,7 @@ template<typename OtherDerived> const CwiseBinaryOp<ei_scalar_product_op, Derived, OtherDerived> MatrixBase<Derived>::cwiseProduct(const MatrixBase<OtherDerived> &other) const { - return CwiseBinaryOp<ei_scalar_product_op, Derived, OtherDerived>(asArg(), other.asArg()); + return CwiseBinaryOp<ei_scalar_product_op, Derived, OtherDerived>(derived(), other.derived()); } /** \returns an expression of the coefficient-wise quotient of *this and \a other @@ -204,7 +200,7 @@ template<typename OtherDerived> const CwiseBinaryOp<ei_scalar_quotient_op, Derived, OtherDerived> MatrixBase<Derived>::cwiseQuotient(const MatrixBase<OtherDerived> &other) const { - return CwiseBinaryOp<ei_scalar_quotient_op, Derived, OtherDerived>(asArg(), other.asArg()); + return CwiseBinaryOp<ei_scalar_quotient_op, Derived, OtherDerived>(derived(), other.derived()); } /** \returns an expression of a custom coefficient-wise operator \a func of *this and \a other @@ -219,7 +215,7 @@ template<typename CustomBinaryOp, typename OtherDerived> const CwiseBinaryOp<CustomBinaryOp, Derived, OtherDerived> MatrixBase<Derived>::cwise(const MatrixBase<OtherDerived> &other, const CustomBinaryOp& func) const { - return CwiseBinaryOp<CustomBinaryOp, Derived, OtherDerived>(asArg(), other.asArg(), func); + return CwiseBinaryOp<CustomBinaryOp, Derived, OtherDerived>(derived(), other.derived(), func); } #endif // EIGEN_CWISE_BINARY_OP_H diff --git a/Eigen/src/Core/CwiseUnaryOp.h b/Eigen/src/Core/CwiseUnaryOp.h index 5fe2293e2..2943f5826 100644 --- a/Eigen/src/Core/CwiseUnaryOp.h +++ b/Eigen/src/Core/CwiseUnaryOp.h @@ -61,13 +61,11 @@ class CwiseUnaryOp : ei_no_assignment_operator, EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseUnaryOp) - typedef typename MatrixType::AsArg MatRef; - - CwiseUnaryOp(const MatRef& mat, const UnaryOp& func = UnaryOp()) : m_matrix(mat), m_functor(func) {} + CwiseUnaryOp(const MatrixType& mat, const UnaryOp& func = UnaryOp()) + : m_matrix(mat), m_functor(func) {} private: - const CwiseUnaryOp& _asArg() const { return *this; } int _rows() const { return m_matrix.rows(); } int _cols() const { return m_matrix.cols(); } @@ -77,7 +75,7 @@ class CwiseUnaryOp : ei_no_assignment_operator, } protected: - const MatRef m_matrix; + const typename MatrixType::XprCopy m_matrix; const UnaryOp m_functor; }; @@ -106,7 +104,7 @@ template<typename Derived> const CwiseUnaryOp<ei_scalar_opposite_op,Derived> MatrixBase<Derived>::operator-() const { - return CwiseUnaryOp<ei_scalar_opposite_op,Derived>(asArg()); + return CwiseUnaryOp<ei_scalar_opposite_op, Derived>(derived()); } /** \returns an expression of the opposite of \c *this @@ -115,10 +113,9 @@ template<typename Derived> const CwiseUnaryOp<ei_scalar_abs_op,Derived> MatrixBase<Derived>::cwiseAbs() const { - return CwiseUnaryOp<ei_scalar_abs_op,Derived>(asArg()); + return CwiseUnaryOp<ei_scalar_abs_op,Derived>(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 @@ -134,10 +131,9 @@ template<typename CustomUnaryOp> const CwiseUnaryOp<CustomUnaryOp, Derived> MatrixBase<Derived>::cwise(const CustomUnaryOp& func) const { - return CwiseUnaryOp<CustomUnaryOp, Derived>(asArg(), func); + return CwiseUnaryOp<CustomUnaryOp, Derived>(derived(), func); } - /** \internal * \brief Template functor to compute the conjugate of a complex value * @@ -154,7 +150,7 @@ template<typename Derived> const CwiseUnaryOp<ei_scalar_conjugate_op, Derived> MatrixBase<Derived>::conjugate() const { - return CwiseUnaryOp<ei_scalar_conjugate_op, Derived>(asArg()); + return CwiseUnaryOp<ei_scalar_conjugate_op, Derived>(derived()); } /** \internal @@ -183,7 +179,7 @@ template<typename NewType> const CwiseUnaryOp<ei_scalar_cast_op<NewType>, Derived> MatrixBase<Derived>::cast() const { - return CwiseUnaryOp<ei_scalar_cast_op<NewType>, Derived>(asArg()); + return CwiseUnaryOp<ei_scalar_cast_op<NewType>, Derived>(derived()); } /** \internal @@ -203,7 +199,8 @@ template<typename Derived> const CwiseUnaryOp<ei_scalar_multiple_op<typename ei_traits<Derived>::Scalar>, Derived> MatrixBase<Derived>::operator*(const Scalar& scalar) const { - return CwiseUnaryOp<ei_scalar_multiple_op<Scalar>, Derived>(asArg(), ei_scalar_multiple_op<Scalar>(scalar)); + return CwiseUnaryOp<ei_scalar_multiple_op<Scalar>, Derived> + (derived(), ei_scalar_multiple_op<Scalar>(scalar)); } /** \relates MatrixBase \sa class ei_scalar_multiple_op */ @@ -213,7 +210,7 @@ MatrixBase<Derived>::operator/(const Scalar& scalar) const { assert(NumTraits<Scalar>::HasFloatingPoint); return CwiseUnaryOp<ei_scalar_multiple_op<Scalar>, Derived> - (asArg(), ei_scalar_multiple_op<Scalar>(static_cast<Scalar>(1) / scalar)); + (derived(), ei_scalar_multiple_op<Scalar>(static_cast<Scalar>(1) / scalar)); } /** \sa ei_scalar_multiple_op */ diff --git a/Eigen/src/Core/DiagonalCoeffs.h b/Eigen/src/Core/DiagonalCoeffs.h index 0eea3f93b..47d24fea4 100644 --- a/Eigen/src/Core/DiagonalCoeffs.h +++ b/Eigen/src/Core/DiagonalCoeffs.h @@ -60,21 +60,18 @@ template<typename MatrixType> class DiagonalCoeffs EIGEN_GENERIC_PUBLIC_INTERFACE(DiagonalCoeffs) - typedef typename MatrixType::AsArg MatRef; - - DiagonalCoeffs(const MatRef& matrix) : m_matrix(matrix) {} + DiagonalCoeffs(const MatrixType& matrix) : m_matrix(matrix) {} EIGEN_INHERIT_ASSIGNMENT_OPERATORS(DiagonalCoeffs) private: - const DiagonalCoeffs& _asArg() const { return *this; } int _rows() const { return std::min(m_matrix.rows(), m_matrix.cols()); } int _cols() const { return 1; } Scalar& _coeffRef(int row, int) { - return m_matrix.coeffRef(row, row); + return m_matrix.const_cast_derived().coeffRef(row, row); } Scalar _coeff(int row, int) const @@ -83,7 +80,8 @@ template<typename MatrixType> class DiagonalCoeffs } protected: - MatRef m_matrix; + + const typename MatrixType::XprCopy m_matrix; }; /** \returns an expression of the main diagonal of *this, which must be a square matrix. @@ -96,7 +94,7 @@ template<typename Derived> DiagonalCoeffs<Derived> MatrixBase<Derived>::diagonal() { - return DiagonalCoeffs<Derived>(asArg()); + return DiagonalCoeffs<Derived>(derived()); } /** This is the const version of diagonal(). */ @@ -104,7 +102,7 @@ template<typename Derived> const DiagonalCoeffs<Derived> MatrixBase<Derived>::diagonal() const { - return DiagonalCoeffs<Derived>(asArg()); + return DiagonalCoeffs<Derived>(derived()); } #endif // EIGEN_DIAGONALCOEFFS_H diff --git a/Eigen/src/Core/DiagonalMatrix.h b/Eigen/src/Core/DiagonalMatrix.h index fc381a048..79fa562d9 100644 --- a/Eigen/src/Core/DiagonalMatrix.h +++ b/Eigen/src/Core/DiagonalMatrix.h @@ -58,9 +58,7 @@ class DiagonalMatrix : ei_no_assignment_operator, EIGEN_GENERIC_PUBLIC_INTERFACE(DiagonalMatrix) - typedef typename CoeffsVectorType::AsArg CoeffsVecRef; - - DiagonalMatrix(const CoeffsVecRef& coeffs) : m_coeffs(coeffs) + DiagonalMatrix(const CoeffsVectorType& coeffs) : m_coeffs(coeffs) { assert(CoeffsVectorType::IsVectorAtCompileTime && coeffs.size() > 0); @@ -68,7 +66,6 @@ class DiagonalMatrix : ei_no_assignment_operator, private: - const DiagonalMatrix& _asArg() const { return *this; } int _rows() const { return m_coeffs.size(); } int _cols() const { return m_coeffs.size(); } @@ -78,7 +75,7 @@ class DiagonalMatrix : ei_no_assignment_operator, } protected: - const CoeffsVecRef m_coeffs; + const typename CoeffsVectorType::XprCopy m_coeffs; }; /** \returns an expression of a diagonal matrix with *this as vector of diagonal coefficients @@ -94,7 +91,7 @@ template<typename Derived> const DiagonalMatrix<Derived> MatrixBase<Derived>::asDiagonal() const { - return DiagonalMatrix<Derived>(asArg()); + return DiagonalMatrix<Derived>(derived()); } /** \returns true if *this is approximately equal to a diagonal matrix, diff --git a/Eigen/src/Core/ForwardDeclarations.h b/Eigen/src/Core/ForwardDeclarations.h index 3459eab5b..114362784 100644 --- a/Eigen/src/Core/ForwardDeclarations.h +++ b/Eigen/src/Core/ForwardDeclarations.h @@ -56,15 +56,15 @@ struct ei_scalar_abs_op; template<typename NewType> struct ei_scalar_cast_op; template<typename Scalar> struct ei_scalar_multiple_op; -template<typename T> struct Reference +template<typename T> struct ei_xpr_copy { typedef T Type; }; template<typename _Scalar, int _Rows, int _Cols, int _StorageOrder, int _MaxRows, int _MaxCols> -struct Reference<Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols> > +struct ei_xpr_copy<Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols> > { - typedef MatrixRef<Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols> > Type; + typedef const Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols> & Type; }; #endif // EIGEN_FORWARDDECLARATIONS_H diff --git a/Eigen/src/Core/Identity.h b/Eigen/src/Core/Identity.h index 2598402b2..129786e4b 100644 --- a/Eigen/src/Core/Identity.h +++ b/Eigen/src/Core/Identity.h @@ -60,7 +60,6 @@ template<typename MatrixType> class Identity : ei_no_assignment_operator, private: - const Identity& _asArg() const { return *this; } int _rows() const { return m_rows.value(); } int _cols() const { return m_cols.value(); } @@ -70,6 +69,7 @@ template<typename MatrixType> class Identity : ei_no_assignment_operator, } protected: + const ei_int_if_dynamic<RowsAtCompileTime> m_rows; const ei_int_if_dynamic<ColsAtCompileTime> m_cols; }; diff --git a/Eigen/src/Core/Map.h b/Eigen/src/Core/Map.h index ece50087c..d0f9cd940 100644 --- a/Eigen/src/Core/Map.h +++ b/Eigen/src/Core/Map.h @@ -59,7 +59,6 @@ template<typename MatrixType> class Map private: - const Map& _asArg() const { return *this; } int _rows() const { return m_rows; } int _cols() const { return m_cols; } diff --git a/Eigen/src/Core/Matrix.h b/Eigen/src/Core/Matrix.h index 112f5f79e..2102ce484 100644 --- a/Eigen/src/Core/Matrix.h +++ b/Eigen/src/Core/Matrix.h @@ -97,14 +97,10 @@ class Matrix : public MatrixBase<Matrix<_Scalar, _Rows, _Cols, friend class Map<Matrix>; - typedef MatrixRef<Matrix> AsArg; - friend class MatrixRef<Matrix>; - private: ei_matrix_storage<Scalar, MaxSizeAtCompileTime, RowsAtCompileTime, ColsAtCompileTime> m_storage; - AsArg _asArg() const { return AsArg(*this); } int _rows() const { return m_storage.rows(); } int _cols() const { return m_storage.cols(); } diff --git a/Eigen/src/Core/MatrixBase.h b/Eigen/src/Core/MatrixBase.h index f89d861ea..d5f8decee 100644 --- a/Eigen/src/Core/MatrixBase.h +++ b/Eigen/src/Core/MatrixBase.h @@ -57,6 +57,12 @@ template<typename Derived> class MatrixBase typedef typename ei_traits<Derived>::Scalar Scalar; + const Derived& derived() const { return *static_cast<const Derived*>(this); } + Derived& derived() { return *static_cast<Derived*>(this); } + Derived& const_cast_derived() const + { return *static_cast<Derived*>(const_cast<MatrixBase*>(this)); } + + /** The number of rows at compile-time. This is just a copy of the value provided * by the \a Derived type. If a value is not known at compile-time, * it is set to the \a Dynamic constant. @@ -125,15 +131,6 @@ template<typename Derived> class MatrixBase = ei_traits<Derived>::RowsAtCompileTime == 1 || ei_traits<Derived>::ColsAtCompileTime == 1 }; - /** This is the "reference type" used to pass objects of type MatrixBase as arguments - * to functions. If this MatrixBase type represents an expression, then \a AsArg - * is just this MatrixBase type itself, i.e. expressions are just passed by value - * and the compiler is usually clever enough to optimize that. If, on the - * other hand, this MatrixBase type is an actual matrix or vector type, then \a AsArg is - * a typedef to MatrixRef, which works as a reference, so that matrices and vectors - * are passed by reference, not by value. \sa asArg()*/ - typedef typename Reference<Derived>::Type AsArg; - /** This is the "real scalar" type; if the \a Scalar type is already real numbers * (e.g. int, float or double) then \a RealScalar is just the same as \a Scalar. If * \a Scalar is \a std::complex<T> then RealScalar is \a T. @@ -161,10 +158,6 @@ template<typename Derived> class MatrixBase bool isVector() const { return rows()==1 || cols()==1; } //@} - /** \returns a AsArg to *this. \sa AsArg */ - AsArg asArg() const - { return static_cast<const Derived *>(this)->_asArg(); } - /** Copies \a other into *this. \returns a reference to *this. */ template<typename OtherDerived> Derived& operator=(const MatrixBase<OtherDerived>& other); diff --git a/Eigen/src/Core/MatrixRef.h b/Eigen/src/Core/MatrixRef.h deleted file mode 100644 index 2a5a1a514..000000000 --- a/Eigen/src/Core/MatrixRef.h +++ /dev/null @@ -1,72 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. Eigen itself is part of the KDE project. -// -// Copyright (C) 2006-2008 Benoit Jacob <jacob@math.jussieu.fr> -// -// 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 <http://www.gnu.org/licenses/>. - -#ifndef EIGEN_MATRIXREF_H -#define EIGEN_MATRIXREF_H - -template<typename MatrixType> -struct ei_traits<MatrixRef<MatrixType> > -{ - typedef typename MatrixType::Scalar Scalar; - enum { - RowsAtCompileTime = MatrixType::RowsAtCompileTime, - ColsAtCompileTime = MatrixType::ColsAtCompileTime, - MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime, - MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime - }; -}; - -template<typename MatrixType> class MatrixRef - : public MatrixBase<MatrixRef<MatrixType> > -{ - public: - - EIGEN_GENERIC_PUBLIC_INTERFACE(MatrixRef) - - MatrixRef(const MatrixType& matrix) : m_matrix(matrix) {} - ~MatrixRef() {} - - EIGEN_INHERIT_ASSIGNMENT_OPERATORS(MatrixRef) - - private: - - MatrixRef _asArg() const { return *this; } - int _rows() const { return m_matrix.rows(); } - int _cols() const { return m_matrix.cols(); } - - const Scalar& _coeff(int row, int col) const - { - return m_matrix._coeff(row, col); - } - - Scalar& _coeffRef(int row, int col) - { - return const_cast<MatrixType*>(&m_matrix)->_coeffRef(row, col); - } - - protected: - const MatrixType& m_matrix; -}; - -#endif // EIGEN_MATRIXREF_H diff --git a/Eigen/src/Core/Minor.h b/Eigen/src/Core/Minor.h index fbd6224aa..6c755bb74 100644 --- a/Eigen/src/Core/Minor.h +++ b/Eigen/src/Core/Minor.h @@ -60,9 +60,7 @@ template<typename MatrixType> class Minor EIGEN_GENERIC_PUBLIC_INTERFACE(Minor) - typedef typename MatrixType::AsArg MatRef; - - Minor(const MatRef& matrix, + Minor(const MatrixType& matrix, int row, int col) : m_matrix(matrix), m_row(row), m_col(col) { @@ -74,13 +72,12 @@ template<typename MatrixType> class Minor private: - const Minor& _asArg() const { return *this; } int _rows() const { return m_matrix.rows() - 1; } int _cols() const { return m_matrix.cols() - 1; } Scalar& _coeffRef(int row, int col) { - return m_matrix.coeffRef(row + (row >= m_row), col + (col >= m_col)); + return m_matrix.const_cast_derived().coeffRef(row + (row >= m_row), col + (col >= m_col)); } Scalar _coeff(int row, int col) const @@ -89,7 +86,7 @@ template<typename MatrixType> class Minor } protected: - MatRef m_matrix; + const typename MatrixType::XprCopy m_matrix; const int m_row, m_col; }; @@ -106,7 +103,7 @@ template<typename Derived> Minor<Derived> MatrixBase<Derived>::minor(int row, int col) { - return Minor<Derived>(asArg(), row, col); + return Minor<Derived>(derived(), row, col); } /** This is the const version of minor(). */ @@ -114,7 +111,7 @@ template<typename Derived> const Minor<Derived> MatrixBase<Derived>::minor(int row, int col) const { - return Minor<Derived>(asArg(), row, col); + return Minor<Derived>(derived(), row, col); } #endif // EIGEN_MINOR_H diff --git a/Eigen/src/Core/Ones.h b/Eigen/src/Core/Ones.h index 836887c43..15ecc04e0 100644 --- a/Eigen/src/Core/Ones.h +++ b/Eigen/src/Core/Ones.h @@ -53,7 +53,6 @@ template<typename MatrixType> class Ones : ei_no_assignment_operator, private: - const Ones& _asArg() const { return *this; } int _rows() const { return m_rows.value(); } int _cols() const { return m_cols.value(); } diff --git a/Eigen/src/Core/Product.h b/Eigen/src/Core/Product.h index 68f6da97f..cbc60f1ed 100644 --- a/Eigen/src/Core/Product.h +++ b/Eigen/src/Core/Product.h @@ -91,10 +91,7 @@ template<typename Lhs, typename Rhs> class Product : ei_no_assignment_operator, EIGEN_GENERIC_PUBLIC_INTERFACE(Product) - typedef typename Lhs::AsArg LhsRef; - typedef typename Rhs::AsArg RhsRef; - - Product(const LhsRef& lhs, const RhsRef& rhs) + Product(const Lhs& lhs, const Rhs& rhs) : m_lhs(lhs), m_rhs(rhs) { assert(lhs.cols() == rhs.rows()); @@ -102,7 +99,6 @@ template<typename Lhs, typename Rhs> class Product : ei_no_assignment_operator, private: - const Product& _asArg() const { return *this; } int _rows() const { return m_lhs.rows(); } int _cols() const { return m_rhs.cols(); } @@ -113,8 +109,9 @@ template<typename Lhs, typename Rhs> class Product : ei_no_assignment_operator, && Lhs::ColsAtCompileTime != Dynamic && Lhs::ColsAtCompileTime <= EIGEN_UNROLLING_LIMIT) ei_product_unroller<Lhs::ColsAtCompileTime-1, - Lhs::ColsAtCompileTime <= EIGEN_UNROLLING_LIMIT ? Lhs::ColsAtCompileTime : Dynamic, - LhsRef, RhsRef> + Lhs::ColsAtCompileTime <= EIGEN_UNROLLING_LIMIT + ? Lhs::ColsAtCompileTime : Dynamic, + Lhs, Rhs> ::run(row, col, m_lhs, m_rhs, res); else { @@ -126,8 +123,8 @@ template<typename Lhs, typename Rhs> class Product : ei_no_assignment_operator, } protected: - const LhsRef m_lhs; - const RhsRef m_rhs; + const typename Lhs::XprCopy m_lhs; + const typename Rhs::XprCopy m_rhs; }; /** \returns an expression of the matrix product of \c this and \a other, in this order. @@ -144,7 +141,7 @@ template<typename OtherDerived> const Product<Derived, OtherDerived> MatrixBase<Derived>::lazyProduct(const MatrixBase<OtherDerived> &other) const { - return Product<Derived, OtherDerived>(asArg(), other.asArg()); + return Product<Derived, OtherDerived>(derived(), other.derived()); } /** \relates MatrixBase diff --git a/Eigen/src/Core/Random.h b/Eigen/src/Core/Random.h index e560a708d..188f7513a 100644 --- a/Eigen/src/Core/Random.h +++ b/Eigen/src/Core/Random.h @@ -51,7 +51,8 @@ template<typename MatrixType> class Random : ei_no_assignment_operator, EIGEN_GENERIC_PUBLIC_INTERFACE(Random) - const Random& _asArg() const { return *this; } + private: + int _rows() const { return m_rows.value(); } int _cols() const { return m_cols.value(); } @@ -61,6 +62,7 @@ template<typename MatrixType> class Random : ei_no_assignment_operator, } public: + Random(int rows, int cols) : m_rows(rows), m_cols(cols) { assert(rows > 0 diff --git a/Eigen/src/Core/Transpose.h b/Eigen/src/Core/Transpose.h index d6613989e..2f1b54d99 100644 --- a/Eigen/src/Core/Transpose.h +++ b/Eigen/src/Core/Transpose.h @@ -56,21 +56,18 @@ template<typename MatrixType> class Transpose EIGEN_GENERIC_PUBLIC_INTERFACE(Transpose) - typedef typename MatrixType::AsArg MatRef; - - Transpose(const MatRef& matrix) : m_matrix(matrix) {} + Transpose(const MatrixType& matrix) : m_matrix(matrix) {} EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Transpose) private: - const Transpose& _asArg() const { return *this; } int _rows() const { return m_matrix.cols(); } int _cols() const { return m_matrix.rows(); } Scalar& _coeffRef(int row, int col) { - return m_matrix.coeffRef(col, row); + return m_matrix.const_cast_derived().coeffRef(col, row); } Scalar _coeff(int row, int col) const @@ -79,7 +76,7 @@ template<typename MatrixType> class Transpose } protected: - MatRef m_matrix; + const typename MatrixType::XprCopy m_matrix; }; /** \returns an expression of the transpose of *this. @@ -92,7 +89,7 @@ template<typename Derived> Transpose<Derived> MatrixBase<Derived>::transpose() { - return Transpose<Derived>(asArg()); + return Transpose<Derived>(derived()); } /** This is the const version of transpose(). \sa adjoint() */ @@ -100,7 +97,7 @@ template<typename Derived> const Transpose<Derived> MatrixBase<Derived>::transpose() const { - return Transpose<Derived>(asArg()); + return Transpose<Derived>(derived()); } /** \returns an expression of the adjoint (i.e. conjugate transpose) of *this. diff --git a/Eigen/src/Core/Util.h b/Eigen/src/Core/Util.h index 3c970d6e8..71a8294f6 100644 --- a/Eigen/src/Core/Util.h +++ b/Eigen/src/Core/Util.h @@ -105,7 +105,8 @@ using Base::MaxRowsAtCompileTime; \ using Base::MaxColsAtCompileTime; \ using Base::SizeAtCompileTime; \ using Base::MaxSizeAtCompileTime; \ -using Base::IsVectorAtCompileTime; +using Base::IsVectorAtCompileTime; \ +typedef typename ei_xpr_copy<Derived>::Type XprCopy; #define EIGEN_GENERIC_PUBLIC_INTERFACE(Derived) \ _EIGEN_GENERIC_PUBLIC_INTERFACE(Derived, MatrixBase<Derived>) \ diff --git a/Eigen/src/Core/Zero.h b/Eigen/src/Core/Zero.h index 3c9fbf533..97bb8b9e9 100644 --- a/Eigen/src/Core/Zero.h +++ b/Eigen/src/Core/Zero.h @@ -53,7 +53,6 @@ template<typename MatrixType> class Zero : ei_no_assignment_operator, private: - const Zero& _asArg() const { return *this; } int _rows() const { return m_rows.value(); } int _cols() const { return m_cols.value(); } diff --git a/bench/benchmark.cpp b/bench/benchmark.cpp index 0d95a5043..ee58607cd 100644 --- a/bench/benchmark.cpp +++ b/bench/benchmark.cpp @@ -1,6 +1,4 @@ // g++ -O3 -DNDEBUG -DMATSIZE=<x> benchmark.cpp -o benchmark && time ./benchmark -#include <cstdlib> -#include <cmath> #include <Eigen/Core> #ifndef MATSIZE diff --git a/doc/examples/class_Block.cpp b/doc/examples/class_Block.cpp index 7a4c60a42..fd5ae816c 100644 --- a/doc/examples/class_Block.cpp +++ b/doc/examples/class_Block.cpp @@ -6,14 +6,14 @@ template<typename Derived> Eigen::Block<Derived> topLeftCorner(MatrixBase<Derived>& m, int rows, int cols) { - return Eigen::Block<Derived>(m.asArg(), 0, 0, rows, cols); + return Eigen::Block<Derived>(m, 0, 0, rows, cols); } template<typename Derived> const Eigen::Block<Derived> topLeftCorner(const MatrixBase<Derived>& m, int rows, int cols) { - return Eigen::Block<Derived>(m.asArg(), 0, 0, rows, cols); + return Eigen::Block<Derived>(m, 0, 0, rows, cols); } int main(int, char**) diff --git a/doc/examples/class_Column.cpp b/doc/examples/class_Column.cpp index fbaaa7a87..1394324fa 100644 --- a/doc/examples/class_Column.cpp +++ b/doc/examples/class_Column.cpp @@ -6,14 +6,14 @@ template<typename Derived> Eigen::Block<Derived,Derived::RowsAtCompileTime,1> firstColumn(MatrixBase<Derived>& m) { - return typename Eigen::Block<Derived,Derived::RowsAtCompileTime,1>(m.asArg(), 0); + return typename Eigen::Block<Derived,Derived::RowsAtCompileTime,1>(m, 0); } template<typename Derived> const Eigen::Block<Derived,Derived::RowsAtCompileTime,1> firstColumn(const MatrixBase<Derived>& m) { - return typename Eigen::Block<Derived,Derived::RowsAtCompileTime,1>(m.asArg(), 0); + return typename Eigen::Block<Derived,Derived::RowsAtCompileTime,1>(m, 0); } int main(int, char**) diff --git a/doc/examples/class_CwiseBinaryOp.cpp b/doc/examples/class_CwiseBinaryOp.cpp index ae634a041..8e4c5361e 100644 --- a/doc/examples/class_CwiseBinaryOp.cpp +++ b/doc/examples/class_CwiseBinaryOp.cpp @@ -13,7 +13,7 @@ template<typename Derived1, typename Derived2> const Eigen::CwiseBinaryOp<CwiseMinOp, Derived1, Derived2> cwiseMin(const MatrixBase<Derived1> &mat1, const MatrixBase<Derived2> &mat2) { - return Eigen::CwiseBinaryOp<CwiseMinOp, Derived1, Derived2>(mat1.asArg(), mat2.asArg()); + return Eigen::CwiseBinaryOp<CwiseMinOp, Derived1, Derived2>(mat1, mat2); } int main(int, char**) diff --git a/doc/examples/class_FixedBlock.cpp b/doc/examples/class_FixedBlock.cpp index b643d1148..644f420bd 100644 --- a/doc/examples/class_FixedBlock.cpp +++ b/doc/examples/class_FixedBlock.cpp @@ -6,14 +6,14 @@ template<typename Derived> Eigen::Block<Derived, 2, 2> topLeft2x2Corner(MatrixBase<Derived>& m) { - return Eigen::Block<Derived, 2, 2>(m.asArg(), 0, 0); + return Eigen::Block<Derived, 2, 2>(m, 0, 0); } template<typename Derived> const Eigen::Block<Derived, 2, 2> topLeft2x2Corner(const MatrixBase<Derived>& m) { - return Eigen::Block<Derived, 2, 2>(m.asArg(), 0, 0); + return Eigen::Block<Derived, 2, 2>(m, 0, 0); } int main(int, char**) diff --git a/doc/examples/class_Row.cpp b/doc/examples/class_Row.cpp index 5138b2e7c..eed1dbdb4 100644 --- a/doc/examples/class_Row.cpp +++ b/doc/examples/class_Row.cpp @@ -6,14 +6,14 @@ template<typename Derived> Eigen::Block<Derived,1,Derived::ColsAtCompileTime> firstRow(MatrixBase<Derived>& m) { - return Eigen::Block<Derived,1,Derived::ColsAtCompileTime>(m.asArg(), 0); + return Eigen::Block<Derived,1,Derived::ColsAtCompileTime>(m, 0); } template<typename Derived> const Eigen::Block<Derived,1,Derived::ColsAtCompileTime> firstRow(const MatrixBase<Derived>& m) { - return Eigen::Block<Derived,1,Derived::ColsAtCompileTime>(m.asArg(), 0); + return Eigen::Block<Derived,1,Derived::ColsAtCompileTime>(m, 0); } int main(int, char**) |