diff --git a/src/Block.h b/src/Block.h index a32d72d70..68c4439cd 100644 --- a/src/Block.h +++ b/src/Block.h @@ -49,14 +49,14 @@ template class MatrixBlock int rows() const { return m_endRow - m_startRow + 1; } int cols() const { return m_endCol - m_startCol + 1; } - Scalar& operator()(int row, int col=0) + Scalar& write(int row, int col=0) { - return m_matrix(row + m_startRow, col + m_startCol); + return m_matrix.write(row + m_startRow, col + m_startCol); } - Scalar operator()(int row, int col=0) const + Scalar read(int row, int col=0) const { - return m_matrix(row + m_startRow, col + m_startCol); + return m_matrix.read(row + m_startRow, col + m_startCol); } protected: @@ -65,33 +65,18 @@ template class MatrixBlock }; template -MatrixConstXpr< +MatrixXpr< MatrixBlock< - const MatrixConstRef< + MatrixRef< MatrixBase > > > -MatrixBase::block(int startRow, int endRow, int startCol, int endCol) const +MatrixBase::block(int startRow, int endRow, int startCol, int endCol) { - typedef MatrixBlock ProductType; - typedef MatrixConstXpr XprType; - return XprType(ProductType(constRef(), startRow, endRow, startCol, endCol)); -} - -template -MatrixConstXpr< - MatrixBlock< - const MatrixConstXpr - > -> -MatrixConstXpr::block(int startRow, int endRow, int startCol, int endCol) const -{ - typedef MatrixBlock< - const MatrixConstXpr - > ProductType; - typedef MatrixConstXpr XprType; - return XprType(ProductType(*this, startRow, endRow, startCol, endCol)); + typedef MatrixBlock ProductType; + typedef MatrixXpr XprType; + return XprType(ProductType(ref(), startRow, endRow, startCol, endCol)); } template diff --git a/src/Matrix.h b/src/Matrix.h index f18624573..8ff819902 100644 --- a/src/Matrix.h +++ b/src/Matrix.h @@ -84,11 +84,11 @@ class Matrix: public MatrixBase< Matrix > { Base::operator=(other); } template - void operator=(const MatrixConstXpr &xpr) + void operator=(const MatrixXpr &xpr) { Base::operator=(xpr); } template - explicit Matrix(const MatrixConstXpr& xpr) + explicit Matrix(const MatrixXpr& xpr) { *this = xpr; } @@ -125,11 +125,11 @@ class MatrixX : public MatrixBase< MatrixX > { Base::operator=(other); } template - void operator=(const MatrixConstXpr &xpr) + void operator=(const MatrixXpr &xpr) { Base::operator=(xpr); } template - explicit MatrixX(const MatrixConstXpr& xpr) + explicit MatrixX(const MatrixXpr& xpr) { _init(xpr.rows(), xpr.cols()); *this = xpr; diff --git a/src/MatrixBase.h b/src/MatrixBase.h index e21887df6..d49ce8c21 100644 --- a/src/MatrixBase.h +++ b/src/MatrixBase.h @@ -32,37 +32,6 @@ namespace Eigen { -template class MatrixConstRef -{ - public: - typedef typename ForwardDecl::Scalar Scalar; - - MatrixConstRef(const MatrixType& matrix) : m_matrix(matrix) {} - MatrixConstRef(const MatrixConstRef& other) : m_matrix(other.m_matrix) {} - ~MatrixConstRef() {} - - static bool hasDynamicNumRows() - { - return MatrixType::hasDynamicNumRows(); - } - - static bool hasDynamicNumCols() - { - return MatrixType::hasDynamicNumCols(); - } - - int rows() const { return m_matrix.rows(); } - int cols() const { return m_matrix.cols(); } - - const Scalar& operator()(int row, int col) const - { - return m_matrix(row, col); - } - - protected: - const MatrixType& m_matrix; -}; - template class MatrixRef { public: @@ -86,12 +55,15 @@ template class MatrixRef int rows() const { return m_matrix.rows(); } int cols() const { return m_matrix.cols(); } - Scalar& operator()(int row, int col) + const Scalar& read(int row, int col) const { - return m_matrix(row, col); + return m_matrix.read(row, col); } - MatrixType& matrix() { return m_matrix; } + Scalar& write(int row, int col) + { + return m_matrix.write(row, col); + } Xpr xpr() { @@ -108,9 +80,7 @@ class MatrixBase public: typedef typename ForwardDecl::Scalar Scalar; - typedef MatrixConstRef > ConstRef; typedef MatrixRef > Ref; - typedef MatrixConstXpr ConstXpr; typedef MatrixXpr Xpr; typedef MatrixAlias Alias; @@ -118,22 +88,12 @@ class MatrixBase { return Ref(*this); } - - ConstRef constRef() const - { - return ConstRef(*this); - } - + Xpr xpr() { return Xpr(ref()); } - ConstXpr constXpr() const - { - return ConstXpr(constRef()); - } - Alias alias(); static bool hasDynamicNumRows() @@ -171,20 +131,30 @@ class MatrixBase return static_cast(this)->m_array; } - const Scalar& operator()(int row, int col = 0) const + const Scalar& read(int row, int col = 0) const { EIGEN_CHECK_RANGES(*this, row, col); return array()[row + col * rows()]; } - Scalar& operator()(int row, int col = 0) + const Scalar& operator()(int row, int col = 0) const + { + return read(row, col); + } + + Scalar& write(int row, int col = 0) { EIGEN_CHECK_RANGES(*this, row, col); return array()[row + col * rows()]; } + Scalar& operator()(int row, int col = 0) + { + return write(row, col); + } + template - MatrixBase& operator=(const MatrixConstXpr &otherXpr) + MatrixBase& operator=(const MatrixXpr &otherXpr) { resize(otherXpr.rows(), otherXpr.cols()); xpr() = otherXpr; @@ -193,23 +163,27 @@ class MatrixBase MatrixBase& operator=(const MatrixBase &other) { - return *this = other.constXpr(); + resize(other.rows(), other.cols()); + for(int i = 0; i < rows(); i++) + for(int j = 0; j < cols(); j++) + this->operator()(i, j) = other(i, j); + return *this; } - MatrixConstXpr > row(int i) const; - MatrixConstXpr > col(int i) const; - MatrixConstXpr > minor(int row, int col) const; - MatrixConstXpr > - block(int startRow, int endRow, int startCol = 0, int endCol = 0) const; + MatrixXpr > row(int i); + MatrixXpr > col(int i); + MatrixXpr > minor(int row, int col); + MatrixXpr > + block(int startRow, int endRow, int startCol = 0, int endCol = 0); template - MatrixBase& operator+=(const MatrixConstXpr &xpr); + MatrixBase& operator+=(const MatrixXpr &xpr); template - MatrixBase& operator-=(const MatrixConstXpr &xpr); + MatrixBase& operator-=(const MatrixXpr &xpr); template - MatrixBase& operator+=(const MatrixBase &other); + MatrixBase& operator+=(MatrixBase &other); template - MatrixBase& operator-=(const MatrixBase &other); + MatrixBase& operator-=(MatrixBase &other); protected: @@ -223,7 +197,7 @@ MatrixXpr& MatrixXpr::operator=(const MatrixBase& mat assert(rows() == matrix.rows() && cols() == matrix.cols()); for(int i = 0; i < rows(); i++) for(int j = 0; j < cols(); j++) - this->operator()(i, j) = matrix(i, j); + write(i, j) = matrix(i, j); return *this; } @@ -245,14 +219,14 @@ std::ostream & operator << template std::ostream & operator << (std::ostream & s, - const MatrixConstXpr& m) + const MatrixXpr& xpr) { - for( int i = 0; i < m.rows(); i++ ) + for( int i = 0; i < xpr.rows(); i++ ) { - s << m( i, 0 ); - for (int j = 1; j < m.cols(); j++ ) - s << " " << m( i, j ); - if( i < m.rows() - 1) + s << xpr.read(i, 0); + for (int j = 1; j < xpr.cols(); j++ ) + s << " " << xpr.read(i, j); + if( i < xpr.rows() - 1) s << std::endl; } return s; @@ -291,9 +265,9 @@ template class MatrixAlias int rows() const { return m_tmp.rows(); } int cols() const { return m_tmp.cols(); } - Scalar& operator()(int row, int col) + Scalar& write(int row, int col) { - return m_tmp(row, col); + return m_tmp.write(row, col); } Ref ref() @@ -301,20 +275,29 @@ template class MatrixAlias return Ref(*this); } + MatrixXpr > row(int i) { return xpr().row(i); }; + MatrixXpr > col(int i) { return xpr().col(i); }; + MatrixXpr > minor(int row, int col) { return xpr().minor(row, col); }; + MatrixXpr > + block(int startRow, int endRow, int startCol = 0, int endCol = 0) + { + return xpr().block(startRow, endRow, startCol, endCol); + } + template - void operator=(const MatrixConstXpr &xpr) + void operator=(const MatrixXpr &xpr) { ref().xpr() = xpr; } template - void operator+=(const MatrixConstXpr &xpr) + void operator+=(const MatrixXpr &xpr) { ref().xpr() += xpr; } template - void operator-=(const MatrixConstXpr &xpr) + void operator-=(const MatrixXpr &xpr) { ref().xpr() -= xpr; } diff --git a/src/MatrixOps.h b/src/MatrixOps.h index 67e10d9d7..e76e64c85 100644 --- a/src/MatrixOps.h +++ b/src/MatrixOps.h @@ -46,9 +46,9 @@ template class Matrix##NAME \ int rows() const { return m_lhs.rows(); } \ int cols() const { return m_lhs.cols(); } \ \ - Scalar operator()(int row, int col) const \ + Scalar read(int row, int col) const \ { \ - return m_lhs(row, col) SYMBOL m_rhs(row, col); \ + return m_lhs.read(row, col) SYMBOL m_rhs.read(row, col); \ } \ \ protected: \ @@ -78,11 +78,11 @@ template class MatrixProduct int rows() const { return m_lhs.rows(); } int cols() const { return m_rhs.cols(); } - Scalar operator()(int row, int col) const + Scalar read(int row, int col) const { Scalar x = static_cast(0); for(int i = 0; i < m_lhs.cols(); i++) - x += m_lhs(row, i) * m_rhs(i, col); + x += m_lhs.read(row, i) * m_rhs.read(i, col); return x; } @@ -93,72 +93,72 @@ template class MatrixProduct #define EIGEN_MAKE_MATRIX_OP(NAME, SYMBOL) \ template \ -const MatrixConstXpr< \ - const Matrix##NAME< \ - MatrixConstXpr, \ - MatrixConstXpr \ +MatrixXpr< \ + Matrix##NAME< \ + MatrixXpr, \ + MatrixXpr \ > \ > \ -operator SYMBOL(const MatrixConstXpr &xpr1, const MatrixConstXpr &xpr2) \ +operator SYMBOL(const MatrixXpr &xpr1, const MatrixXpr &xpr2) \ { \ - typedef const Matrix##NAME< \ - MatrixConstXpr, \ - MatrixConstXpr \ - > ProductType; \ - typedef const MatrixConstXpr XprType; \ + typedef Matrix##NAME< \ + MatrixXpr, \ + MatrixXpr \ + > ProductType; \ + typedef MatrixXpr XprType; \ return XprType(ProductType(xpr1, xpr2)); \ } \ \ template \ -const MatrixConstXpr< \ - const Matrix##NAME< \ - MatrixConstRef >, \ - MatrixConstXpr \ +MatrixXpr< \ + Matrix##NAME< \ + MatrixRef >, \ + MatrixXpr \ > \ > \ -operator SYMBOL(const MatrixBase &mat, const MatrixConstXpr &xpr) \ +operator SYMBOL(MatrixBase &mat, const MatrixXpr &xpr) \ { \ - typedef const Matrix##NAME< \ - MatrixConstRef >, \ - MatrixConstXpr \ - > ProductType; \ - typedef const MatrixConstXpr XprType; \ - return XprType(ProductType(mat.constRef(), xpr)); \ + typedef Matrix##NAME< \ + MatrixRef >, \ + MatrixXpr \ + > ProductType; \ + typedef MatrixXpr XprType; \ + return XprType(ProductType(mat.ref(), xpr)); \ } \ \ template \ -const MatrixConstXpr< \ - const Matrix##NAME< \ - MatrixConstXpr, \ - MatrixConstRef > \ +MatrixXpr< \ + Matrix##NAME< \ + MatrixXpr, \ + MatrixRef > \ > \ > \ -operator SYMBOL(const MatrixConstXpr &xpr, const MatrixBase &mat) \ +operator SYMBOL(const MatrixXpr &xpr, MatrixBase &mat) \ { \ - typedef const Matrix##NAME< \ - MatrixConstXpr, \ - MatrixConstRef > \ - > ProductType; \ - typedef const MatrixConstXpr XprType; \ - return XprType(ProductType(xpr, mat.constRef())); \ + typedef Matrix##NAME< \ + MatrixXpr, \ + MatrixRef > \ + > ProductType; \ + typedef MatrixXpr XprType; \ + return XprType(ProductType(xpr, mat.ref())); \ } \ \ template \ -const MatrixConstXpr< \ - const Matrix##NAME< \ - MatrixConstRef >, \ - MatrixConstRef > \ +MatrixXpr< \ + Matrix##NAME< \ + MatrixRef >, \ + MatrixRef > \ > \ > \ -operator SYMBOL(const MatrixBase &mat1, const MatrixBase &mat2) \ +operator SYMBOL(MatrixBase &mat1, MatrixBase &mat2) \ { \ - typedef const Matrix##NAME< \ - MatrixConstRef >, \ - MatrixConstRef > \ + typedef Matrix##NAME< \ + MatrixRef >, \ + MatrixRef > \ > ProductType; \ - typedef const MatrixConstXpr XprType; \ - return XprType(ProductType(MatrixConstRef >(mat1), \ - MatrixConstRef >(mat2))); \ + typedef MatrixXpr XprType; \ + return XprType(ProductType(mat1.ref(), \ + mat2.ref())); \ } EIGEN_MAKE_MATRIX_OP(Sum, +) @@ -171,7 +171,7 @@ EIGEN_MAKE_MATRIX_OP(Product, *) template \ template \ MatrixBase & \ -MatrixBase::operator SYMBOL##=(const MatrixBase &mat2) \ +MatrixBase::operator SYMBOL##=(MatrixBase &mat2) \ { \ return *this = *this SYMBOL mat2; \ } \ @@ -179,7 +179,7 @@ MatrixBase::operator SYMBOL##=(const MatrixBase &mat2) \ template \ template \ MatrixBase & \ -MatrixBase::operator SYMBOL##=(const MatrixConstXpr &xpr) \ +MatrixBase::operator SYMBOL##=(const MatrixXpr &xpr) \ { \ return *this = *this SYMBOL xpr; \ } \ @@ -187,24 +187,24 @@ MatrixBase::operator SYMBOL##=(const MatrixConstXpr &xpr) \ template \ template \ MatrixXpr & \ -MatrixXpr::operator SYMBOL##=(const MatrixBase &mat) \ +MatrixXpr::operator SYMBOL##=(MatrixBase &mat) \ { \ assert(rows() == mat.rows() && cols() == mat.cols()); \ for(int i = 0; i < rows(); i++) \ for(int j = 0; j < cols(); j++) \ - this->operator()(i, j) SYMBOL##= mat(i, j); \ + write(i, j) SYMBOL##= mat.read(i, j); \ return *this; \ } \ \ template \ template \ MatrixXpr & \ -MatrixXpr::operator SYMBOL##=(const MatrixConstXpr &other) \ +MatrixXpr::operator SYMBOL##=(const MatrixXpr &other) \ { \ assert(rows() == other.rows() && cols() == other.cols()); \ for(int i = 0; i < rows(); i++) \ for(int j = 0; j < cols(); j++) \ - this->operator()(i, j) SYMBOL##= other(i, j); \ + write(i, j) SYMBOL##= other.read(i, j); \ return *this; \ } diff --git a/src/MatrixXpr.h b/src/MatrixXpr.h index 5caf365ed..a42f84af6 100644 --- a/src/MatrixXpr.h +++ b/src/MatrixXpr.h @@ -34,42 +34,6 @@ template class MatrixCol; template class MatrixMinor; template class MatrixBlock; -template class MatrixConstXpr -{ - public: - typedef typename Content::Scalar Scalar; - - MatrixConstXpr(const Content& content) - : m_content(content) {} - - MatrixConstXpr(const MatrixConstXpr& other) - : m_content(other.m_content) {} - - ~MatrixConstXpr() {} - - static bool hasDynamicSize() - { - return Content::hasDynamicSize(); - } - - int rows() const { return m_content.rows(); } - int cols() const { return m_content.cols(); } - - Scalar operator()(int row, int col) const - { - return m_content(row, col); - } - - MatrixConstXpr > > row(int i) const; - MatrixConstXpr > > col(int i) const; - MatrixConstXpr > > minor(int row, int col) const; - MatrixConstXpr > > - block(int startRow, int endRow, int startCol= 0, int endCol = 0) const; - - protected: - const Content m_content; -}; - template class MatrixXpr { public: @@ -83,26 +47,35 @@ template class MatrixXpr ~MatrixXpr() {} - static bool hasDynamicSize() - { - return Content::hasDynamicSize(); - } - int rows() const { return m_content.rows(); } int cols() const { return m_content.cols(); } - Scalar& operator()(int row, int col) + Scalar& write(int row, int col) { - return m_content(row, col); + return m_content.write(row, col); + } + + Scalar read(int row, int col) const + { + return m_content.read(row, col); } template - MatrixXpr& operator=(const MatrixConstXpr &other) + MatrixXpr& operator=(const MatrixXpr& other) { assert(rows() == other.rows() && cols() == other.cols()); for(int i = 0; i < rows(); i++) for(int j = 0; j < cols(); j++) - this->operator()(i, j) = other(i, j); + write(i, j) = other.read(i, j); + return *this; + } + + MatrixXpr& operator=(const MatrixXpr& other) + { + assert(rows() == other.rows() && cols() == other.cols()); + for(int i = 0; i < rows(); i++) + for(int j = 0; j < cols(); j++) + write(i, j) = other.read(i, j); return *this; } @@ -116,17 +89,13 @@ template class MatrixXpr block(int startRow, int endRow, int startCol= 0, int endCol = 0); template - MatrixXpr& operator+=(const MatrixConstXpr &other); + MatrixXpr& operator+=(const MatrixXpr &other); template - MatrixXpr& operator-=(const MatrixConstXpr &other); + MatrixXpr& operator-=(const MatrixXpr &other); template - MatrixXpr& operator+=(const MatrixBase &matrix); + MatrixXpr& operator+=(MatrixBase &matrix); template - MatrixXpr& operator-=(const MatrixBase &matrix); - - private: - void operator=(const MatrixXpr &other) - {} + MatrixXpr& operator-=(MatrixBase &matrix); protected: Content m_content; diff --git a/src/Minor.h b/src/Minor.h index 0617361b2..da0d759de 100644 --- a/src/Minor.h +++ b/src/Minor.h @@ -45,14 +45,14 @@ template class MatrixMinor int rows() const { return m_matrix.rows() - 1; } int cols() const { return m_matrix.cols() - 1; } - Scalar& operator()(int row, int col=0) + Scalar& write(int row, int col=0) { - return m_matrix(row + (row >= m_row), col + (col >= m_col)); + return m_matrix.write(row + (row >= m_row), col + (col >= m_col)); } - Scalar operator()(int row, int col=0) const + Scalar read(int row, int col=0) const { - return m_matrix(row + (row >= m_row), col + (col >= m_col)); + return m_matrix.read(row + (row >= m_row), col + (col >= m_col)); } protected: @@ -61,33 +61,18 @@ template class MatrixMinor }; template -MatrixConstXpr< +MatrixXpr< MatrixMinor< - const MatrixConstRef< + MatrixRef< MatrixBase > > > -MatrixBase::minor(int row, int col) const +MatrixBase::minor(int row, int col) { - typedef MatrixMinor ProductType; - typedef MatrixConstXpr XprType; - return XprType(ProductType(constRef(), row, col)); -} - -template -MatrixConstXpr< - MatrixMinor< - const MatrixConstXpr - > -> -MatrixConstXpr::minor(int row, int col) const -{ - typedef MatrixMinor< - const MatrixConstXpr - > ProductType; - typedef MatrixConstXpr XprType; - return XprType(ProductType(*this, row, col)); + typedef MatrixMinor ProductType; + typedef MatrixXpr XprType; + return XprType(ProductType(ref(), row, col)); } template diff --git a/src/RowAndCol.h b/src/RowAndCol.h index 5e348781d..5da3cfa23 100644 --- a/src/RowAndCol.h +++ b/src/RowAndCol.h @@ -45,18 +45,18 @@ template class MatrixRow int rows() const { return m_matrix.cols(); } int cols() const { return 1; } - Scalar& operator()(int row, int col=0) + Scalar& write(int row, int col=0) { EIGEN_UNUSED(col); EIGEN_CHECK_ROW_RANGE(*this, row); - return m_matrix(m_row, row); + return m_matrix.write(m_row, row); } - Scalar operator()(int row, int col=0) const + Scalar read(int row, int col=0) const { EIGEN_UNUSED(col); EIGEN_CHECK_ROW_RANGE(*this, row); - return m_matrix(m_row, row); + return m_matrix.read(m_row, row); } protected: @@ -81,18 +81,18 @@ template class MatrixCol int rows() const { return m_matrix.rows(); } int cols() const { return 1; } - Scalar& operator()(int row, int col=0) + Scalar& write(int row, int col=0) { EIGEN_UNUSED(col); EIGEN_CHECK_ROW_RANGE(*this, row); - return m_matrix(row, m_col); + return m_matrix.write(row, m_col); } - Scalar operator()(int row, int col=0) const + Scalar read(int row, int col=0) const { EIGEN_UNUSED(col); EIGEN_CHECK_ROW_RANGE(*this, row); - return m_matrix(row, m_col); + return m_matrix.read(row, m_col); } protected: @@ -102,33 +102,18 @@ template class MatrixCol #define EIGEN_MAKE_ROW_COL_FUNCTIONS(func, Func) \ template \ -MatrixConstXpr< \ +MatrixXpr< \ Matrix##Func< \ - const MatrixConstRef< \ + MatrixRef< \ MatrixBase \ > \ > \ > \ -MatrixBase::func(int i) const\ +MatrixBase::func(int i)\ { \ - typedef Matrix##Func ProductType; \ - typedef MatrixConstXpr XprType; \ - return XprType(ProductType(constRef(), i)); \ -} \ -\ -template \ -MatrixConstXpr< \ - Matrix##Func< \ - const MatrixConstXpr \ - > \ -> \ -MatrixConstXpr::func(int i) const\ -{ \ - typedef Matrix##Func< \ - const MatrixConstXpr \ - > ProductType; \ - typedef MatrixConstXpr XprType; \ - return XprType(ProductType(*this, i)); \ + typedef Matrix##Func ProductType; \ + typedef MatrixXpr XprType; \ + return XprType(ProductType(ref(), i)); \ } \ \ template \ @@ -137,7 +122,7 @@ MatrixXpr< \ MatrixXpr \ > \ > \ -MatrixXpr::func(int i) \ +MatrixXpr::func(int i)\ { \ typedef Matrix##Func< \ MatrixXpr \ diff --git a/src/ScalarOps.h b/src/ScalarOps.h index 5d0a16ec9..01772569a 100644 --- a/src/ScalarOps.h +++ b/src/ScalarOps.h @@ -42,9 +42,9 @@ template class ScalarProduct int rows() const { return m_matrix.rows(); } int cols() const { return m_matrix.cols(); } - Scalar operator()(int row, int col) const + Scalar read(int row, int col) const { - return m_matrix(row, col) * m_scalar; + return m_matrix.read(row, col) * m_scalar; } protected: @@ -53,89 +53,89 @@ template class ScalarProduct }; template -const MatrixConstXpr< - const ScalarProduct< - MatrixConstXpr +MatrixXpr< + ScalarProduct< + MatrixXpr > > -operator *(const MatrixConstXpr& xpr, - typename Content::Scalar scalar) +operator *(const MatrixXpr& xpr, + typename Content::Scalar scalar) { - typedef const ScalarProduct< - MatrixConstXpr - > ProductType; - typedef const MatrixConstXpr XprType; + typedef ScalarProduct< + MatrixXpr + > ProductType; + typedef MatrixXpr XprType; return XprType(ProductType(xpr, scalar)); } template -const MatrixConstXpr< - const ScalarProduct< - MatrixConstXpr +MatrixXpr< + ScalarProduct< + MatrixXpr > > operator *(typename Content::Scalar scalar, - const MatrixConstXpr& xpr) + const MatrixXpr& xpr) { - typedef const ScalarProduct< - MatrixConstXpr - > ProductType; - typedef const MatrixConstXpr XprType; + typedef ScalarProduct< + MatrixXpr + > ProductType; + typedef MatrixXpr XprType; return XprType(ProductType(xpr, scalar)); } template -const MatrixConstXpr< - const ScalarProduct< - MatrixConstRef > +MatrixXpr< + ScalarProduct< + MatrixRef > > > -operator *(const MatrixBase& matrix, - typename Derived::Scalar scalar) +operator *(MatrixBase& matrix, + typename Derived::Scalar scalar) { - typedef const ScalarProduct< - MatrixConstRef > + typedef ScalarProduct< + MatrixRef > > ProductType; - typedef const MatrixConstXpr XprType; - return XprType(ProductType(matrix.constRef(), scalar)); + typedef MatrixXpr XprType; + return XprType(ProductType(matrix.ref(), scalar)); } template -const MatrixConstXpr< - const ScalarProduct< - MatrixConstRef > +MatrixXpr< + ScalarProduct< + MatrixRef > > > operator *(typename Derived::Scalar scalar, - const MatrixBase& matrix) + MatrixBase& matrix) { - typedef const ScalarProduct< - MatrixConstRef > - > ProductType; - typedef const MatrixConstXpr XprType; - return XprType(ProductType(matrix.constRef(), scalar)); + typedef ScalarProduct< + MatrixRef > + > ProductType; + typedef MatrixXpr XprType; + return XprType(ProductType(matrix.ref(), scalar)); } template -const MatrixConstXpr< - const ScalarProduct< - MatrixConstXpr +MatrixXpr< + ScalarProduct< + MatrixXpr > > -operator /(const MatrixConstXpr& xpr, - typename Content::Scalar scalar) +operator /(MatrixXpr& xpr, + typename Content::Scalar scalar) { return xpr * (static_cast(1) / scalar); } template -const MatrixConstXpr< - const ScalarProduct< - MatrixConstRef > +MatrixXpr< + ScalarProduct< + MatrixRef > > > -operator /(const MatrixBase& matrix, - typename Derived::Scalar scalar) +operator /(MatrixBase& matrix, + typename Derived::Scalar scalar) { return matrix * (static_cast(1) / scalar); } diff --git a/src/Vector.h b/src/Vector.h index f36364d4b..ae43a50c7 100644 --- a/src/Vector.h +++ b/src/Vector.h @@ -84,13 +84,13 @@ class Vector: public MatrixBase > { Base::operator=(other); } template - void operator=(const MatrixConstXpr &xpr) + void operator=(const MatrixXpr &xpr) { Base::operator=(xpr); } template - explicit Vector(const MatrixConstXpr& xpr) + explicit Vector(const MatrixXpr& xpr) { *this = xpr; } @@ -131,13 +131,13 @@ class VectorX : public MatrixBase > } template - void operator=(const MatrixConstXpr &xpr) + void operator=(const MatrixXpr &xpr) { Base::operator=(xpr); } template - explicit VectorX(const MatrixConstXpr& xpr) + explicit VectorX(const MatrixXpr& xpr) { _init(xpr.rows()); *this = xpr; diff --git a/test/matrixmanip.cpp b/test/matrixmanip.cpp index aa55d02cf..b3413212a 100644 --- a/test/matrixmanip.cpp +++ b/test/matrixmanip.cpp @@ -35,10 +35,10 @@ template void matrixManip(const MatrixType& m) a.col(j); a.minor(i, j); a.block(1, rows-1, 1, cols-1); - a.xpr().row(i) = b.row(i); - a.xpr().row(i) += b.row(i); - a.xpr().minor(i, j) = b.block(1, rows-1, 1, cols-1); - a.alias().xpr().minor(i, j) -= a.block(1, rows-1, 1, cols-1); + a.row(i) = b.row(i); + a.row(i) += b.row(i); + a.minor(i, j) = b.block(1, rows-1, 1, cols-1); + a.alias().minor(i, j) -= a.block(1, rows-1, 1, cols-1); } void EigenTest::testMatrixManip()