From a2dd9dd6f9a9b6f45e79082e4d8a3577dd4246b6 Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Wed, 26 Sep 2007 14:06:26 +0000 Subject: Give the axe to the aliasing system. Improve the evaluation system instead. --- doc/tutorial.cpp | 9 +++-- src/internal/Block.h | 3 ++ src/internal/Matrix.h | 1 - src/internal/MatrixAlias.h | 84 ---------------------------------------------- src/internal/MatrixOps.h | 6 ++++ src/internal/Minor.h | 3 ++ src/internal/RowAndCol.h | 6 ++++ src/internal/ScalarOps.h | 3 ++ test/matrixmanip.cpp | 2 +- test/matrixops.cpp | 3 +- test/vectorops.cpp | 4 +-- 11 files changed, 29 insertions(+), 95 deletions(-) delete mode 100644 src/internal/MatrixAlias.h diff --git a/doc/tutorial.cpp b/doc/tutorial.cpp index e37c245cc..2d881cda2 100644 --- a/doc/tutorial.cpp +++ b/doc/tutorial.cpp @@ -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 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; } diff --git a/src/internal/Block.h b/src/internal/Block.h index dde15b0c0..cd4422887 100644 --- a/src/internal/Block.h +++ b/src/internal/Block.h @@ -36,6 +36,9 @@ template class MatrixBlock typedef typename MatrixType::Ref MatRef; friend class EigenBase >; typedef MatrixBlock Ref; + + static const int RowsAtCompileTime = DynamicSize, + ColsAtCompileTime = DynamicSize; MatrixBlock(const MatRef& matrix, int startRow, int endRow, diff --git a/src/internal/Matrix.h b/src/internal/Matrix.h index a6efcd866..a4018c29d 100644 --- a/src/internal/Matrix.h +++ b/src/internal/Matrix.h @@ -125,7 +125,6 @@ EIGEN_MAKE_TYPEDEFS_ALL_SIZES(std::complex, cd) } // namespace Eigen -#include "MatrixAlias.h" #include "MatrixOps.h" #include "ScalarOps.h" #include "RowAndCol.h" diff --git a/src/internal/MatrixAlias.h b/src/internal/MatrixAlias.h deleted file mode 100644 index 94d913a5f..000000000 --- a/src/internal/MatrixAlias.h +++ /dev/null @@ -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 -// -// 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 class MatrixAlias - : public EigenBase > -{ - public: - typedef typename MatrixType::Scalar Scalar; - typedef MatrixRef Ref; - typedef EigenBase Base; - friend class EigenBase; - - 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(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 m_aliased; - MatrixType m_tmp; -}; - -template -typename Matrix<_Scalar, _Rows, _Cols>::Alias -Matrix<_Scalar, _Rows, _Cols>::alias() -{ - return Alias(*this); -} - -} // namespace Eigen - -#endif // EIGEN_MATRIXALIAS_H diff --git a/src/internal/MatrixOps.h b/src/internal/MatrixOps.h index 34a24e914..5697588ac 100644 --- a/src/internal/MatrixOps.h +++ b/src/internal/MatrixOps.h @@ -37,6 +37,9 @@ template class MatrixSum typedef typename Rhs::Ref RhsRef; friend class EigenBase; 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 class MatrixDifference friend class EigenBase; 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) { diff --git a/src/internal/Minor.h b/src/internal/Minor.h index 05873f1f1..c7ddd5de3 100644 --- a/src/internal/Minor.h +++ b/src/internal/Minor.h @@ -36,6 +36,9 @@ template class MatrixMinor typedef typename MatrixType::Ref MatRef; friend class EigenBase >; typedef MatrixMinor Ref; + + static const int RowsAtCompileTime = MatrixType::RowsAtCompileTime - 1, + ColsAtCompileTime = MatrixType::ColsAtCompileTime - 1; MatrixMinor(const MatRef& matrix, int row, int col = 0) diff --git a/src/internal/RowAndCol.h b/src/internal/RowAndCol.h index d7e3f73b0..c8e9eb46d 100644 --- a/src/internal/RowAndCol.h +++ b/src/internal/RowAndCol.h @@ -37,6 +37,9 @@ template class MatrixRow friend class EigenBase >; 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 class MatrixCol friend class EigenBase >; typedef MatrixCol Ref; + static const int RowsAtCompileTime = MatrixType::RowsAtCompileTime, + ColsAtCompileTime = 1; + MatrixCol(const MatRef& matrix, int col) : m_matrix(matrix), m_col(col) { diff --git a/src/internal/ScalarOps.h b/src/internal/ScalarOps.h index de2cad770..ecfebcaf3 100644 --- a/src/internal/ScalarOps.h +++ b/src/internal/ScalarOps.h @@ -37,6 +37,9 @@ template class ScalarProduct typedef ScalarProduct Ref; friend class EigenBase >; + static const int RowsAtCompileTime = MatrixType::RowsAtCompileTime, + ColsAtCompileTime = MatrixType::ColsAtCompileTime; + ScalarProduct(const MatRef& matrix, Scalar scalar) : m_matrix(matrix), m_scalar(scalar) {} diff --git a/test/matrixmanip.cpp b/test/matrixmanip.cpp index b5bdd21c6..9e7b613b2 100644 --- a/test/matrixmanip.cpp +++ b/test/matrixmanip.cpp @@ -38,7 +38,7 @@ template 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() diff --git a/test/matrixops.cpp b/test/matrixops.cpp index 1a70dcf5d..8acf43277 100644 --- a/test/matrixops.cpp +++ b/test/matrixops.cpp @@ -44,10 +44,9 @@ template 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() -- cgit v1.2.3