2
0
mirror of https://gitlab.com/libeigen/eigen.git synced 2024-12-15 07:10:37 +08:00

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 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<typename MatrixType> class MatrixBlock
};
template<typename Derived>
MatrixConstXpr<
MatrixXpr<
MatrixBlock<
const MatrixConstRef<
MatrixRef<
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 MatrixConstXpr<ProductType> XprType;
return XprType(ProductType(constRef(), 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));
typedef MatrixBlock<Ref> ProductType;
typedef MatrixXpr<ProductType> XprType;
return XprType(ProductType(ref(), startRow, endRow, startCol, endCol));
}
template<typename Content>

View File

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

View File

@ -32,37 +32,6 @@
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
{
public:
@ -86,12 +55,15 @@ template<typename MatrixType> 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<Derived>::Scalar Scalar;
typedef MatrixConstRef<MatrixBase<Derived> > ConstRef;
typedef MatrixRef<MatrixBase<Derived> > Ref;
typedef MatrixConstXpr<ConstRef> ConstXpr;
typedef MatrixXpr<Ref> Xpr;
typedef MatrixAlias<Derived> 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<Derived*>(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<typename XprContent>
MatrixBase& operator=(const MatrixConstXpr<XprContent> &otherXpr)
MatrixBase& operator=(const MatrixXpr<XprContent> &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<MatrixRow<const ConstRef> > row(int i) const;
MatrixConstXpr<MatrixCol<const ConstRef> > col(int i) const;
MatrixConstXpr<MatrixMinor<const ConstRef> > minor(int row, int col) const;
MatrixConstXpr<MatrixBlock<const ConstRef> >
block(int startRow, int endRow, int startCol = 0, int endCol = 0) const;
MatrixXpr<MatrixRow<Ref> > row(int i);
MatrixXpr<MatrixCol<Ref> > col(int i);
MatrixXpr<MatrixMinor<Ref> > minor(int row, int col);
MatrixXpr<MatrixBlock<Ref> >
block(int startRow, int endRow, int startCol = 0, int endCol = 0);
template<typename Content>
MatrixBase& operator+=(const MatrixConstXpr<Content> &xpr);
MatrixBase& operator+=(const MatrixXpr<Content> &xpr);
template<typename Content>
MatrixBase& operator-=(const MatrixConstXpr<Content> &xpr);
MatrixBase& operator-=(const MatrixXpr<Content> &xpr);
template<typename Derived2>
MatrixBase& operator+=(const MatrixBase<Derived2> &other);
MatrixBase& operator+=(MatrixBase<Derived2> &other);
template<typename Derived2>
MatrixBase& operator-=(const MatrixBase<Derived2> &other);
MatrixBase& operator-=(MatrixBase<Derived2> &other);
protected:
@ -223,7 +197,7 @@ MatrixXpr<Content>& MatrixXpr<Content>::operator=(const MatrixBase<Derived>& 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<typename Content>
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 );
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<typename Derived> 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<typename Derived> class MatrixAlias
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>
void operator=(const MatrixConstXpr<XprContent> &xpr)
void operator=(const MatrixXpr<XprContent> &xpr)
{
ref().xpr() = xpr;
}
template<typename XprContent>
void operator+=(const MatrixConstXpr<XprContent> &xpr)
void operator+=(const MatrixXpr<XprContent> &xpr)
{
ref().xpr() += xpr;
}
template<typename XprContent>
void operator-=(const MatrixConstXpr<XprContent> &xpr)
void operator-=(const MatrixXpr<XprContent> &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 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<typename Lhs, typename Rhs> 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<Scalar>(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<typename Lhs, typename Rhs> class MatrixProduct
#define EIGEN_MAKE_MATRIX_OP(NAME, SYMBOL) \
template<typename Content1, typename Content2> \
const MatrixConstXpr< \
const Matrix##NAME< \
MatrixConstXpr<Content1>, \
MatrixConstXpr<Content2> \
MatrixXpr< \
Matrix##NAME< \
MatrixXpr<Content1>, \
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< \
MatrixConstXpr<Content1>, \
MatrixConstXpr<Content2> \
> ProductType; \
typedef const MatrixConstXpr<ProductType> XprType; \
typedef Matrix##NAME< \
MatrixXpr<Content1>, \
MatrixXpr<Content2> \
> ProductType; \
typedef MatrixXpr<ProductType> XprType; \
return XprType(ProductType(xpr1, xpr2)); \
} \
\
template<typename Derived, typename Content> \
const MatrixConstXpr< \
const Matrix##NAME< \
MatrixConstRef<MatrixBase<Derived> >, \
MatrixConstXpr<Content> \
MatrixXpr< \
Matrix##NAME< \
MatrixRef<MatrixBase<Derived> >, \
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< \
MatrixConstRef<MatrixBase<Derived> >, \
MatrixConstXpr<Content> \
> ProductType; \
typedef const MatrixConstXpr<ProductType> XprType; \
return XprType(ProductType(mat.constRef(), xpr)); \
typedef Matrix##NAME< \
MatrixRef<MatrixBase<Derived> >, \
MatrixXpr<Content> \
> ProductType; \
typedef MatrixXpr<ProductType> XprType; \
return XprType(ProductType(mat.ref(), xpr)); \
} \
\
template<typename Content, typename Derived> \
const MatrixConstXpr< \
const Matrix##NAME< \
MatrixConstXpr<Content>, \
MatrixConstRef<MatrixBase<Derived> > \
MatrixXpr< \
Matrix##NAME< \
MatrixXpr<Content>, \
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< \
MatrixConstXpr<Content>, \
MatrixConstRef<MatrixBase<Derived> > \
> ProductType; \
typedef const MatrixConstXpr<ProductType> XprType; \
return XprType(ProductType(xpr, mat.constRef())); \
typedef Matrix##NAME< \
MatrixXpr<Content>, \
MatrixRef<MatrixBase<Derived> > \
> ProductType; \
typedef MatrixXpr<ProductType> XprType; \
return XprType(ProductType(xpr, mat.ref())); \
} \
\
template<typename Derived1, typename Derived2> \
const MatrixConstXpr< \
const Matrix##NAME< \
MatrixConstRef<MatrixBase<Derived1> >, \
MatrixConstRef<MatrixBase<Derived2> > \
MatrixXpr< \
Matrix##NAME< \
MatrixRef<MatrixBase<Derived1> >, \
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< \
MatrixConstRef<MatrixBase<Derived1> >, \
MatrixConstRef<MatrixBase<Derived2> > \
typedef Matrix##NAME< \
MatrixRef<MatrixBase<Derived1> >, \
MatrixRef<MatrixBase<Derived2> > \
> ProductType; \
typedef const MatrixConstXpr<ProductType> XprType; \
return XprType(ProductType(MatrixConstRef<MatrixBase<Derived1> >(mat1), \
MatrixConstRef<MatrixBase<Derived2> >(mat2))); \
typedef MatrixXpr<ProductType> XprType; \
return XprType(ProductType(mat1.ref(), \
mat2.ref())); \
}
EIGEN_MAKE_MATRIX_OP(Sum, +)
@ -171,7 +171,7 @@ EIGEN_MAKE_MATRIX_OP(Product, *)
template<typename Derived1> \
template<typename Derived2> \
MatrixBase<Derived1> & \
MatrixBase<Derived1>::operator SYMBOL##=(const MatrixBase<Derived2> &mat2) \
MatrixBase<Derived1>::operator SYMBOL##=(MatrixBase<Derived2> &mat2) \
{ \
return *this = *this SYMBOL mat2; \
} \
@ -179,7 +179,7 @@ MatrixBase<Derived1>::operator SYMBOL##=(const MatrixBase<Derived2> &mat2) \
template<typename Derived> \
template<typename Content> \
MatrixBase<Derived> & \
MatrixBase<Derived>::operator SYMBOL##=(const MatrixConstXpr<Content> &xpr) \
MatrixBase<Derived>::operator SYMBOL##=(const MatrixXpr<Content> &xpr) \
{ \
return *this = *this SYMBOL xpr; \
} \
@ -187,24 +187,24 @@ MatrixBase<Derived>::operator SYMBOL##=(const MatrixConstXpr<Content> &xpr) \
template<typename Content> \
template<typename Derived> \
MatrixXpr<Content> & \
MatrixXpr<Content>::operator SYMBOL##=(const MatrixBase<Derived> &mat) \
MatrixXpr<Content>::operator SYMBOL##=(MatrixBase<Derived> &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<typename Content1> \
template<typename Content2> \
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()); \
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; \
}

