remove the MatrixConstXpr and MatrixConstRef classes.

Now the user doesn't need anymore to call .xpr() and can simply do:
matrix.row(i) += matrix.row(j)

Also remove the obsolete MatrixXpr::hasDynamicSize() method (thanks to
Michael Olbrich for reporting this).

CCMAIL:<michael.olbrich@gmx.net>
This commit is contained in:
Benoit Jacob 2007-09-09 08:15:48 +00:00
parent 506cc5db12
commit fe9b6b8f17
10 changed files with 224 additions and 317 deletions

View File

@ -49,14 +49,14 @@ template<typename MatrixType> class MatrixBlock
int rows() const { return m_endRow - m_startRow + 1; } int rows() const { return m_endRow - m_startRow + 1; }
int cols() const { return m_endCol - m_startCol + 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: protected:
@ -65,33 +65,18 @@ template<typename MatrixType> class MatrixBlock
}; };
template<typename Derived> template<typename Derived>
MatrixConstXpr< MatrixXpr<
MatrixBlock< MatrixBlock<
const MatrixConstRef< MatrixRef<
MatrixBase<Derived> MatrixBase<Derived>
> >
> >
> >
MatrixBase<Derived>::block(int startRow, int endRow, int startCol, int endCol) const MatrixBase<Derived>::block(int startRow, int endRow, int startCol, int endCol)
{ {
typedef MatrixBlock<const ConstRef> ProductType; typedef MatrixBlock<Ref> ProductType;
typedef MatrixConstXpr<ProductType> XprType; typedef MatrixXpr<ProductType> XprType;
return XprType(ProductType(constRef(), startRow, endRow, startCol, endCol)); return XprType(ProductType(ref(), startRow, endRow, startCol, endCol));
}
template<typename Content>
MatrixConstXpr<
MatrixBlock<
const MatrixConstXpr<Content>
>
>
MatrixConstXpr<Content>::block(int startRow, int endRow, int startCol, int endCol) const
{
typedef MatrixBlock<
const MatrixConstXpr<Content>
> ProductType;
typedef MatrixConstXpr<ProductType> XprType;
return XprType(ProductType(*this, startRow, endRow, startCol, endCol));
} }
template<typename Content> template<typename Content>

View File

