aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Benoit Jacob <jacob.benoit.1@gmail.com>2007-09-26 14:06:26 +0000
committerGravatar Benoit Jacob <jacob.benoit.1@gmail.com>2007-09-26 14:06:26 +0000
commita2dd9dd6f9a9b6f45e79082e4d8a3577dd4246b6 (patch)
treec6c8459d72aea374b2e469b94d762e9e34537615
parent55227b1f636b03c321940035061360484ea05e66 (diff)
Give the axe to the aliasing system.
Improve the evaluation system instead.
-rw-r--r--doc/tutorial.cpp9
-rw-r--r--src/internal/Block.h3
-rw-r--r--src/internal/Matrix.h1
-rw-r--r--src/internal/MatrixAlias.h84
-rw-r--r--src/internal/MatrixOps.h6
-rw-r--r--src/internal/Minor.h3
-rw-r--r--src/internal/RowAndCol.h6
-rw-r--r--src/internal/ScalarOps.h3
-rw-r--r--test/matrixmanip.cpp2
-rw-r--r--test/matrixops.cpp3
-rw-r--r--test/vectorops.cpp4
11 files changed, 29 insertions, 95 deletions
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<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;
}
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<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,
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<double>, 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 <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
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<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)
{
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<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)
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<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)
{
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<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) {}
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<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()
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<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);
diff --git a/test/vectorops.cpp b/test/vectorops.cpp
index 5f6331bf1..38beb19c2 100644
--- a/test/vectorops.cpp
+++ b/test/vectorops.cpp
@@ -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()