mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-03-25 18:50:40 +08:00
Found a way to have eval() be a member function of class EiObject, instead of a global function.
CCMAIL:bensch128@yahoo.com
This commit is contained in:
parent
28c44a95c2
commit
835e0c9f67
@ -45,7 +45,7 @@ int main(int, char **)
|
||||
<< "Anyway, if you want to store m * m into m, you can do this:" << endl
|
||||
<< " m = eval(m * m);" << endl;
|
||||
m = m_save;
|
||||
m = eval(m * m);
|
||||
m = (m * m).eval();
|
||||
cout << "And m is now:" << endl << m << endl << "as was expected." << endl;
|
||||
return 0;
|
||||
}
|
||||
|
52
src/internal/Eval.h
Normal file
52
src/internal/Eval.h
Normal file
@ -0,0 +1,52 @@
|
||||
// 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 EI_EVAL_H
|
||||
#define EI_EVAL_H
|
||||
|
||||
template<typename Expression> class EiEval
|
||||
: public EiMatrix< typename Expression::Scalar,
|
||||
Expression::Derived::RowsAtCompileTime,
|
||||
Expression::Derived::ColsAtCompileTime >
|
||||
{
|
||||
public:
|
||||
typedef typename Expression::Scalar Scalar;
|
||||
typedef typename Expression::Derived Derived;
|
||||
typedef EiMatrix< Scalar, Derived::RowsAtCompileTime, Derived::ColsAtCompileTime> MatrixType;
|
||||
typedef Expression Base;
|
||||
friend class EiObject<Scalar, Derived>;
|
||||
|
||||
EI_INHERIT_ASSIGNMENT_OPERATORS(EiEval)
|
||||
|
||||
EiEval(const Expression& expression) : MatrixType(expression) {}
|
||||
};
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
EiEval<EiObject<Scalar, Derived> > EiObject<Scalar, Derived>::eval() const
|
||||
{
|
||||
return EiEval<EiObject<Scalar, Derived> >(*this);
|
||||
}
|
||||
|
||||
#endif // EI_EVAL_H
|
@ -97,13 +97,6 @@ class EiMatrix : public EiObject<_Scalar, EiMatrix<_Scalar, _Rows, _Cols> >,
|
||||
~EiMatrix() {}
|
||||
};
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
EiMatrix<Scalar, Derived::RowsAtCompileTime, Derived::ColsAtCompileTime>
|
||||
eval(const EiObject<Scalar, Derived>& expression)
|
||||
{
|
||||
return EiMatrix<Scalar, Derived::RowsAtCompileTime, Derived::ColsAtCompileTime>(expression);
|
||||
}
|
||||
|
||||
#define EI_MAKE_TYPEDEFS(Type, TypeSuffix, Size, SizeSuffix) \
|
||||
typedef EiMatrix<Type, Size, Size> EiMatrix##SizeSuffix##TypeSuffix; \
|
||||
typedef EiMatrix<Type, Size, 1> EiVector##SizeSuffix##TypeSuffix;
|
||||
@ -124,6 +117,7 @@ EI_MAKE_TYPEDEFS_ALL_SIZES(std::complex<double>, cd)
|
||||
#undef EI_MAKE_TYPEDEFS_ALL_SIZES
|
||||
#undef EI_MAKE_TYPEDEFS
|
||||
|
||||
#include "Eval.h"
|
||||
#include "MatrixOps.h"
|
||||
#include "ScalarOps.h"
|
||||
#include "RowAndCol.h"
|
||||
|
@ -28,13 +28,14 @@
|
||||
|
||||
#include "Util.h"
|
||||
|
||||
template<typename _Scalar, typename Derived> class EiObject
|
||||
template<typename _Scalar, typename _Derived> class EiObject
|
||||
{
|
||||
static const int RowsAtCompileTime = Derived::RowsAtCompileTime,
|
||||
ColsAtCompileTime = Derived::ColsAtCompileTime;
|
||||
static const int RowsAtCompileTime = _Derived::RowsAtCompileTime,
|
||||
ColsAtCompileTime = _Derived::ColsAtCompileTime;
|
||||
public:
|
||||
typedef typename EiForwardDecl<Derived>::Ref Ref;
|
||||
typedef typename EiForwardDecl<_Derived>::Ref Ref;
|
||||
typedef _Scalar Scalar;
|
||||
typedef _Derived Derived;
|
||||
|
||||
int rows() const { return static_cast<const Derived *>(this)->_rows(); }
|
||||
int cols() const { return static_cast<const Derived *>(this)->_cols(); }
|
||||
@ -109,6 +110,8 @@ template<typename _Scalar, typename Derived> class EiObject
|
||||
|
||||
Scalar& operator()(int row, int col = 0)
|
||||
{ return write(row, col); }
|
||||
|
||||
EiEval<EiObject> eval() const;
|
||||
};
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
|
@ -51,6 +51,7 @@ template<typename Lhs, typename Rhs> class EiSum;
|
||||
template<typename Lhs, typename Rhs> class EiDifference;
|
||||
template<typename Lhs, typename Rhs> class EiMatrixProduct;
|
||||
template<typename MatrixType> class EiScalarProduct;
|
||||
template<typename ExpressionType> class EiEval;
|
||||
|
||||
template<typename T> struct EiForwardDecl
|
||||
{
|
||||
|
@ -39,7 +39,7 @@ template<typename MatrixType> void matrixManip(const MatrixType& m)
|
||||
a.row(i) += b.row(i);
|
||||
a.col(j) *= 2;
|
||||
a.minor(i, j) = b.block(1, rows-1, 1, cols-1);
|
||||
a.minor(i, j) -= eval(a.block(1, rows-1, 1, cols-1));
|
||||
a.minor(i, j) -= a.block(1, rows-1, 1, cols-1).eval();
|
||||
}
|
||||
|
||||
void EigenTest::testMatrixManip()
|
||||
|
@ -44,7 +44,7 @@ template<typename MatrixType1,
|
||||
a = b;
|
||||
a = b + c;
|
||||
a = s * (b - c);
|
||||
a = eval(a + b);
|
||||
a = (a + b).eval();
|
||||
a += b;
|
||||
a -= b + b;
|
||||
a *= s;
|
||||
|
@ -42,13 +42,13 @@ template<typename VectorType> void vectorOps(const VectorType& v)
|
||||
a = b;
|
||||
a = b + c;
|
||||
a = s * (b - c);
|
||||
a = eval(s * (b - c));
|
||||
a = (s * (b - c)).eval();
|
||||
|
||||
a += b;
|
||||
a -= b + b;
|
||||
a *= s;
|
||||
b /= s;
|
||||
a += eval(a + a);
|
||||
a += (a + a).eval();
|
||||
}
|
||||
|
||||
void EigenTest::testVectorOps()
|
||||
|
Loading…
x
Reference in New Issue
Block a user