View File

@ -34,42 +34,6 @@ template<typename MatrixType> class MatrixCol;
template<typename MatrixType> class MatrixMinor;
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
{
public:
@ -83,26 +47,35 @@ template<typename Content> 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<typename OtherContent>
MatrixXpr& operator=(const MatrixConstXpr<OtherContent> &other)
MatrixXpr& operator=(const MatrixXpr<OtherContent>& 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<typename Content> class MatrixXpr
block(int startRow, int endRow, int startCol= 0, int endCol = 0);
template<typename Content2>
MatrixXpr& operator+=(const MatrixConstXpr<Content2> &other);
MatrixXpr& operator+=(const MatrixXpr<Content2> &other);
template<typename Content2>
MatrixXpr& operator-=(const MatrixConstXpr<Content2> &other);
MatrixXpr& operator-=(const MatrixXpr<Content2> &other);
template<typename Derived>
MatrixXpr& operator+=(const MatrixBase<Derived> &matrix);
MatrixXpr& operator+=(MatrixBase<Derived> &matrix);
template<typename Derived>
MatrixXpr& operator-=(const MatrixBase<Derived> &matrix);
private:
void operator=(const MatrixXpr &other)
{}
MatrixXpr& operator-=(MatrixBase<Derived> &matrix);
protected:
Content m_content;

View File

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

View File

@ -45,18 +45,18 @@ template<typename MatrixType> 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<typename MatrixType> 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<typename MatrixType> class MatrixCol
#define EIGEN_MAKE_ROW_COL_FUNCTIONS(func, Func) \
template<typename Derived> \
MatrixConstXpr< \
MatrixXpr< \
Matrix##Func< \
const MatrixConstRef< \
MatrixRef< \
MatrixBase<Derived> \
> \
> \
> \
MatrixBase<Derived>::func(int i) const\
MatrixBase<Derived>::func(int i)\
{ \
typedef Matrix##Func<const ConstRef> ProductType; \
typedef MatrixConstXpr<ProductType> XprType; \
return XprType(ProductType(constRef(), 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)); \
typedef Matrix##Func<Ref> ProductType; \
typedef MatrixXpr<ProductType> XprType; \
return XprType(ProductType(ref(), i)); \
} \
\
template<typename Content> \
@ -137,7 +122,7 @@ MatrixXpr< \
MatrixXpr<Content> \
> \
> \
MatrixXpr<Content>::func(int i) \
MatrixXpr<Content>::func(int i)\
{ \
typedef Matrix##Func< \
MatrixXpr<Content> \

View File

@ -42,9 +42,9 @@ template<typename MatrixType> 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<typename MatrixType> class ScalarProduct
};
template<typename Content>
const MatrixConstXpr<
const ScalarProduct<
MatrixConstXpr<Content>
MatrixXpr<
ScalarProduct<
MatrixXpr<Content>
>
>
operator *(const MatrixConstXpr<Content>& xpr,
typename Content::Scalar scalar)
operator *(const MatrixXpr<Content>& xpr,
typename Content::Scalar scalar)
{
typedef const ScalarProduct<
MatrixConstXpr<Content>
> ProductType;
typedef const MatrixConstXpr<ProductType> XprType;
typedef ScalarProduct<
MatrixXpr<Content>
> ProductType;
typedef MatrixXpr<ProductType> XprType;
return XprType(ProductType(xpr, scalar));
}
template<typename Content>
const MatrixConstXpr<
const ScalarProduct<
MatrixConstXpr<Content>
MatrixXpr<
ScalarProduct<
MatrixXpr<Content>
>
>
operator *(typename Content::Scalar scalar,
const MatrixConstXpr<Content>& xpr)
const MatrixXpr<Content>& xpr)
{
typedef const ScalarProduct<
MatrixConstXpr<Content>
> ProductType;
typedef const MatrixConstXpr<ProductType> XprType;
typedef ScalarProduct<
MatrixXpr<Content>
> ProductType;
typedef MatrixXpr<ProductType> XprType;
return XprType(ProductType(xpr, scalar));
}
template<typename Derived>
const MatrixConstXpr<
const ScalarProduct<
MatrixConstRef<MatrixBase<Derived> >
MatrixXpr<
ScalarProduct<
MatrixRef<MatrixBase<Derived> >
>
>
operator *(const MatrixBase<Derived>& matrix,
typename Derived::Scalar scalar)
operator *(MatrixBase<Derived>& matrix,
typename Derived::Scalar scalar)
{
typedef const ScalarProduct<
MatrixConstRef<MatrixBase<Derived> >
typedef ScalarProduct<
MatrixRef<MatrixBase<Derived> >
> ProductType;
typedef const MatrixConstXpr<ProductType> XprType;
return XprType(ProductType(matrix.constRef(), scalar));
typedef MatrixXpr<ProductType> XprType;
return XprType(ProductType(matrix.ref(), scalar));
}
template<typename Derived>
const MatrixConstXpr<
const ScalarProduct<
MatrixConstRef<MatrixBase<Derived> >
MatrixXpr<
ScalarProduct<
MatrixRef<MatrixBase<Derived> >
>
>
operator *(typename Derived::Scalar scalar,
const MatrixBase<Derived>& matrix)
MatrixBase<Derived>& matrix)
{
typedef const ScalarProduct<
MatrixConstRef<MatrixBase<Derived> >
> ProductType;
typedef const MatrixConstXpr<ProductType> XprType;
return XprType(ProductType(matrix.constRef(), scalar));
typedef ScalarProduct<
MatrixRef<MatrixBase<Derived> >
> ProductType;
typedef MatrixXpr<ProductType> XprType;
return XprType(ProductType(matrix.ref(), scalar));
}
template<typename Content>
const MatrixConstXpr<
const ScalarProduct<
MatrixConstXpr<Content>
MatrixXpr<
ScalarProduct<
MatrixXpr<Content>
>
>
operator /(const MatrixConstXpr<Content>& xpr,
typename Content::Scalar scalar)
operator /(MatrixXpr<Content>& xpr,
typename Content::Scalar scalar)
{
return xpr * (static_cast<typename Content::Scalar>(1) / scalar);
}
template<typename Derived>
const MatrixConstXpr<
const ScalarProduct<
MatrixConstRef<MatrixBase<Derived> >
MatrixXpr<
ScalarProduct<
MatrixRef<MatrixBase<Derived> >
>
>
operator /(const MatrixBase<Derived>& matrix,
typename Derived::Scalar scalar)
operator /(MatrixBase<Derived>& matrix,
typename Derived::Scalar 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); }
template<typename XprContent>
void operator=(const MatrixConstXpr<XprContent> &xpr)
void operator=(const MatrixXpr<XprContent> &xpr)
{
Base::operator=(xpr);
}
template<typename XprContent>
explicit Vector(const MatrixConstXpr<XprContent>& xpr)
explicit Vector(const MatrixXpr<XprContent>& xpr)
{
*this = xpr;
}
@ -131,13 +131,13 @@ class VectorX : public MatrixBase<VectorX<T> >
}
template<typename XprContent>
void operator=(const MatrixConstXpr<XprContent> &xpr)
void operator=(const MatrixXpr<XprContent> &xpr)
{
Base::operator=(xpr);
}
template<typename XprContent>
explicit VectorX(const MatrixConstXpr<XprContent>& xpr)
explicit VectorX(const MatrixXpr<XprContent>& xpr)
{
_init(xpr.rows());
*this = xpr;

View File

@ -35,10 +35,10 @@ template<typename MatrixType> 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()