Give the axe to the aliasing system.

Improve the evaluation system instead.
This commit is contained in:
Benoit Jacob 2007-09-26 14:06:26 +00:00
parent 55227b1f63
commit a2dd9dd6f9
11 changed files with 29 additions and 95 deletions

View File

@ -12,9 +12,9 @@ int main(int, char **)
m(1,1) = 4;
n = m;
n = eval(n*n);
n = eval(n*n+n);
cout << n << endl;
#if 0
cout << "Here is a 2x2 matrix m:" << endl << m << endl;
cout << "Let us now build a 4x4 matrix m2 by assembling together four 2x2 blocks." << endl;
Matrix<double,4,4> m2; // dynamic matrix with initial size 4x4 and uninitialized entries
@ -50,10 +50,9 @@ int main(int, char **)
<< "overwritten _while_ the matrix product m * m is being computed." << endl
<< "This is the counterpart of eliminating temporary objects!" << endl
<< "Anyway, if you want to store m * m into m, you can do this:" << endl
<< " m.alias() = m * m;" << endl;
<< " m = eval(m * m);" << endl;
m = m_save;
m.alias() = m * m;
m = eval(m * m);
cout << "And m is now:" << endl << m << endl << "as was expected." << endl;
#endif
return 0;
}

View File

@ -36,6 +36,9 @@ template<typename MatrixType> class MatrixBlock
typedef typename MatrixType::Ref MatRef;
friend class EigenBase<Scalar, MatrixBlock<MatrixType> >;
typedef MatrixBlock Ref;
static const int RowsAtCompileTime = DynamicSize,
ColsAtCompileTime = DynamicSize;
MatrixBlock(const MatRef& matrix,
int startRow, int endRow,

View File

@ -125,7 +125,6 @@ EIGEN_MAKE_TYPEDEFS_ALL_SIZES(std::complex<double>, cd)
} // namespace Eigen
#include "MatrixAlias.h"
#include "MatrixOps.h"
#include "ScalarOps.h"
#include "RowAndCol.h"

View File

@ -1,84 +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-2007 Benoit Jacob <jacob@math.jussieu.fr>
//
// Eigen is free software; 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 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 General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along
// with Eigen; if not, write to the Free Software Foundation, Inc., 51
// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. This exception does not invalidate any other reasons why a work
// based on this file might be covered by the GNU General Public License.
#ifndef EIGEN_MATRIXALIAS_H
#define EIGEN_MATRIXALIAS_H
namespace Eigen
{
template<typename MatrixType> class MatrixAlias
: public EigenBase<typename MatrixType::Scalar, MatrixAlias<MatrixType> >
{
public:
typedef typename MatrixType::Scalar Scalar;
typedef MatrixRef<MatrixAlias> Ref;
typedef EigenBase<typename MatrixType::Scalar, MatrixAlias> Base;
friend class EigenBase<typename MatrixType::Scalar, MatrixAlias>;
MatrixAlias(MatrixType& matrix) : m_aliased(matrix), m_tmp(matrix) {}
MatrixAlias(const MatrixAlias& other) : m_aliased(other.m_aliased), m_tmp(other.m_tmp) {}
~MatrixAlias()
{
m_aliased = m_tmp;
}
INHERIT_ASSIGNMENT_OPERATORS(MatrixAlias)
private:
Ref _ref() const
{
return Ref(*const_cast<MatrixAlias*>(this));
}
int _rows() const { return m_tmp.rows(); }
int _cols() const { return m_tmp.cols(); }
Scalar& _write(int row, int col)
{
return m_tmp.write(row, col);
}
Scalar _read(int row, int col) const
{
return m_aliased.read(row, col);
}
protected:
MatrixRef<MatrixType> m_aliased;
MatrixType m_tmp;
};
template<typename _Scalar, int _Rows, int _Cols>
typename Matrix<_Scalar, _Rows, _Cols>::Alias
Matrix<_Scalar, _Rows, _Cols>::alias()
{
return Alias(*this);
}
} // namespace Eigen
#endif // EIGEN_MATRIXALIAS_H

View File

@ -37,6 +37,9 @@ template<typename Lhs, typename Rhs> class MatrixSum
typedef typename Rhs::Ref RhsRef;
friend class EigenBase<Scalar, MatrixSum>;
typedef MatrixSum Ref;
static const int RowsAtCompileTime = Lhs::RowsAtCompileTime,
ColsAtCompileTime = Rhs::ColsAtCompileTime;
MatrixSum(const LhsRef& lhs, const RhsRef& rhs)
: m_lhs(lhs), m_rhs(rhs)
@ -75,6 +78,9 @@ template<typename Lhs, typename Rhs> class MatrixDifference
friend class EigenBase<Scalar, MatrixDifference>;
typedef MatrixDifference Ref;
static const int RowsAtCompileTime = Lhs::RowsAtCompileTime,
ColsAtCompileTime = Rhs::ColsAtCompileTime;
MatrixDifference(const LhsRef& lhs, const RhsRef& rhs)
: m_lhs(lhs), m_rhs(rhs)
{

View File

@ -36,6 +36,9 @@ template<typename MatrixType> class MatrixMinor
typedef typename MatrixType::Ref MatRef;
friend class EigenBase<Scalar, MatrixMinor<MatrixType> >;
typedef MatrixMinor Ref;
static const int RowsAtCompileTime = MatrixType::RowsAtCompileTime - 1,
ColsAtCompileTime = MatrixType::ColsAtCompileTime - 1;
MatrixMinor(const MatRef& matrix,
int row, int col = 0)

View File

@ -37,6 +37,9 @@ template<typename MatrixType> class MatrixRow
friend class EigenBase<Scalar, MatrixRow<MatrixType> >;
typedef MatrixRow Ref;
static const int RowsAtCompileTime = MatrixType::ColsAtCompileTime,
ColsAtCompileTime = 1;
MatrixRow(const MatRef& matrix, int row)
: m_matrix(matrix), m_row(row)
{
@ -88,6 +91,9 @@ template<typename MatrixType> class MatrixCol
friend class EigenBase<Scalar, MatrixCol<MatrixType> >;
typedef MatrixCol Ref;
static const int RowsAtCompileTime = MatrixType::RowsAtCompileTime,
ColsAtCompileTime = 1;
MatrixCol(const MatRef& matrix, int col)
: m_matrix(matrix), m_col(col)
{

View File

@ -37,6 +37,9 @@ template<typename MatrixType> class ScalarProduct
typedef ScalarProduct Ref;
friend class EigenBase<typename MatrixType::Scalar, ScalarProduct<MatrixType> >;
static const int RowsAtCompileTime = MatrixType::RowsAtCompileTime,
ColsAtCompileTime = MatrixType::ColsAtCompileTime;
ScalarProduct(const MatRef& matrix, Scalar scalar)
: m_matrix(matrix), m_scalar(scalar) {}

View File

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

View File

@ -44,10 +44,9 @@ template<typename MatrixType1,
a = b;
a = b + c;
a = s * (b - c);
a.alias() = a + b;
a = eval(a + b);
a += b;
a.alias() += b;
a -= b + b;
MatrixType1 d(rows1, cols1);

View File

@ -42,11 +42,11 @@ template<typename VectorType> void vectorOps(const VectorType& v)
a = b;
a = b + c;
a = s * (b - c);
a.alias() = a + b;
a = eval(s * (b - c));
a += b;
a += b + b;
a.alias() += a + a;
a += eval(a + a);
}
void EigenTest::testVectorOps()