aboutsummaryrefslogtreecommitdiffhomepage
path: root/Eigen
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2009-03-04 13:00:00 +0000
committerGravatar Gael Guennebaud <g.gael@free.fr>2009-03-04 13:00:00 +0000
commit6a265063417db175eb436e6bcc0e3e74780a1b2f (patch)
tree89d28475febfac8cc175da53ccf585de737291de /Eigen
parent45136ac3b6ea63e9f8b093ab0e8dd0b9eac6452a (diff)
add ReturnByValue pseudo expression for in-place evaluation with a
return-by-value API style (will soon use it for the transform products)
Diffstat (limited to 'Eigen')
-rw-r--r--Eigen/Core1
-rw-r--r--Eigen/src/Core/Matrix.h10
-rw-r--r--Eigen/src/Core/MatrixBase.h3
-rw-r--r--Eigen/src/Core/ReturnByValue.h63
-rw-r--r--Eigen/src/Core/util/ForwardDeclarations.h1
5 files changed, 77 insertions, 1 deletions
diff --git a/Eigen/Core b/Eigen/Core
index 1e38ecf69..e75b90931 100644
--- a/Eigen/Core
+++ b/Eigen/Core
@@ -121,6 +121,7 @@ namespace Eigen {
#include "src/Core/MatrixStorage.h"
#include "src/Core/NestByValue.h"
+#include "src/Core/ReturnByValue.h"
#include "src/Core/Flagged.h"
#include "src/Core/Matrix.h"
#include "src/Core/Cwise.h"
diff --git a/Eigen/src/Core/Matrix.h b/Eigen/src/Core/Matrix.h
index 0b172e97c..fbd55e526 100644
--- a/Eigen/src/Core/Matrix.h
+++ b/Eigen/src/Core/Matrix.h
@@ -289,9 +289,13 @@ class Matrix
*/
EIGEN_STRONG_INLINE Matrix& operator=(const Matrix& other)
{
- return _set(other);
+ return _set(other);
}
+ template<typename OtherDerived,typename OtherEvalType>
+ EIGEN_STRONG_INLINE Matrix& operator=(const ReturnByValue<OtherDerived,OtherEvalType>& func)
+ { return Base::operator=(func); }
+
EIGEN_INHERIT_ASSIGNMENT_OPERATOR(Matrix, +=)
EIGEN_INHERIT_ASSIGNMENT_OPERATOR(Matrix, -=)
EIGEN_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Matrix, *=)
@@ -412,6 +416,10 @@ class Matrix
_check_template_params();
_set_noalias(other);
}
+ /** Copy constructor with in-place evaluation */
+ template<typename OtherDerived,typename OtherEvalType>
+ EIGEN_STRONG_INLINE Matrix(const ReturnByValue<OtherDerived,OtherEvalType>& other)
+ { other.evalTo(*this); }
/** Destructor */
inline ~Matrix() {}
diff --git a/Eigen/src/Core/MatrixBase.h b/Eigen/src/Core/MatrixBase.h
index 654296489..3a7f1a3e0 100644
--- a/Eigen/src/Core/MatrixBase.h
+++ b/Eigen/src/Core/MatrixBase.h
@@ -630,6 +630,9 @@ template<typename Derived> class MatrixBase
template<typename Derived1, typename Derived2>
Derived& lazyAssign(const SparseProduct<Derived1,Derived2,DenseTimeSparseProduct>& product);
+ template<typename OtherDerived,typename OtherEvalType>
+ Derived& operator=(const ReturnByValue<OtherDerived,OtherEvalType>& func);
+
#ifdef EIGEN_MATRIXBASE_PLUGIN
#include EIGEN_MATRIXBASE_PLUGIN
#endif
diff --git a/Eigen/src/Core/ReturnByValue.h b/Eigen/src/Core/ReturnByValue.h
new file mode 100644
index 000000000..e6d2b0d01
--- /dev/null
+++ b/Eigen/src/Core/ReturnByValue.h
@@ -0,0 +1,63 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra. Eigen itself is part of the KDE project.
+//
+// Copyright (C) 2009 Gael Guennebaud <g.gael@free.fr>
+//
+// Eigen is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 3 of the License, or (at your option) any later version.
+//
+// Alternatively, 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 of
+// the License, 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 Lesser General Public License or the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License and a copy of the GNU General Public License along with
+// Eigen. If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef EIGEN_RETURNBYVALUE_H
+#define EIGEN_RETURNBYVALUE_H
+
+/** \class ReturnByValue
+ *
+ */
+template<typename Functor,typename EvalType>
+struct ei_traits<ReturnByValue<Functor,EvalType> > : public ei_traits<EvalType>
+{
+ enum {
+ Flags = ei_traits<EvalType>::Flags | EvalBeforeNestingBit
+ };
+};
+
+template<typename Functor,typename EvalType,int n>
+struct ei_nested<ReturnByValue<Functor,EvalType>, n, EvalType>
+{
+ typedef EvalType type;
+};
+
+template<typename Functor, typename EvalType> class ReturnByValue
+ : public MatrixBase<ReturnByValue<Functor,EvalType> >
+{
+ public:
+ EIGEN_GENERIC_PUBLIC_INTERFACE(ReturnByValue)
+ template<typename Dest>
+ inline void evalTo(Dest& dst) const
+ { static_cast<const Functor*>(this)->evalTo(dst); }
+};
+
+template<typename Derived>
+template<typename OtherDerived,typename OtherEvalType>
+Derived& MatrixBase<Derived>::operator=(const ReturnByValue<OtherDerived,OtherEvalType>& other)
+{
+ other.evalTo(derived());
+ return derived();
+}
+
+#endif // EIGEN_RETURNBYVALUE_H
diff --git a/Eigen/src/Core/util/ForwardDeclarations.h b/Eigen/src/Core/util/ForwardDeclarations.h
index 46faf1e48..3dc6762f8 100644
--- a/Eigen/src/Core/util/ForwardDeclarations.h
+++ b/Eigen/src/Core/util/ForwardDeclarations.h
@@ -56,6 +56,7 @@ template<typename MatrixType, unsigned int Mode> class Extract;
template<typename ExpressionType> class Cwise;
template<typename ExpressionType> class WithFormat;
template<typename MatrixType> struct CommaInitializer;
+template<typename Functor, typename EvalType> class ReturnByValue;
template<typename Lhs, typename Rhs> struct ei_product_mode;