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 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 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 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 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 class Block protected: - MatRef m_matrix; + const typename MatrixType::XprCopy m_matrix; ei_int_if_dynamic m_startRow; ei_int_if_dynamic m_startCol; ei_int_if_dynamic m_blockRows; @@ -168,7 +166,7 @@ template Block MatrixBase ::block(int startRow, int startCol, int blockRows, int blockCols) { - return Block(asArg(), startRow, startCol, blockRows, blockCols); + return Block(derived(), startRow, startCol, blockRows, blockCols); } /** This is the const version of block(int,int,int,int). */ @@ -176,7 +174,7 @@ template const Block MatrixBase ::block(int startRow, int startCol, int blockRows, int blockCols) const { - return Block(asArg(), startRow, startCol, blockRows, blockCols); + return Block(derived(), startRow, startCol, blockRows, blockCols); } /** \returns a dynamic-size expression of a block in *this. @@ -200,10 +198,10 @@ Block MatrixBase ::block(int start, int size) { assert(IsVectorAtCompileTime); - return Block(asArg(), RowsAtCompileTime == 1 ? 0 : start, - ColsAtCompileTime == 1 ? 0 : start, - RowsAtCompileTime == 1 ? 1 : size, - ColsAtCompileTime == 1 ? 1 : size); + return Block(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 MatrixBase ::block(int start, int size) const { assert(IsVectorAtCompileTime); - return Block(asArg(), RowsAtCompileTime == 1 ? 0 : start, - ColsAtCompileTime == 1 ? 0 : start, - RowsAtCompileTime == 1 ? 1 : size, - ColsAtCompileTime == 1 ? 1 : size); + return Block(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 MatrixBase ::start(int size) { assert(IsVectorAtCompileTime); - return Block(asArg(), 0, 0, + return Block(derived(), 0, 0, RowsAtCompileTime == 1 ? 1 : size, ColsAtCompileTime == 1 ? 1 : size); } @@ -249,7 +247,7 @@ const Block MatrixBase ::start(int size) const { assert(IsVectorAtCompileTime); - return Block(asArg(), 0, 0, + return Block(derived(), 0, 0, RowsAtCompileTime == 1 ? 1 : size, ColsAtCompileTime == 1 ? 1 : size); } @@ -274,7 +272,7 @@ Block MatrixBase ::end(int size) { assert(IsVectorAtCompileTime); - return Block(asArg(), + return Block(derived(), RowsAtCompileTime == 1 ? 0 : rows() - size, ColsAtCompileTime == 1 ? 0 : cols() - size, RowsAtCompileTime == 1 ? 1 : size, @@ -287,7 +285,7 @@ const Block MatrixBase ::end(int size) const { assert(IsVectorAtCompileTime); - return Block(asArg(), + return Block(derived(), RowsAtCompileTime == 1 ? 0 : rows() - size, ColsAtCompileTime == 1 ? 0 : cols() - size, RowsAtCompileTime == 1 ? 1 : size, @@ -315,13 +313,13 @@ Block MatrixBase ::corner(CornerType type, int cRows, int cCols) { if(type == TopLeft) - return Block(asArg(), 0, 0, cRows, cCols); + return Block(derived(), 0, 0, cRows, cCols); else if(type == TopRight) - return Block(asArg(), 0, cols() - cCols, cRows, cCols); + return Block(derived(), 0, cols() - cCols, cRows, cCols); else if(type == BottomLeft) - return Block(asArg(), rows() - cRows, 0, cRows, cCols); + return Block(derived(), rows() - cRows, 0, cRows, cCols); else - return Block(asArg(), rows() - cRows, cols() - cCols, cRows, cCols); + return Block(derived(), rows() - cRows, cols() - cCols, cRows, cCols); } /** This is the const version of corner(CornerType, int, int).*/ @@ -330,13 +328,13 @@ const Block MatrixBase ::corner(CornerType type, int cRows, int cCols) const { if(type == TopLeft) - return Block(asArg(), 0, 0, cRows, cCols); + return Block(derived(), 0, 0, cRows, cCols); else if(type == TopRight) - return Block(asArg(), 0, cols() - cCols, cRows, cCols); + return Block(derived(), 0, cols() - cCols, cRows, cCols); else if(type == BottomLeft) - return Block(asArg(), rows() - cRows, 0, cRows, cCols); + return Block(derived(), rows() - cRows, 0, cRows, cCols); else - return Block(asArg(), rows() - cRows, cols() - cCols, cRows, cCols); + return Block(derived(), rows() - cRows, cols() - cCols, cRows, cCols); } /** \returns a fixed-size expression of a block in *this. @@ -360,7 +358,7 @@ template Block MatrixBase ::block(int startRow, int startCol) { - return Block(asArg(), startRow, startCol); + return Block(derived(), startRow, startCol); } /** This is the const version of block<>(int, int). */ @@ -369,7 +367,7 @@ template const Block MatrixBase ::block(int startRow, int startCol) const { - return Block(asArg(), startRow, startCol); + return Block(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 Block::RowsAtCompileTime, 1> MatrixBase::col(int i) { - return Block::RowsAtCompileTime, 1>(asArg(), i); + return Block::RowsAtCompileTime, 1>(derived(), i); } /** This is the const version of col(). */ @@ -390,7 +388,7 @@ template const Block::RowsAtCompileTime, 1> MatrixBase::col(int i) const { - return Block::RowsAtCompileTime, 1>(asArg(), i); + return Block::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 Block::ColsAtCompileTime> MatrixBase::row(int i) { - return Block::ColsAtCompileTime>(asArg(), i); + return Block::ColsAtCompileTime>(derived(), i); } /** This is the const version of row(). */ @@ -411,7 +409,7 @@ template const Block::ColsAtCompileTime> MatrixBase::row(int i) const { - return Block::ColsAtCompileTime>(asArg(), i); + return Block::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::Scalar MatrixBase { eigen_internal_assert(row >= 0 && row < rows() && col >= 0 && col < cols()); - return static_cast(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::Scalar MatrixBase { assert(row >= 0 && row < rows() && col >= 0 && col < cols()); - return static_cast(this)->_coeff(row, col); + return derived()._coeff(row, col); } /** Short version: don't use this function, use @@ -81,7 +81,7 @@ typename ei_traits::Scalar& MatrixBase { eigen_internal_assert(row >= 0 && row < rows() && col >= 0 && col < cols()); - return static_cast(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::Scalar& MatrixBase { assert(row >= 0 && row < rows() && col >= 0 && col < cols()); - return static_cast(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 const CwiseBinaryOp operator-(const MatrixBase &mat1, const MatrixBase &mat2) { - return CwiseBinaryOp(mat1.asArg(), mat2.asArg()); + return CwiseBinaryOp(mat1.derived(), mat2.derived()); } /** replaces \c *this by \c *this - \a other. @@ -168,7 +164,7 @@ template const CwiseBinaryOp operator+(const MatrixBase &mat1, const MatrixBase &mat2) { - return CwiseBinaryOp(mat1.asArg(), mat2.asArg()); + return CwiseBinaryOp(mat1.derived(), mat2.derived()); } /** replaces \c *this by \c *this + \a other. @@ -192,7 +188,7 @@ template const CwiseBinaryOp MatrixBase::cwiseProduct(const MatrixBase &other) const { - return CwiseBinaryOp(asArg(), other.asArg()); + return CwiseBinaryOp(derived(), other.derived()); } /** \returns an expression of the coefficient-wise quotient of *this and \a other @@ -204,7 +200,7 @@ template const CwiseBinaryOp MatrixBase::cwiseQuotient(const MatrixBase &other) const { - return CwiseBinaryOp(asArg(), other.asArg()); + return CwiseBinaryOp(derived(), other.derived()); } /** \returns an expression of a custom coefficient-wise operator \a func of *this and \a other @@ -219,7 +215,7 @@ template const CwiseBinaryOp MatrixBase::cwise(const MatrixBase &other, const CustomBinaryOp& func) const { - return CwiseBinaryOp(asArg(), other.asArg(), func); + return CwiseBinaryOp(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 const CwiseUnaryOp MatrixBase::operator-() const { - return CwiseUnaryOp(asArg()); + return CwiseUnaryOp(derived()); } /** \returns an expression of the opposite of \c *this @@ -115,10 +113,9 @@ template const CwiseUnaryOp MatrixBase::cwiseAbs() const { - return CwiseUnaryOp(asArg()); + return CwiseUnaryOp(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 const CwiseUnaryOp MatrixBase::cwise(const CustomUnaryOp& func) const { - return CwiseUnaryOp(asArg(), func); + return CwiseUnaryOp(derived(), func); } - /** \internal * \brief Template functor to compute the conjugate of a complex value * @@ -154,7 +150,7 @@ template const CwiseUnaryOp MatrixBase::conjugate() const { - return CwiseUnaryOp(asArg()); + return CwiseUnaryOp(derived()); } /** \internal @@ -183,7 +179,7 @@ template const CwiseUnaryOp, Derived> MatrixBase::cast() const { - return CwiseUnaryOp, Derived>(asArg()); + return CwiseUnaryOp, Derived>(derived()); } /** \internal @@ -203,7 +199,8 @@ template const CwiseUnaryOp::Scalar>, Derived> MatrixBase::operator*(const Scalar& scalar) const { - return CwiseUnaryOp, Derived>(asArg(), ei_scalar_multiple_op(scalar)); + return CwiseUnaryOp, Derived> + (derived(), ei_scalar_multiple_op(scalar)); } /** \relates MatrixBase \sa class ei_scalar_multiple_op */ @@ -213,7 +210,7 @@ MatrixBase::operator/(const Scalar& scalar) const { assert(NumTraits::HasFloatingPoint); return CwiseUnaryOp, Derived> - (asArg(), ei_scalar_multiple_op(static_cast(1) / scalar)); + (derived(), ei_scalar_multiple_op(static_cast(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 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 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 DiagonalCoeffs MatrixBase::diagonal() { - return DiagonalCoeffs(asArg()); + return DiagonalCoeffs(derived()); } /** This is the const version of diagonal(). */ @@ -104,7 +102,7 @@ template const DiagonalCoeffs MatrixBase::diagonal() const { - return DiagonalCoeffs(asArg()); + return DiagonalCoeffs(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 const DiagonalMatrix MatrixBase::asDiagonal() const { - return DiagonalMatrix(asArg()); + return DiagonalMatrix(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 struct ei_scalar_cast_op; template struct ei_scalar_multiple_op; -template struct Reference +template struct ei_xpr_copy { typedef T Type; }; template -struct Reference > +struct ei_xpr_copy > { - typedef MatrixRef > 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 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 class Identity : ei_no_assignment_operator, } protected: + const ei_int_if_dynamic m_rows; const ei_int_if_dynamic 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 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; - typedef MatrixRef AsArg; - friend class MatrixRef; - private: ei_matrix_storage 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 class MatrixBase typedef typename ei_traits::Scalar Scalar; + const Derived& derived() const { return *static_cast(this); } + Derived& derived() { return *static_cast(this); } + Derived& const_cast_derived() const + { return *static_cast(const_cast(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 class MatrixBase = ei_traits::RowsAtCompileTime == 1 || ei_traits::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::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 then RealScalar is \a T. @@ -161,10 +158,6 @@ template class MatrixBase bool isVector() const { return rows()==1 || cols()==1; } //@} - /** \returns a AsArg to *this. \sa AsArg */ - AsArg asArg() const - { return static_cast(this)->_asArg(); } - /** Copies \a other into *this. \returns a reference to *this. */ template Derived& operator=(const MatrixBase& 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 -// -// 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_MATRIXREF_H -#define EIGEN_MATRIXREF_H - -template -struct ei_traits > -{ - typedef typename MatrixType::Scalar Scalar; - enum { - RowsAtCompileTime = MatrixType::RowsAtCompileTime, - ColsAtCompileTime = MatrixType::ColsAtCompileTime, - MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime, - MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime - }; -}; - -template class MatrixRef - : public MatrixBase > -{ - 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(&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 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 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 class Minor } protected: - MatRef m_matrix; + const typename MatrixType::XprCopy m_matrix; const int m_row, m_col; }; @@ -106,7 +103,7 @@ template Minor MatrixBase::minor(int row, int col) { - return Minor(asArg(), row, col); + return Minor(derived(), row, col); } /** This is the const version of minor(). */ @@ -114,7 +111,7 @@ template const Minor MatrixBase::minor(int row, int col) const { - return Minor(asArg(), row, col); + return Minor(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 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 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 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 class Product : ei_no_assignment_operator, && Lhs::ColsAtCompileTime != Dynamic && Lhs::ColsAtCompileTime <= EIGEN_UNROLLING_LIMIT) ei_product_unroller + Lhs::ColsAtCompileTime <= EIGEN_UNROLLING_LIMIT + ? Lhs::ColsAtCompileTime : Dynamic, + Lhs, Rhs> ::run(row, col, m_lhs, m_rhs, res); else { @@ -126,8 +123,8 @@ template 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 const Product MatrixBase::lazyProduct(const MatrixBase &other) const { - return Product(asArg(), other.asArg()); + return Product(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 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 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 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 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 Transpose MatrixBase::transpose() { - return Transpose(asArg()); + return Transpose(derived()); } /** This is the const version of transpose(). \sa adjoint() */ @@ -100,7 +97,7 @@ template const Transpose MatrixBase::transpose() const { - return Transpose(asArg()); + return Transpose(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::Type XprCopy; #define EIGEN_GENERIC_PUBLIC_INTERFACE(Derived) \ _EIGEN_GENERIC_PUBLIC_INTERFACE(Derived, MatrixBase) \ 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 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= benchmark.cpp -o benchmark && time ./benchmark -#include -#include #include #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 Eigen::Block topLeftCorner(MatrixBase& m, int rows, int cols) { - return Eigen::Block(m.asArg(), 0, 0, rows, cols); + return Eigen::Block(m, 0, 0, rows, cols); } template const Eigen::Block topLeftCorner(const MatrixBase& m, int rows, int cols) { - return Eigen::Block(m.asArg(), 0, 0, rows, cols); + return Eigen::Block(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 Eigen::Block firstColumn(MatrixBase& m) { - return typename Eigen::Block(m.asArg(), 0); + return typename Eigen::Block(m, 0); } template const Eigen::Block firstColumn(const MatrixBase& m) { - return typename Eigen::Block(m.asArg(), 0); + return typename Eigen::Block(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 const Eigen::CwiseBinaryOp cwiseMin(const MatrixBase &mat1, const MatrixBase &mat2) { - return Eigen::CwiseBinaryOp(mat1.asArg(), mat2.asArg()); + return Eigen::CwiseBinaryOp(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 Eigen::Block topLeft2x2Corner(MatrixBase& m) { - return Eigen::Block(m.asArg(), 0, 0); + return Eigen::Block(m, 0, 0); } template const Eigen::Block topLeft2x2Corner(const MatrixBase& m) { - return Eigen::Block(m.asArg(), 0, 0); + return Eigen::Block(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 Eigen::Block firstRow(MatrixBase& m) { - return Eigen::Block(m.asArg(), 0); + return Eigen::Block(m, 0); } template const Eigen::Block firstRow(const MatrixBase& m) { - return Eigen::Block(m.asArg(), 0); + return Eigen::Block(m, 0); } int main(int, char**)