@ -84,11 +84,11 @@ class Matrix: public MatrixBase< Matrix<T, Rows, Cols> >
{ Base::operator=(other); } { Base::operator=(other); }
template<typename XprContent> template<typename XprContent>
void operator=(const MatrixConstXpr<XprContent> &xpr) void operator=(const MatrixXpr<XprContent> &xpr)
{ Base::operator=(xpr); } { Base::operator=(xpr); }
template<typename XprContent> template<typename XprContent>
explicit Matrix(const MatrixConstXpr<XprContent>& xpr) explicit Matrix(const MatrixXpr<XprContent>& xpr)
{ {
*this = xpr; *this = xpr;
} }
@ -125,11 +125,11 @@ class MatrixX : public MatrixBase< MatrixX<T> >
{ Base::operator=(other); } { Base::operator=(other); }
template<typename XprContent> template<typename XprContent>
void operator=(const MatrixConstXpr<XprContent> &xpr) void operator=(const MatrixXpr<XprContent> &xpr)
{ Base::operator=(xpr); } { Base::operator=(xpr); }
template<typename XprContent> template<typename XprContent>
explicit MatrixX(const MatrixConstXpr<XprContent>& xpr) explicit MatrixX(const MatrixXpr<XprContent>& xpr)
{ {
_init(xpr.rows(), xpr.cols()); _init(xpr.rows(), xpr.cols());
*this = xpr; *this = xpr;

View File

@ -32,37 +32,6 @@
namespace Eigen namespace Eigen
{ {
template<typename MatrixType> class MatrixConstRef
{
public:
typedef typename ForwardDecl<MatrixType>::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<typename MatrixType> class MatrixRef template<typename MatrixType> class MatrixRef
{ {
public: public:
@ -86,12 +55,15 @@ template<typename MatrixType> class MatrixRef
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(); }
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() Xpr xpr()
{ {
@ -108,9 +80,7 @@ class MatrixBase
public: public:
typedef typename ForwardDecl<Derived>::Scalar Scalar; typedef typename ForwardDecl<Derived>::Scalar Scalar;
typedef MatrixConstRef<MatrixBase<Derived> > ConstRef;
typedef MatrixRef<MatrixBase<Derived> > Ref; typedef MatrixRef<MatrixBase<Derived> > Ref;
typedef MatrixConstXpr<ConstRef> ConstXpr;
typedef MatrixXpr<Ref> Xpr; typedef MatrixXpr<Ref> Xpr;
typedef MatrixAlias<Derived> Alias; typedef MatrixAlias<Derived> Alias;
@ -119,21 +89,11 @@ class MatrixBase
return Ref(*this); return Ref(*this);
} }
ConstRef constRef() const
{
return ConstRef(*this);
}
Xpr xpr() Xpr xpr()
{ {
return Xpr(ref()); return Xpr(ref());
} }
ConstXpr constXpr() const
{
return ConstXpr(constRef());
}
Alias alias(); Alias alias();
static bool hasDynamicNumRows() static bool hasDynamicNumRows()
@ -171,7 +131,18 @@ class MatrixBase
return static_cast<Derived*>(this)->m_array; return static_cast<Derived*>(this)->m_array;
} }
const Scalar& read(int row, int col = 0) const
{
EIGEN_CHECK_RANGES(*this, row, col);
return array()[row + col * rows()];
}
const Scalar& operator()(int row, int col = 0) const 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); EIGEN_CHECK_RANGES(*this, row, col);
return array()[row + col * rows()]; return array()[row + col * rows()];
@ -179,12 +150,11 @@ class MatrixBase
Scalar& operator()(int row, int col = 0) Scalar& operator()(int row, int col = 0)
{ {
EIGEN_CHECK_RANGES(*this, row, col); return write(row, col);
return array()[row + col * rows()];
} }
template<typename XprContent> template<typename XprContent>
MatrixBase& operator=(const MatrixConstXpr<XprContent> &otherXpr) MatrixBase& operator=(const MatrixXpr<XprContent> &otherXpr)
{ {
resize(otherXpr.rows(), otherXpr.cols()); resize(otherXpr.rows(), otherXpr.cols());
xpr() = otherXpr; xpr() = otherXpr;
@ -193,23 +163,27 @@ class MatrixBase
MatrixBase& operator=(const MatrixBase &other) 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<MatrixRow<const ConstRef> > row(int i) const; MatrixXpr<MatrixRow<Ref> > row(int i);
MatrixConstXpr<MatrixCol<const ConstRef> > col(int i) const; MatrixXpr<MatrixCol<Ref> > col(int i);
MatrixConstXpr<MatrixMinor<const ConstRef> > minor(int row, int col) const; MatrixXpr<MatrixMinor<Ref> > minor(int row, int col);
MatrixConstXpr<MatrixBlock<const ConstRef> > MatrixXpr<MatrixBlock<Ref> >
block(int startRow, int endRow, int startCol = 0, int endCol = 0) const; block(int startRow, int endRow, int startCol = 0, int endCol = 0);
template<typename Content> template<typename Content>
MatrixBase& operator+=(const MatrixConstXpr<Content> &xpr); MatrixBase& operator+=(const MatrixXpr<Content> &xpr);
template<typename Content> template<typename Content>
MatrixBase& operator-=(const MatrixConstXpr<Content> &xpr); MatrixBase& operator-=(const MatrixXpr<Content> &xpr);
template<typename Derived2> template<typename Derived2>
MatrixBase& operator+=(const MatrixBase<Derived2> &other); MatrixBase& operator+=(MatrixBase<Derived2> &other);
template<typename Derived2> template<typename Derived2>
MatrixBase& operator-=(const MatrixBase<Derived2> &other); MatrixBase& operator-=(MatrixBase<Derived2> &other);
protected: protected:
@ -223,7 +197,7 @@ MatrixXpr<Content>& MatrixXpr<Content>::operator=(const MatrixBase<Derived>& mat
assert(rows() == matrix.rows() && cols() == matrix.cols()); assert(rows() == matrix.rows() && cols() == matrix.cols());
for(int i = 0; i < rows(); i++) for(int i = 0; i < rows(); i++)
for(int j = 0; j < cols(); j++) for(int j = 0; j < cols(); j++)
this->operator()(i, j) = matrix(i, j); write(i, j) = matrix(i, j);
return *this; return *this;
} }
@ -245,14 +219,14 @@ std::ostream & operator <<
template<typename Content> template<typename Content>
std::ostream & operator << (std::ostream & s, std::ostream & operator << (std::ostream & s,
const MatrixConstXpr<Content>& m) const MatrixXpr<Content>& xpr)
{ {
for( int i = 0; i < m.rows(); i++ ) for( int i = 0; i < xpr.rows(); i++ )
{ {
s << m( i, 0 ); s << xpr.read(i, 0);
for (int j = 1; j < m.cols(); j++ ) for (int j = 1; j < xpr.cols(); j++ )
s << " " << m( i, j ); s << " " << xpr.read(i, j);
if( i < m.rows() - 1) if( i < xpr.rows() - 1)
s << std::endl; s << std::endl;
} }
return s; return s;
@ -291,9 +265,9 @@ template<typename Derived> class MatrixAlias
int rows() const { return m_tmp.rows(); } int rows() const { return m_tmp.rows(); }
int cols() const { return m_tmp.cols(); } 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() Ref ref()
@ -301,20 +275,29 @@ template<typename Derived> class MatrixAlias
return Ref(*this); return Ref(*this);
} }
MatrixXpr<MatrixRow<Xpr> > row(int i) { return xpr().row(i); };
MatrixXpr<MatrixCol<Xpr> > col(int i) { return xpr().col(i); };
MatrixXpr<MatrixMinor<Xpr> > minor(int row, int col) { return xpr().minor(row, col); };
MatrixXpr<MatrixBlock<Xpr> >
block(int startRow, int endRow, int startCol = 0, int endCol = 0)
{
return xpr().block(startRow, endRow, startCol, endCol);
}
template<typename XprContent> template<typename XprContent>
void operator=(const MatrixConstXpr<XprContent> &xpr) void operator=(const MatrixXpr<XprContent> &xpr)
{ {
ref().xpr() = xpr; ref().xpr() = xpr;
} }
template<typename XprContent> template<typename XprContent>
void operator+=(const MatrixConstXpr<XprContent> &xpr) void operator+=(const MatrixXpr<XprContent> &xpr)
{ {
ref().xpr() += xpr; ref().xpr() += xpr;
} }
template<typename XprContent> template<typename XprContent>
void operator-=(const MatrixConstXpr<XprContent> &xpr) void operator-=(const MatrixXpr<XprContent> &xpr)
{ {
ref().xpr() -= xpr; ref().xpr() -= xpr;
} }

View File

@ -46,9 +46,9 @@ template<typename Lhs, typename Rhs> class Matrix##NAME \
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(); } \
\ \
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: \ protected: \
@ -78,11 +78,11 @@ template<typename Lhs, typename Rhs> class MatrixProduct
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(); }
Scalar operator()(int row, int col) const Scalar read(int row, int col) const
{ {
Scalar x = static_cast<Scalar>(0); Scalar x = static_cast<Scalar>(0);
for(int i = 0; i < m_lhs.cols(); i++) 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; return x;
} }
@ -93,72 +93,72 @@ template<typename Lhs, typename Rhs> class MatrixProduct
#define EIGEN_MAKE_MATRIX_OP(NAME, SYMBOL) \ #define EIGEN_MAKE_MATRIX_OP(NAME, SYMBOL) \
template<typename Content1, typename Content2> \ template<typename Content1, typename Content2> \
const MatrixConstXpr< \ MatrixXpr< \
const Matrix##NAME< \ Matrix##NAME< \
MatrixConstXpr<Content1>, \ MatrixXpr<Content1>, \
MatrixConstXpr<Content2> \ MatrixXpr<Content2> \
> \ > \
> \ > \
operator SYMBOL(const MatrixConstXpr<Content1> &xpr1, const MatrixConstXpr<Content2> &xpr2) \ operator SYMBOL(const MatrixXpr<Content1> &xpr1, const MatrixXpr<Content2> &xpr2) \
{ \ { \
typedef const Matrix##NAME< \ typedef Matrix##NAME< \
MatrixConstXpr<Content1>, \ MatrixXpr<Content1>, \
MatrixConstXpr<Content2> \ MatrixXpr<Content2> \
> ProductType; \ > ProductType; \
typedef const MatrixConstXpr<ProductType> XprType; \ typedef MatrixXpr<ProductType> XprType; \
return XprType(ProductType(xpr1, xpr2)); \ return XprType(ProductType(xpr1, xpr2)); \
} \ } \
\ \
template<typename Derived, typename Content> \ template<typename Derived, typename Content> \
const MatrixConstXpr< \ MatrixXpr< \
const Matrix##NAME< \ Matrix##NAME< \
MatrixConstRef<MatrixBase<Derived> >, \ MatrixRef<MatrixBase<Derived> >, \
MatrixConstXpr<Content> \ MatrixXpr<Content> \
> \ > \
> \ > \
operator SYMBOL(const MatrixBase<Derived> &mat, const MatrixConstXpr<Content> &xpr) \ operator SYMBOL(MatrixBase<Derived> &mat, const MatrixXpr<Content> &xpr) \
{ \ { \
typedef const Matrix##NAME< \ typedef Matrix##NAME< \
MatrixConstRef<MatrixBase<Derived> >, \ MatrixRef<MatrixBase<Derived> >, \
MatrixConstXpr<Content> \ MatrixXpr<Content> \
> ProductType; \ > ProductType; \
typedef const MatrixConstXpr<ProductType> XprType; \ typedef MatrixXpr<ProductType> XprType; \
return XprType(ProductType(mat.constRef(), xpr)); \ return XprType(ProductType(mat.ref(), xpr)); \
} \ } \
\ \
template<typename Content, typename Derived> \ template<typename Content, typename Derived> \
const MatrixConstXpr< \ MatrixXpr< \
const Matrix##NAME< \ Matrix##NAME< \
MatrixConstXpr<Content>, \ MatrixXpr<Content>, \
MatrixConstRef<MatrixBase<Derived> > \ MatrixRef<MatrixBase<Derived> > \
> \ > \
> \ > \
operator SYMBOL(const MatrixConstXpr<Content> &xpr, const MatrixBase<Derived> &mat) \ operator SYMBOL(const MatrixXpr<Content> &xpr, MatrixBase<Derived> &mat) \
{ \ { \
typedef const Matrix##NAME< \ typedef Matrix##NAME< \
MatrixConstXpr<Content>, \ MatrixXpr<Content>, \
MatrixConstRef<MatrixBase<Derived> > \ MatrixRef<MatrixBase<Derived> > \
> ProductType; \ > ProductType; \
typedef const MatrixConstXpr<ProductType> XprType; \ typedef MatrixXpr<ProductType> XprType; \
return XprType(ProductType(xpr, mat.constRef())); \ return XprType(ProductType(xpr, mat.ref())); \
} \ } \
\ \
template<typename Derived1, typename Derived2> \ template<typename Derived1, typename Derived2> \
const MatrixConstXpr< \ MatrixXpr< \
const Matrix##NAME< \ Matrix##NAME< \
MatrixConstRef<MatrixBase<Derived1> >, \ MatrixRef<MatrixBase<Derived1> >, \
MatrixConstRef<MatrixBase<Derived2> > \ MatrixRef<MatrixBase<Derived2> > \
> \ > \
> \ > \
operator SYMBOL(const MatrixBase<Derived1> &mat1, const MatrixBase<Derived2> &mat2) \ operator SYMBOL(MatrixBase<Derived1> &mat1, MatrixBase<Derived2> &mat2) \
{ \ { \
typedef const Matrix##NAME< \ typedef Matrix##NAME< \
MatrixConstRef<MatrixBase<Derived1> >, \ MatrixRef<MatrixBase<Derived1> >, \
MatrixConstRef<MatrixBase<Derived2> > \ MatrixRef<MatrixBase<Derived2> > \
> ProductType; \ > ProductType; \
typedef const MatrixConstXpr<ProductType> XprType; \ typedef MatrixXpr<ProductType> XprType; \
return XprType(ProductType(MatrixConstRef<MatrixBase<Derived1> >(mat1), \ return XprType(ProductType(mat1.ref(), \
MatrixConstRef<MatrixBase<Derived2> >(mat2))); \ mat2.ref())); \
} }
EIGEN_MAKE_MATRIX_OP(Sum, +) EIGEN_MAKE_MATRIX_OP(Sum, +)
@ -171,7 +171,7 @@ EIGEN_MAKE_MATRIX_OP(Product, *)
template<typename Derived1> \ template<typename Derived1> \
template<typename Derived2> \ template<typename Derived2> \
MatrixBase<Derived1> & \ MatrixBase<Derived1> & \
MatrixBase<Derived1>::operator SYMBOL##=(const MatrixBase<Derived2> &mat2) \ MatrixBase<Derived1>::operator SYMBOL##=(MatrixBase<Derived2> &mat2) \
{ \ { \
return *this = *this SYMBOL mat2; \ return *this = *this SYMBOL mat2; \
} \ } \
@ -179,7 +179,7 @@ MatrixBase<Derived1>::operator SYMBOL##=(const MatrixBase<Derived2> &mat2) \
template<typename Derived> \ template<typename Derived> \
template<typename Content> \ template<typename Content> \
MatrixBase<Derived> & \ MatrixBase<Derived> & \
MatrixBase<Derived>::operator SYMBOL##=(const MatrixConstXpr<Content> &xpr) \ MatrixBase<Derived>::operator SYMBOL##=(const MatrixXpr<Content> &xpr) \
{ \ { \
return *this = *this SYMBOL xpr; \ return *this = *this SYMBOL xpr; \
} \ } \
@ -187,24 +187,24 @@ MatrixBase<Derived>::operator SYMBOL##=(const MatrixConstXpr<Content> &xpr) \
template<typename Content> \ template<typename Content> \
template<typename Derived> \ template<typename Derived> \
MatrixXpr<Content> & \ MatrixXpr<Content> & \
MatrixXpr<Content>::operator SYMBOL##=(const MatrixBase<Derived> &mat) \ MatrixXpr<Content>::operator SYMBOL##=(MatrixBase<Derived> &mat) \
{ \ { \
assert(rows() == mat.rows() && cols() == mat.cols()); \ assert(rows() == mat.rows() && cols() == mat.cols()); \
for(int i = 0; i < rows(); i++) \ for(int i = 0; i < rows(); i++) \
for(int j = 0; j < cols(); j++) \ 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; \ return *this; \
} \ } \
\ \
template<typename Content1> \ template<typename Content1> \
template<typename Content2> \ template<typename Content2> \
MatrixXpr<Content1> & \ MatrixXpr<Content1> & \
MatrixXpr<Content1>::operator SYMBOL##=(const MatrixConstXpr<Content2> &other) \ MatrixXpr<Content1>::operator SYMBOL##=(const MatrixXpr<Content2> &other) \
{ \ { \
assert(rows() == other.rows() && cols() == other.cols()); \ assert(rows() == other.rows() && cols() == other.cols()); \
for(int i = 0; i < rows(); i++) \ for(int i = 0; i < rows(); i++) \
for(int j = 0; j < cols(); j++) \ 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; \ return *this; \
} }

View File

@ -34,42 +34,6 @@ template<typename MatrixType> class MatrixCol;
template<typename MatrixType> class MatrixMinor; template<typename MatrixType> class MatrixMinor;
template<typename MatrixType> class MatrixBlock; template<typename MatrixType> class MatrixBlock;
template<typename Content> 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<MatrixRow<const MatrixConstXpr<Content> > > row(int i) const;
MatrixConstXpr<MatrixCol<const MatrixConstXpr<Content> > > col(int i) const;
MatrixConstXpr<MatrixMinor<const MatrixConstXpr<Content> > > minor(int row, int col) const;
MatrixConstXpr<MatrixBlock<const MatrixConstXpr<Content> > >
block(int startRow, int endRow, int startCol= 0, int endCol = 0) const;
protected:
const Content m_content;
};
template<typename Content> class MatrixXpr template<typename Content> class MatrixXpr
{ {
public: public:
@ -83,26 +47,35 @@ template<typename Content> class MatrixXpr
~MatrixXpr() {} ~MatrixXpr() {}
static bool hasDynamicSize()
{
return Content::hasDynamicSize();
}
int rows() const { return m_content.rows(); } int rows() const { return m_content.rows(); }
int cols() const { return m_content.cols(); } 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<typename OtherContent> template<typename OtherContent>
MatrixXpr& operator=(const MatrixConstXpr<OtherContent> &other) MatrixXpr& operator=(const MatrixXpr<OtherContent>& other)
{ {
assert(rows() == other.rows() && cols() == other.cols()); assert(rows() == other.rows() && cols() == other.cols());
for(int i = 0; i < rows(); i++) for(int i = 0; i < rows(); i++)
for(int j = 0; j < cols(); j++) 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; return *this;
} }
@ -116,17 +89,13 @@ template<typename Content> class MatrixXpr
block(int startRow, int endRow, int startCol= 0, int endCol = 0); block(int startRow, int endRow, int startCol= 0, int endCol = 0);
template<typename Content2> template<typename Content2>
MatrixXpr& operator+=(const MatrixConstXpr<Content2> &other); MatrixXpr& operator+=(const MatrixXpr<Content2> &other);
template<typename Content2> template<typename Content2>
MatrixXpr& operator-=(const MatrixConstXpr<Content2> &other); MatrixXpr& operator-=(const MatrixXpr<Content2> &other);
template<typename Derived> template<typename Derived>
MatrixXpr& operator+=(const MatrixBase<Derived> &matrix); MatrixXpr& operator+=(MatrixBase<Derived> &matrix);
template<typename Derived> template<typename Derived>
MatrixXpr& operator-=(const MatrixBase<Derived> &matrix); MatrixXpr& operator-=(MatrixBase<Derived> &matrix);
private:
void operator=(const MatrixXpr &other)
{}
protected: protected:
Content m_content; Content m_content;

View File

@ -45,14 +45,14 @@ template<typename MatrixType> class MatrixMinor
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& 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: protected:
@ -61,33 +61,18 @@ template<typename MatrixType> class MatrixMinor
}; };
template<typename Derived> template<typename Derived>
MatrixConstXpr< MatrixXpr<
MatrixMinor< MatrixMinor<
const MatrixConstRef< MatrixRef<
MatrixBase<Derived> MatrixBase<Derived>
> >
> >
> >
MatrixBase<Derived>::minor(int row, int col) const MatrixBase<Derived>::minor(int row, int col)
{ {
typedef MatrixMinor<const ConstRef> ProductType; typedef MatrixMinor<Ref> ProductType;
typedef MatrixConstXpr<ProductType> XprType; typedef MatrixXpr<ProductType> XprType;
return XprType(ProductType(constRef(), row, col)); return XprType(ProductType(ref(), row, col));
}
template<typename Content>
MatrixConstXpr<
MatrixMinor<
const MatrixConstXpr<Content>
>
>
MatrixConstXpr<Content>::minor(int row, int col) const
{
typedef MatrixMinor<
const MatrixConstXpr<Content>
> ProductType;
typedef MatrixConstXpr<ProductType> XprType;
return XprType(ProductType(*this, row, col));
} }
template<typename Content> template<typename Content>

View File

@ -45,18 +45,18 @@ template<typename MatrixType> class MatrixRow
int rows() const { return m_matrix.cols(); } int rows() const { return m_matrix.cols(); }
int cols() const { return 1; } int cols() const { return 1; }
Scalar& operator()(int row, int col=0) Scalar& write(int row, int col=0)
{ {
EIGEN_UNUSED(col); EIGEN_UNUSED(col);
EIGEN_CHECK_ROW_RANGE(*this, row); 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_UNUSED(col);
EIGEN_CHECK_ROW_RANGE(*this, row); EIGEN_CHECK_ROW_RANGE(*this, row);
return m_matrix(m_row, row); return m_matrix.read(m_row, row);
} }
protected: protected:
@ -81,18 +81,18 @@ template<typename MatrixType> class MatrixCol
int rows() const { return m_matrix.rows(); } int rows() const { return m_matrix.rows(); }
int cols() const { return 1; } int cols() const { return 1; }
Scalar& operator()(int row, int col=0) Scalar& write(int row, int col=0)
{ {
EIGEN_UNUSED(col); EIGEN_UNUSED(col);
EIGEN_CHECK_ROW_RANGE(*this, row); 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_UNUSED(col);
EIGEN_CHECK_ROW_RANGE(*this, row); EIGEN_CHECK_ROW_RANGE(*this, row);
return m_matrix(row, m_col); return m_matrix.read(row, m_col);
} }
protected: protected:
@ -102,33 +102,18 @@ template<typename MatrixType> class MatrixCol
#define EIGEN_MAKE_ROW_COL_FUNCTIONS(func, Func) \ #define EIGEN_MAKE_ROW_COL_FUNCTIONS(func, Func) \
template<typename Derived> \ template<typename Derived> \
MatrixConstXpr< \ MatrixXpr< \
Matrix##Func< \ Matrix##Func< \
const MatrixConstRef< \ MatrixRef< \
MatrixBase<Derived> \ MatrixBase<Derived> \
> \ > \
> \ > \
> \ > \
MatrixBase<Derived>::func(int i) const\ MatrixBase<Derived>::func(int i)\
{ \ { \
typedef Matrix##Func<const ConstRef> ProductType; \ typedef Matrix##Func<Ref> ProductType; \
typedef MatrixConstXpr<ProductType> XprType; \ typedef MatrixXpr<ProductType> XprType; \
return XprType(ProductType(constRef(), i)); \ return XprType(ProductType(ref(), i)); \
} \
\
template<typename Content> \
MatrixConstXpr< \
Matrix##Func< \
const MatrixConstXpr<Content> \
> \
> \
MatrixConstXpr<Content>::func(int i) const\
{ \
typedef Matrix##Func< \
const MatrixConstXpr<Content> \
> ProductType; \
typedef MatrixConstXpr<ProductType> XprType; \
return XprType(ProductType(*this, i)); \
} \ } \
\ \
template<typename Content> \ template<typename Content> \

View File

@ -42,9 +42,9 @@ template<typename MatrixType> class ScalarProduct
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(); }
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: protected:
@ -53,88 +53,88 @@ template<typename MatrixType> class ScalarProduct
}; };
template<typename Content> template<typename Content>
const MatrixConstXpr< MatrixXpr<
const ScalarProduct< ScalarProduct<
MatrixConstXpr<Content> MatrixXpr<Content>
> >
> >
operator *(const MatrixConstXpr<Content>& xpr, operator *(const MatrixXpr<Content>& xpr,
typename Content::Scalar scalar) typename Content::Scalar scalar)
{ {
typedef const ScalarProduct< typedef ScalarProduct<
MatrixConstXpr<Content> MatrixXpr<Content>
> ProductType; > ProductType;
typedef const MatrixConstXpr<ProductType> XprType; typedef MatrixXpr<ProductType> XprType;
return XprType(ProductType(xpr, scalar)); return XprType(ProductType(xpr, scalar));
} }
template<typename Content> template<typename Content>
const MatrixConstXpr< MatrixXpr<
const ScalarProduct< ScalarProduct<
MatrixConstXpr<Content> MatrixXpr<Content>
> >
> >
operator *(typename Content::Scalar scalar, operator *(typename Content::Scalar scalar,
const MatrixConstXpr<Content>& xpr) const MatrixXpr<Content>& xpr)
{ {
typedef const ScalarProduct< typedef ScalarProduct<
MatrixConstXpr<Content> MatrixXpr<Content>
> ProductType; > ProductType;
typedef const MatrixConstXpr<ProductType> XprType; typedef MatrixXpr<ProductType> XprType;
return XprType(ProductType(xpr, scalar)); return XprType(ProductType(xpr, scalar));
} }
template<typename Derived> template<typename Derived>
const MatrixConstXpr< MatrixXpr<
const ScalarProduct< ScalarProduct<
MatrixConstRef<MatrixBase<Derived> > MatrixRef<MatrixBase<Derived> >
> >
> >
operator *(const MatrixBase<Derived>& matrix, operator *(MatrixBase<Derived>& matrix,
typename Derived::Scalar scalar) typename Derived::Scalar scalar)
{ {
typedef const ScalarProduct< typedef ScalarProduct<
MatrixConstRef<MatrixBase<Derived> > MatrixRef<MatrixBase<Derived> >
> ProductType; > ProductType;
typedef const MatrixConstXpr<ProductType> XprType; typedef MatrixXpr<ProductType> XprType;
return XprType(ProductType(matrix.constRef(), scalar)); return XprType(ProductType(matrix.ref(), scalar));
} }
template<typename Derived> template<typename Derived>
const MatrixConstXpr< MatrixXpr<
const ScalarProduct< ScalarProduct<
MatrixConstRef<MatrixBase<Derived> > MatrixRef<MatrixBase<Derived> >
> >
> >
operator *(typename Derived::Scalar scalar, operator *(typename Derived::Scalar scalar,
const MatrixBase<Derived>& matrix) MatrixBase<Derived>& matrix)
{ {
typedef const ScalarProduct< typedef ScalarProduct<
MatrixConstRef<MatrixBase<Derived> > MatrixRef<MatrixBase<Derived> >
> ProductType; > ProductType;
typedef const MatrixConstXpr<ProductType> XprType; typedef MatrixXpr<ProductType> XprType;
return XprType(ProductType(matrix.constRef(), scalar)); return XprType(ProductType(matrix.ref(), scalar));
} }
template<typename Content> template<typename Content>
const MatrixConstXpr< MatrixXpr<
const ScalarProduct< ScalarProduct<
MatrixConstXpr<Content> MatrixXpr<Content>
> >
> >
operator /(const MatrixConstXpr<Content>& xpr, operator /(MatrixXpr<Content>& xpr,
typename Content::Scalar scalar) typename Content::Scalar scalar)
{ {
return xpr * (static_cast<typename Content::Scalar>(1) / scalar); return xpr * (static_cast<typename Content::Scalar>(1) / scalar);
} }
template<typename Derived> template<typename Derived>
const MatrixConstXpr< MatrixXpr<
const ScalarProduct< ScalarProduct<
MatrixConstRef<MatrixBase<Derived> > MatrixRef<MatrixBase<Derived> >
> >
> >
operator /(const MatrixBase<Derived>& matrix, operator /(MatrixBase<Derived>& matrix,
typename Derived::Scalar scalar) typename Derived::Scalar scalar)
{ {
return matrix * (static_cast<typename Derived::Scalar>(1) / scalar); return matrix * (static_cast<typename Derived::Scalar>(1) / scalar);

View File

@ -84,13 +84,13 @@ class Vector: public MatrixBase<Vector<T, Size> >
{ Base::operator=(other); } { Base::operator=(other); }
template<typename XprContent> template<typename XprContent>
void operator=(const MatrixConstXpr<XprContent> &xpr) void operator=(const MatrixXpr<XprContent> &xpr)
{ {
Base::operator=(xpr); Base::operator=(xpr);
} }
template<typename XprContent> template<typename XprContent>
explicit Vector(const MatrixConstXpr<XprContent>& xpr) explicit Vector(const MatrixXpr<XprContent>& xpr)
{ {
*this = xpr; *this = xpr;
} }
@ -131,13 +131,13 @@ class VectorX : public MatrixBase<VectorX<T> >
} }
template<typename XprContent> template<typename XprContent>
void operator=(const MatrixConstXpr<XprContent> &xpr) void operator=(const MatrixXpr<XprContent> &xpr)
{ {
Base::operator=(xpr); Base::operator=(xpr);
} }
template<typename XprContent> template<typename XprContent>
explicit VectorX(const MatrixConstXpr<XprContent>& xpr) explicit VectorX(const MatrixXpr<XprContent>& xpr)
{ {
_init(xpr.rows()); _init(xpr.rows());
*this = xpr; *this = xpr;

View File

@ -35,10 +35,10 @@ template<typename MatrixType> void matrixManip(const MatrixType& m)
a.col(j); a.col(j);
a.minor(i, j); a.minor(i, j);
a.block(1, rows-1, 1, cols-1); a.block(1, rows-1, 1, cols-1);
a.xpr().row(i) = b.row(i); a.row(i) = b.row(i);
a.xpr().row(i) += b.row(i); a.row(i) += b.row(i);
a.xpr().minor(i, j) = b.block(1, rows-1, 1, cols-1); a.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.alias().minor(i, j) -= a.block(1, rows-1, 1, cols-1);
} }
void EigenTest::testMatrixManip() void EigenTest::testMatrixManip()