get rid of MatrixRef, simplifications.

This commit is contained in:
Benoit Jacob 2008-03-13 20:36:01 +00:00
parent 908a0fbab5
commit fe569b060c
26 changed files with 107 additions and 216 deletions

View File

@ -15,7 +15,6 @@ namespace Eigen {
#include "src/Core/MatrixBase.h" #include "src/Core/MatrixBase.h"
#include "src/Core/Coeffs.h" #include "src/Core/Coeffs.h"
#include "src/Core/OperatorEquals.h" #include "src/Core/OperatorEquals.h"
#include "src/Core/MatrixRef.h"
#include "src/Core/MatrixStorage.h" #include "src/Core/MatrixStorage.h"
#include "src/Core/Matrix.h" #include "src/Core/Matrix.h"
#include "src/Core/Eval.h" #include "src/Core/Eval.h"

View File

@ -77,11 +77,9 @@ template<typename MatrixType, int BlockRows, int BlockCols> class Block
EIGEN_GENERIC_PUBLIC_INTERFACE(Block) EIGEN_GENERIC_PUBLIC_INTERFACE(Block)
typedef typename MatrixType::AsArg MatRef;
/** Column or Row constructor /** Column or Row constructor
*/ */
Block(const MatRef& matrix, int i) Block(const MatrixType& matrix, int i)
: m_matrix(matrix), : m_matrix(matrix),
// It is a row if and only if BlockRows==1 and BlockCols==MatrixType::ColsAtCompileTime, // 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, // 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 /** 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) : m_matrix(matrix), m_startRow(startRow), m_startCol(startCol)
{ {
assert(RowsAtCompileTime!=Dynamic && RowsAtCompileTime!=Dynamic); assert(RowsAtCompileTime!=Dynamic && RowsAtCompileTime!=Dynamic);
@ -109,7 +107,7 @@ template<typename MatrixType, int BlockRows, int BlockCols> class Block
/** Dynamic-size constructor /** Dynamic-size constructor
*/ */
Block(const MatRef& matrix, Block(const MatrixType& matrix,
int startRow, int startCol, int startRow, int startCol,
int blockRows, int blockCols) int blockRows, int blockCols)
: m_matrix(matrix), m_startRow(startRow), m_startCol(startCol), : m_matrix(matrix), m_startRow(startRow), m_startCol(startCol),
@ -125,13 +123,13 @@ template<typename MatrixType, int BlockRows, int BlockCols> class Block
private: private:
const Block& _asArg() const { return *this; }
int _rows() const { return m_blockRows.value(); } int _rows() const { return m_blockRows.value(); }
int _cols() const { return m_blockCols.value(); } int _cols() const { return m_blockCols.value(); }
Scalar& _coeffRef(int row, int col) 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 Scalar _coeff(int row, int col) const
@ -141,7 +139,7 @@ template<typename MatrixType, int BlockRows, int BlockCols> class Block
protected: 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::RowsAtCompileTime == 1 ? 0 : Dynamic> m_startRow;
ei_int_if_dynamic<MatrixType::ColsAtCompileTime == 1 ? 0 : Dynamic> m_startCol; ei_int_if_dynamic<MatrixType::ColsAtCompileTime == 1 ? 0 : Dynamic> m_startCol;
ei_int_if_dynamic<RowsAtCompileTime> m_blockRows; ei_int_if_dynamic<RowsAtCompileTime> m_blockRows;
@ -168,7 +166,7 @@ template<typename Derived>
Block<Derived> MatrixBase<Derived> Block<Derived> MatrixBase<Derived>
::block(int startRow, int startCol, int blockRows, int blockCols) ::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). */ /** This is the const version of block(int,int,int,int). */
@ -176,7 +174,7 @@ template<typename Derived>
const Block<Derived> MatrixBase<Derived> const Block<Derived> MatrixBase<Derived>
::block(int startRow, int startCol, int blockRows, int blockCols) const ::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. /** \returns a dynamic-size expression of a block in *this.
@ -200,7 +198,7 @@ Block<Derived> MatrixBase<Derived>
::block(int start, int size) ::block(int start, int size)
{ {
assert(IsVectorAtCompileTime); assert(IsVectorAtCompileTime);
return Block<Derived>(asArg(), RowsAtCompileTime == 1 ? 0 : start, return Block<Derived>(derived(), RowsAtCompileTime == 1 ? 0 : start,
ColsAtCompileTime == 1 ? 0 : start, ColsAtCompileTime == 1 ? 0 : start,
RowsAtCompileTime == 1 ? 1 : size, RowsAtCompileTime == 1 ? 1 : size,
ColsAtCompileTime == 1 ? 1 : size); ColsAtCompileTime == 1 ? 1 : size);
@ -212,7 +210,7 @@ const Block<Derived> MatrixBase<Derived>
::block(int start, int size) const ::block(int start, int size) const
{ {
assert(IsVectorAtCompileTime); assert(IsVectorAtCompileTime);
return Block<Derived>(asArg(), RowsAtCompileTime == 1 ? 0 : start, return Block<Derived>(derived(), RowsAtCompileTime == 1 ? 0 : start,
ColsAtCompileTime == 1 ? 0 : start, ColsAtCompileTime == 1 ? 0 : start,
RowsAtCompileTime == 1 ? 1 : size, RowsAtCompileTime == 1 ? 1 : size,
ColsAtCompileTime == 1 ? 1 : size); ColsAtCompileTime == 1 ? 1 : size);
@ -238,7 +236,7 @@ Block<Derived> MatrixBase<Derived>
::start(int size) ::start(int size)
{ {
assert(IsVectorAtCompileTime); assert(IsVectorAtCompileTime);
return Block<Derived>(asArg(), 0, 0, return Block<Derived>(derived(), 0, 0,
RowsAtCompileTime == 1 ? 1 : size, RowsAtCompileTime == 1 ? 1 : size,
ColsAtCompileTime == 1 ? 1 : size); ColsAtCompileTime == 1 ? 1 : size);
} }
@ -249,7 +247,7 @@ const Block<Derived> MatrixBase<Derived>
::start(int size) const ::start(int size) const
{ {
assert(IsVectorAtCompileTime); assert(IsVectorAtCompileTime);
return Block<Derived>(asArg(), 0, 0, return Block<Derived>(derived(), 0, 0,
RowsAtCompileTime == 1 ? 1 : size, RowsAtCompileTime == 1 ? 1 : size,
ColsAtCompileTime == 1 ? 1 : size); ColsAtCompileTime == 1 ? 1 : size);
} }
@ -274,7 +272,7 @@ Block<Derived> MatrixBase<Derived>
::end(int size) ::end(int size)
{ {
assert(IsVectorAtCompileTime); assert(IsVectorAtCompileTime);
return Block<Derived>(asArg(), return Block<Derived>(derived(),
RowsAtCompileTime == 1 ? 0 : rows() - size, RowsAtCompileTime == 1 ? 0 : rows() - size,
ColsAtCompileTime == 1 ? 0 : cols() - size, ColsAtCompileTime == 1 ? 0 : cols() - size,
RowsAtCompileTime == 1 ? 1 : size, RowsAtCompileTime == 1 ? 1 : size,
@ -287,7 +285,7 @@ const Block<Derived> MatrixBase<Derived>
::end(int size) const ::end(int size) const
{ {
assert(IsVectorAtCompileTime); assert(IsVectorAtCompileTime);
return Block<Derived>(asArg(), return Block<Derived>(derived(),
RowsAtCompileTime == 1 ? 0 : rows() - size, RowsAtCompileTime == 1 ? 0 : rows() - size,
ColsAtCompileTime == 1 ? 0 : cols() - size, ColsAtCompileTime == 1 ? 0 : cols() - size,
RowsAtCompileTime == 1 ? 1 : size, RowsAtCompileTime == 1 ? 1 : size,
@ -315,13 +313,13 @@ Block<Derived> MatrixBase<Derived>
::corner(CornerType type, int cRows, int cCols) ::corner(CornerType type, int cRows, int cCols)
{ {
if(type == TopLeft) if(type == TopLeft)
return Block<Derived>(asArg(), 0, 0, cRows, cCols); return Block<Derived>(derived(), 0, 0, cRows, cCols);
else if(type == TopRight) 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) else if(type == BottomLeft)
return Block<Derived>(asArg(), rows() - cRows, 0, cRows, cCols); return Block<Derived>(derived(), rows() - cRows, 0, cRows, cCols);
else 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).*/ /** 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 ::corner(CornerType type, int cRows, int cCols) const
{ {
if(type == TopLeft) if(type == TopLeft)
return Block<Derived>(asArg(), 0, 0, cRows, cCols); return Block<Derived>(derived(), 0, 0, cRows, cCols);
else if(type == TopRight) 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) else if(type == BottomLeft)
return Block<Derived>(asArg(), rows() - cRows, 0, cRows, cCols); return Block<Derived>(derived(), rows() - cRows, 0, cRows, cCols);
else 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. /** \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<Derived, BlockRows, BlockCols> MatrixBase<Derived>
::block(int startRow, int startCol) ::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). */ /** 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> const Block<Derived, BlockRows, BlockCols> MatrixBase<Derived>
::block(int startRow, int startCol) const ::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. /** \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> Block<Derived, ei_traits<Derived>::RowsAtCompileTime, 1>
MatrixBase<Derived>::col(int i) 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(). */ /** This is the const version of col(). */
@ -390,7 +388,7 @@ template<typename Derived>
const Block<Derived, ei_traits<Derived>::RowsAtCompileTime, 1> const Block<Derived, ei_traits<Derived>::RowsAtCompileTime, 1>
MatrixBase<Derived>::col(int i) const 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. /** \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> Block<Derived, 1, ei_traits<Derived>::ColsAtCompileTime>
MatrixBase<Derived>::row(int i) 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(). */ /** This is the const version of row(). */
@ -411,7 +409,7 @@ template<typename Derived>
const Block<Derived, 1, ei_traits<Derived>::ColsAtCompileTime> const Block<Derived, 1, ei_traits<Derived>::ColsAtCompileTime>
MatrixBase<Derived>::row(int i) const 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 #endif // EIGEN_BLOCK_H

View File

@ -45,7 +45,7 @@ typename ei_traits<Derived>::Scalar MatrixBase<Derived>
{ {
eigen_internal_assert(row >= 0 && row < rows() eigen_internal_assert(row >= 0 && row < rows()
&& col >= 0 && col < cols()); && 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. /** \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() assert(row >= 0 && row < rows()
&& col >= 0 && col < cols()); && 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 /** 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() eigen_internal_assert(row >= 0 && row < rows()
&& col >= 0 && col < cols()); && 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. /** \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() assert(row >= 0 && row < rows()
&& col >= 0 && col < cols()); && 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 /** Short version: don't use this function, use

View File

@ -71,10 +71,7 @@ class CwiseBinaryOp : ei_no_assignment_operator,
EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseBinaryOp) EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseBinaryOp)
typedef typename Lhs::AsArg LhsRef; CwiseBinaryOp(const Lhs& lhs, const Rhs& rhs, const BinaryOp& func = BinaryOp())
typedef typename Rhs::AsArg RhsRef;
CwiseBinaryOp(const LhsRef& lhs, const RhsRef& rhs, const BinaryOp& func = BinaryOp())
: m_lhs(lhs), m_rhs(rhs), m_functor(func) : m_lhs(lhs), m_rhs(rhs), m_functor(func)
{ {
assert(lhs.rows() == rhs.rows() && lhs.cols() == rhs.cols()); assert(lhs.rows() == rhs.rows() && lhs.cols() == rhs.cols());
@ -82,7 +79,6 @@ class CwiseBinaryOp : ei_no_assignment_operator,
private: private:
const CwiseBinaryOp& _asArg() const { return *this; }
int _rows() const { return m_lhs.rows(); } int _rows() const { return m_lhs.rows(); }
int _cols() const { return m_lhs.cols(); } int _cols() const { return m_lhs.cols(); }
@ -92,8 +88,8 @@ class CwiseBinaryOp : ei_no_assignment_operator,
} }
protected: protected:
const LhsRef m_lhs; const typename Lhs::XprCopy m_lhs;
const RhsRef m_rhs; const typename Rhs::XprCopy m_rhs;
const BinaryOp m_functor; const BinaryOp m_functor;
}; };
@ -143,7 +139,7 @@ template<typename Derived1, typename Derived2>
const CwiseBinaryOp<ei_scalar_difference_op, Derived1, Derived2> const CwiseBinaryOp<ei_scalar_difference_op, Derived1, Derived2>
operator-(const MatrixBase<Derived1> &mat1, const MatrixBase<Derived2> &mat2) 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. /** 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> const CwiseBinaryOp<ei_scalar_sum_op, Derived1, Derived2>
operator+(const MatrixBase<Derived1> &mat1, const MatrixBase<Derived2> &mat2) 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. /** replaces \c *this by \c *this + \a other.
@ -192,7 +188,7 @@ template<typename OtherDerived>
const CwiseBinaryOp<ei_scalar_product_op, Derived, OtherDerived> const CwiseBinaryOp<ei_scalar_product_op, Derived, OtherDerived>
MatrixBase<Derived>::cwiseProduct(const MatrixBase<OtherDerived> &other) const 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 /** \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> const CwiseBinaryOp<ei_scalar_quotient_op, Derived, OtherDerived>
MatrixBase<Derived>::cwiseQuotient(const MatrixBase<OtherDerived> &other) const 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 /** \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> const CwiseBinaryOp<CustomBinaryOp, Derived, OtherDerived>
MatrixBase<Derived>::cwise(const MatrixBase<OtherDerived> &other, const CustomBinaryOp& func) const 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 #endif // EIGEN_CWISE_BINARY_OP_H

View File

@ -61,13 +61,11 @@ class CwiseUnaryOp : ei_no_assignment_operator,
EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseUnaryOp) EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseUnaryOp)
typedef typename MatrixType::AsArg MatRef; CwiseUnaryOp(const MatrixType& mat, const UnaryOp& func = UnaryOp())
: m_matrix(mat), m_functor(func) {}
CwiseUnaryOp(const MatRef& mat, const UnaryOp& func = UnaryOp()) : m_matrix(mat), m_functor(func) {}
private: private:
const CwiseUnaryOp& _asArg() const { return *this; }
int _rows() const { return m_matrix.rows(); } int _rows() const { return m_matrix.rows(); }
int _cols() const { return m_matrix.cols(); } int _cols() const { return m_matrix.cols(); }
@ -77,7 +75,7 @@ class CwiseUnaryOp : ei_no_assignment_operator,
} }
protected: protected:
const MatRef m_matrix; const typename MatrixType::XprCopy m_matrix;
const UnaryOp m_functor; const UnaryOp m_functor;
}; };
@ -106,7 +104,7 @@ template<typename Derived>
const CwiseUnaryOp<ei_scalar_opposite_op,Derived> const CwiseUnaryOp<ei_scalar_opposite_op,Derived>
MatrixBase<Derived>::operator-() const 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 /** \returns an expression of the opposite of \c *this
@ -115,10 +113,9 @@ template<typename Derived>
const CwiseUnaryOp<ei_scalar_abs_op,Derived> const CwiseUnaryOp<ei_scalar_abs_op,Derived>
MatrixBase<Derived>::cwiseAbs() const 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 /** \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 * The template parameter \a CustomUnaryOp is the type of the functor
@ -134,10 +131,9 @@ template<typename CustomUnaryOp>
const CwiseUnaryOp<CustomUnaryOp, Derived> const CwiseUnaryOp<CustomUnaryOp, Derived>
MatrixBase<Derived>::cwise(const CustomUnaryOp& func) const MatrixBase<Derived>::cwise(const CustomUnaryOp& func) const
{ {
return CwiseUnaryOp<CustomUnaryOp, Derived>(asArg(), func); return CwiseUnaryOp<CustomUnaryOp, Derived>(derived(), func);
} }
/** \internal /** \internal
* \brief Template functor to compute the conjugate of a complex value * \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> const CwiseUnaryOp<ei_scalar_conjugate_op, Derived>
MatrixBase<Derived>::conjugate() const MatrixBase<Derived>::conjugate() const
{ {
return CwiseUnaryOp<ei_scalar_conjugate_op, Derived>(asArg()); return CwiseUnaryOp<ei_scalar_conjugate_op, Derived>(derived());
} }
/** \internal /** \internal
@ -183,7 +179,7 @@ template<typename NewType>
const CwiseUnaryOp<ei_scalar_cast_op<NewType>, Derived> const CwiseUnaryOp<ei_scalar_cast_op<NewType>, Derived>
MatrixBase<Derived>::cast() const MatrixBase<Derived>::cast() const
{ {
return CwiseUnaryOp<ei_scalar_cast_op<NewType>, Derived>(asArg()); return CwiseUnaryOp<ei_scalar_cast_op<NewType>, Derived>(derived());
} }
/** \internal /** \internal
@ -203,7 +199,8 @@ template<typename Derived>
const CwiseUnaryOp<ei_scalar_multiple_op<typename ei_traits<Derived>::Scalar>, Derived> const CwiseUnaryOp<ei_scalar_multiple_op<typename ei_traits<Derived>::Scalar>, Derived>
MatrixBase<Derived>::operator*(const Scalar& scalar) const 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 */ /** \relates MatrixBase \sa class ei_scalar_multiple_op */
@ -213,7 +210,7 @@ MatrixBase<Derived>::operator/(const Scalar& scalar) const
{ {
assert(NumTraits<Scalar>::HasFloatingPoint); assert(NumTraits<Scalar>::HasFloatingPoint);
return CwiseUnaryOp<ei_scalar_multiple_op<Scalar>, Derived> 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 */ /** \sa ei_scalar_multiple_op */

View File

@ -60,21 +60,18 @@ template<typename MatrixType> class DiagonalCoeffs
EIGEN_GENERIC_PUBLIC_INTERFACE(DiagonalCoeffs) EIGEN_GENERIC_PUBLIC_INTERFACE(DiagonalCoeffs)
typedef typename MatrixType::AsArg MatRef; DiagonalCoeffs(const MatrixType& matrix) : m_matrix(matrix) {}
DiagonalCoeffs(const MatRef& matrix) : m_matrix(matrix) {}
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(DiagonalCoeffs) EIGEN_INHERIT_ASSIGNMENT_OPERATORS(DiagonalCoeffs)
private: private:
const DiagonalCoeffs& _asArg() const { return *this; }
int _rows() const { return std::min(m_matrix.rows(), m_matrix.cols()); } int _rows() const { return std::min(m_matrix.rows(), m_matrix.cols()); }
int _cols() const { return 1; } int _cols() const { return 1; }
Scalar& _coeffRef(int row, int) 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 Scalar _coeff(int row, int) const
@ -83,7 +80,8 @@ template<typename MatrixType> class DiagonalCoeffs
} }
protected: 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. /** \returns an expression of the main diagonal of *this, which must be a square matrix.
@ -96,7 +94,7 @@ template<typename Derived>
DiagonalCoeffs<Derived> DiagonalCoeffs<Derived>
MatrixBase<Derived>::diagonal() MatrixBase<Derived>::diagonal()
{ {
return DiagonalCoeffs<Derived>(asArg()); return DiagonalCoeffs<Derived>(derived());
} }
/** This is the const version of diagonal(). */ /** This is the const version of diagonal(). */
@ -104,7 +102,7 @@ template<typename Derived>
const DiagonalCoeffs<Derived> const DiagonalCoeffs<Derived>
MatrixBase<Derived>::diagonal() const MatrixBase<Derived>::diagonal() const
{ {
return DiagonalCoeffs<Derived>(asArg()); return DiagonalCoeffs<Derived>(derived());
} }
#endif // EIGEN_DIAGONALCOEFFS_H #endif // EIGEN_DIAGONALCOEFFS_H

View File

@ -58,9 +58,7 @@ class DiagonalMatrix : ei_no_assignment_operator,
EIGEN_GENERIC_PUBLIC_INTERFACE(DiagonalMatrix) EIGEN_GENERIC_PUBLIC_INTERFACE(DiagonalMatrix)
typedef typename CoeffsVectorType::AsArg CoeffsVecRef; DiagonalMatrix(const CoeffsVectorType& coeffs) : m_coeffs(coeffs)
DiagonalMatrix(const CoeffsVecRef& coeffs) : m_coeffs(coeffs)
{ {
assert(CoeffsVectorType::IsVectorAtCompileTime assert(CoeffsVectorType::IsVectorAtCompileTime
&& coeffs.size() > 0); && coeffs.size() > 0);
@ -68,7 +66,6 @@ class DiagonalMatrix : ei_no_assignment_operator,
private: private:
const DiagonalMatrix& _asArg() const { return *this; }
int _rows() const { return m_coeffs.size(); } int _rows() const { return m_coeffs.size(); }
int _cols() const { return m_coeffs.size(); } int _cols() const { return m_coeffs.size(); }
@ -78,7 +75,7 @@ class DiagonalMatrix : ei_no_assignment_operator,
} }
protected: 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 /** \returns an expression of a diagonal matrix with *this as vector of diagonal coefficients
@ -94,7 +91,7 @@ template<typename Derived>
const DiagonalMatrix<Derived> const DiagonalMatrix<Derived>
MatrixBase<Derived>::asDiagonal() const MatrixBase<Derived>::asDiagonal() const
{ {
return DiagonalMatrix<Derived>(asArg()); return DiagonalMatrix<Derived>(derived());
} }
/** \returns true if *this is approximately equal to a diagonal matrix, /** \returns true if *this is approximately equal to a diagonal matrix,

View File

@ -56,15 +56,15 @@ struct ei_scalar_abs_op;
template<typename NewType> struct ei_scalar_cast_op; template<typename NewType> struct ei_scalar_cast_op;
template<typename Scalar> struct ei_scalar_multiple_op; template<typename Scalar> struct ei_scalar_multiple_op;
template<typename T> struct Reference template<typename T> struct ei_xpr_copy
{ {
typedef T Type; typedef T Type;
}; };
template<typename _Scalar, int _Rows, int _Cols, int _StorageOrder, int _MaxRows, int _MaxCols> 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 #endif // EIGEN_FORWARDDECLARATIONS_H

View File

@ -60,7 +60,6 @@ template<typename MatrixType> class Identity : ei_no_assignment_operator,
private: private:
const Identity& _asArg() const { return *this; }
int _rows() const { return m_rows.value(); } int _rows() const { return m_rows.value(); }
int _cols() const { return m_cols.value(); } int _cols() const { return m_cols.value(); }
@ -70,6 +69,7 @@ template<typename MatrixType> class Identity : ei_no_assignment_operator,
} }
protected: protected:
const ei_int_if_dynamic<RowsAtCompileTime> m_rows; const ei_int_if_dynamic<RowsAtCompileTime> m_rows;
const ei_int_if_dynamic<ColsAtCompileTime> m_cols; const ei_int_if_dynamic<ColsAtCompileTime> m_cols;
}; };

View File

@ -59,7 +59,6 @@ template<typename MatrixType> class Map
private: private:
const Map& _asArg() const { return *this; }
int _rows() const { return m_rows; } int _rows() const { return m_rows; }
int _cols() const { return m_cols; } int _cols() const { return m_cols; }

View File

@ -97,14 +97,10 @@ class Matrix : public MatrixBase<Matrix<_Scalar, _Rows, _Cols,
friend class Map<Matrix>; friend class Map<Matrix>;
typedef MatrixRef<Matrix> AsArg;
friend class MatrixRef<Matrix>;
private: private:
ei_matrix_storage<Scalar, MaxSizeAtCompileTime, RowsAtCompileTime, ColsAtCompileTime> m_storage; ei_matrix_storage<Scalar, MaxSizeAtCompileTime, RowsAtCompileTime, ColsAtCompileTime> m_storage;
AsArg _asArg() const { return AsArg(*this); }
int _rows() const { return m_storage.rows(); } int _rows() const { return m_storage.rows(); }
int _cols() const { return m_storage.cols(); } int _cols() const { return m_storage.cols(); }

View File

@ -57,6 +57,12 @@ template<typename Derived> class MatrixBase
typedef typename ei_traits<Derived>::Scalar Scalar; 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 /** 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, * by the \a Derived type. If a value is not known at compile-time,
* it is set to the \a Dynamic constant. * 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 = 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 /** 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 * (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. * \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; } 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. */ /** Copies \a other into *this. \returns a reference to *this. */
template<typename OtherDerived> template<typename OtherDerived>
Derived& operator=(const MatrixBase<OtherDerived>& other); Derived& operator=(const MatrixBase<OtherDerived>& other);

View File

@ -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

View File

@ -60,9 +60,7 @@ template<typename MatrixType> class Minor
EIGEN_GENERIC_PUBLIC_INTERFACE(Minor) EIGEN_GENERIC_PUBLIC_INTERFACE(Minor)
typedef typename MatrixType::AsArg MatRef; Minor(const MatrixType& matrix,
Minor(const MatRef& matrix,
int row, int col) int row, int col)
: m_matrix(matrix), m_row(row), m_col(col) : m_matrix(matrix), m_row(row), m_col(col)
{ {
@ -74,13 +72,12 @@ template<typename MatrixType> class Minor
private: private:
const Minor& _asArg() const { return *this; }
int _rows() const { return m_matrix.rows() - 1; } int _rows() const { return m_matrix.rows() - 1; }
int _cols() const { return m_matrix.cols() - 1; } int _cols() const { return m_matrix.cols() - 1; }
Scalar& _coeffRef(int row, int col) 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 Scalar _coeff(int row, int col) const
@ -89,7 +86,7 @@ template<typename MatrixType> class Minor
} }
protected: protected:
MatRef m_matrix; const typename MatrixType::XprCopy m_matrix;
const int m_row, m_col; const int m_row, m_col;
}; };
@ -106,7 +103,7 @@ template<typename Derived>
Minor<Derived> Minor<Derived>
MatrixBase<Derived>::minor(int row, int col) 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(). */ /** This is the const version of minor(). */
@ -114,7 +111,7 @@ template<typename Derived>
const Minor<Derived> const Minor<Derived>
MatrixBase<Derived>::minor(int row, int col) const MatrixBase<Derived>::minor(int row, int col) const
{ {
return Minor<Derived>(asArg(), row, col); return Minor<Derived>(derived(), row, col);
} }
#endif // EIGEN_MINOR_H #endif // EIGEN_MINOR_H

View File

@ -53,7 +53,6 @@ template<typename MatrixType> class Ones : ei_no_assignment_operator,
private: private:
const Ones& _asArg() const { return *this; }
int _rows() const { return m_rows.value(); } int _rows() const { return m_rows.value(); }
int _cols() const { return m_cols.value(); } int _cols() const { return m_cols.value(); }

View File

@ -91,10 +91,7 @@ template<typename Lhs, typename Rhs> class Product : ei_no_assignment_operator,
EIGEN_GENERIC_PUBLIC_INTERFACE(Product) EIGEN_GENERIC_PUBLIC_INTERFACE(Product)
typedef typename Lhs::AsArg LhsRef; Product(const Lhs& lhs, const Rhs& rhs)
typedef typename Rhs::AsArg RhsRef;
Product(const LhsRef& lhs, const RhsRef& rhs)
: m_lhs(lhs), m_rhs(rhs) : m_lhs(lhs), m_rhs(rhs)
{ {
assert(lhs.cols() == rhs.rows()); assert(lhs.cols() == rhs.rows());
@ -102,7 +99,6 @@ template<typename Lhs, typename Rhs> class Product : ei_no_assignment_operator,
private: private:
const Product& _asArg() const { return *this; }
int _rows() const { return m_lhs.rows(); } int _rows() const { return m_lhs.rows(); }
int _cols() const { return m_rhs.cols(); } 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 != Dynamic
&& Lhs::ColsAtCompileTime <= EIGEN_UNROLLING_LIMIT) && Lhs::ColsAtCompileTime <= EIGEN_UNROLLING_LIMIT)
ei_product_unroller<Lhs::ColsAtCompileTime-1, ei_product_unroller<Lhs::ColsAtCompileTime-1,
Lhs::ColsAtCompileTime <= EIGEN_UNROLLING_LIMIT ? Lhs::ColsAtCompileTime : Dynamic, Lhs::ColsAtCompileTime <= EIGEN_UNROLLING_LIMIT
LhsRef, RhsRef> ? Lhs::ColsAtCompileTime : Dynamic,
Lhs, Rhs>
::run(row, col, m_lhs, m_rhs, res); ::run(row, col, m_lhs, m_rhs, res);
else else
{ {
@ -126,8 +123,8 @@ template<typename Lhs, typename Rhs> class Product : ei_no_assignment_operator,
} }
protected: protected:
const LhsRef m_lhs; const typename Lhs::XprCopy m_lhs;
const RhsRef m_rhs; const typename Rhs::XprCopy m_rhs;
}; };
/** \returns an expression of the matrix product of \c this and \a other, in this order. /** \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> const Product<Derived, OtherDerived>
MatrixBase<Derived>::lazyProduct(const MatrixBase<OtherDerived> &other) const MatrixBase<Derived>::lazyProduct(const MatrixBase<OtherDerived> &other) const
{ {
return Product<Derived, OtherDerived>(asArg(), other.asArg()); return Product<Derived, OtherDerived>(derived(), other.derived());
} }
/** \relates MatrixBase /** \relates MatrixBase

View File

@ -51,7 +51,8 @@ template<typename MatrixType> class Random : ei_no_assignment_operator,
EIGEN_GENERIC_PUBLIC_INTERFACE(Random) EIGEN_GENERIC_PUBLIC_INTERFACE(Random)
const Random& _asArg() const { return *this; } private:
int _rows() const { return m_rows.value(); } int _rows() const { return m_rows.value(); }
int _cols() const { return m_cols.value(); } int _cols() const { return m_cols.value(); }
@ -61,6 +62,7 @@ template<typename MatrixType> class Random : ei_no_assignment_operator,
} }
public: public:
Random(int rows, int cols) : m_rows(rows), m_cols(cols) Random(int rows, int cols) : m_rows(rows), m_cols(cols)
{ {
assert(rows > 0 assert(rows > 0

View File

@ -56,21 +56,18 @@ template<typename MatrixType> class Transpose
EIGEN_GENERIC_PUBLIC_INTERFACE(Transpose) EIGEN_GENERIC_PUBLIC_INTERFACE(Transpose)
typedef typename MatrixType::AsArg MatRef; Transpose(const MatrixType& matrix) : m_matrix(matrix) {}
Transpose(const MatRef& matrix) : m_matrix(matrix) {}
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Transpose) EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Transpose)
private: private:
const Transpose& _asArg() const { return *this; }
int _rows() const { return m_matrix.cols(); } int _rows() const { return m_matrix.cols(); }
int _cols() const { return m_matrix.rows(); } int _cols() const { return m_matrix.rows(); }
Scalar& _coeffRef(int row, int col) 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 Scalar _coeff(int row, int col) const
@ -79,7 +76,7 @@ template<typename MatrixType> class Transpose
} }
protected: protected:
MatRef m_matrix; const typename MatrixType::XprCopy m_matrix;
}; };
/** \returns an expression of the transpose of *this. /** \returns an expression of the transpose of *this.
@ -92,7 +89,7 @@ template<typename Derived>
Transpose<Derived> Transpose<Derived>
MatrixBase<Derived>::transpose() MatrixBase<Derived>::transpose()
{ {
return Transpose<Derived>(asArg()); return Transpose<Derived>(derived());
} }
/** This is the const version of transpose(). \sa adjoint() */ /** This is the const version of transpose(). \sa adjoint() */
@ -100,7 +97,7 @@ template<typename Derived>
const Transpose<Derived> const Transpose<Derived>
MatrixBase<Derived>::transpose() const MatrixBase<Derived>::transpose() const
{ {
return Transpose<Derived>(asArg()); return Transpose<Derived>(derived());
} }
/** \returns an expression of the adjoint (i.e. conjugate transpose) of *this. /** \returns an expression of the adjoint (i.e. conjugate transpose) of *this.

View File

@ -105,7 +105,8 @@ using Base::MaxRowsAtCompileTime; \
using Base::MaxColsAtCompileTime; \ using Base::MaxColsAtCompileTime; \
using Base::SizeAtCompileTime; \ using Base::SizeAtCompileTime; \
using Base::MaxSizeAtCompileTime; \ using Base::MaxSizeAtCompileTime; \
using Base::IsVectorAtCompileTime; using Base::IsVectorAtCompileTime; \
typedef typename ei_xpr_copy<Derived>::Type XprCopy;
#define EIGEN_GENERIC_PUBLIC_INTERFACE(Derived) \ #define EIGEN_GENERIC_PUBLIC_INTERFACE(Derived) \
_EIGEN_GENERIC_PUBLIC_INTERFACE(Derived, MatrixBase<Derived>) \ _EIGEN_GENERIC_PUBLIC_INTERFACE(Derived, MatrixBase<Derived>) \

View File

@ -53,7 +53,6 @@ template<typename MatrixType> class Zero : ei_no_assignment_operator,
private: private:
const Zero& _asArg() const { return *this; }
int _rows() const { return m_rows.value(); } int _rows() const { return m_rows.value(); }
int _cols() const { return m_cols.value(); } int _cols() const { return m_cols.value(); }

View File

@ -1,6 +1,4 @@
// g++ -O3 -DNDEBUG -DMATSIZE=<x> benchmark.cpp -o benchmark && time ./benchmark // g++ -O3 -DNDEBUG -DMATSIZE=<x> benchmark.cpp -o benchmark && time ./benchmark
#include <cstdlib>
#include <cmath>
#include <Eigen/Core> #include <Eigen/Core>
#ifndef MATSIZE #ifndef MATSIZE

View File

@ -6,14 +6,14 @@ template<typename Derived>
Eigen::Block<Derived> Eigen::Block<Derived>
topLeftCorner(MatrixBase<Derived>& m, int rows, int cols) 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> template<typename Derived>
const Eigen::Block<Derived> const Eigen::Block<Derived>
topLeftCorner(const MatrixBase<Derived>& m, int rows, int cols) 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**) int main(int, char**)

View File

@ -6,14 +6,14 @@ template<typename Derived>
Eigen::Block<Derived,Derived::RowsAtCompileTime,1> Eigen::Block<Derived,Derived::RowsAtCompileTime,1>
firstColumn(MatrixBase<Derived>& m) 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> template<typename Derived>
const Eigen::Block<Derived,Derived::RowsAtCompileTime,1> const Eigen::Block<Derived,Derived::RowsAtCompileTime,1>
firstColumn(const MatrixBase<Derived>& m) 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**) int main(int, char**)

View File

@ -13,7 +13,7 @@ template<typename Derived1, typename Derived2>
const Eigen::CwiseBinaryOp<CwiseMinOp, Derived1, Derived2> const Eigen::CwiseBinaryOp<CwiseMinOp, Derived1, Derived2>
cwiseMin(const MatrixBase<Derived1> &mat1, const MatrixBase<Derived2> &mat2) 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**) int main(int, char**)

View File

@ -6,14 +6,14 @@ template<typename Derived>
Eigen::Block<Derived, 2, 2> Eigen::Block<Derived, 2, 2>
topLeft2x2Corner(MatrixBase<Derived>& m) 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> template<typename Derived>
const Eigen::Block<Derived, 2, 2> const Eigen::Block<Derived, 2, 2>
topLeft2x2Corner(const MatrixBase<Derived>& m) 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**) int main(int, char**)

View File

@ -6,14 +6,14 @@ template<typename Derived>
Eigen::Block<Derived,1,Derived::ColsAtCompileTime> Eigen::Block<Derived,1,Derived::ColsAtCompileTime>
firstRow(MatrixBase<Derived>& m) 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> template<typename Derived>
const Eigen::Block<Derived,1,Derived::ColsAtCompileTime> const Eigen::Block<Derived,1,Derived::ColsAtCompileTime>
firstRow(const MatrixBase<Derived>& m) 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**) int main(int, char**)