mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-04-22 01:29:35 +08:00
add ReturnByValue pseudo expression for in-place evaluation with a
return-by-value API style (will soon use it for the transform products)
This commit is contained in:
parent
45136ac3b6
commit
6a26506341
@ -121,6 +121,7 @@ namespace Eigen {
|
|||||||
|
|
||||||
#include "src/Core/MatrixStorage.h"
|
#include "src/Core/MatrixStorage.h"
|
||||||
#include "src/Core/NestByValue.h"
|
#include "src/Core/NestByValue.h"
|
||||||
|
#include "src/Core/ReturnByValue.h"
|
||||||
#include "src/Core/Flagged.h"
|
#include "src/Core/Flagged.h"
|
||||||
#include "src/Core/Matrix.h"
|
#include "src/Core/Matrix.h"
|
||||||
#include "src/Core/Cwise.h"
|
#include "src/Core/Cwise.h"
|
||||||
|
@ -292,6 +292,10 @@ class Matrix
|
|||||||
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_ASSIGNMENT_OPERATOR(Matrix, -=)
|
EIGEN_INHERIT_ASSIGNMENT_OPERATOR(Matrix, -=)
|
||||||
EIGEN_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Matrix, *=)
|
EIGEN_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Matrix, *=)
|
||||||
@ -412,6 +416,10 @@ class Matrix
|
|||||||
_check_template_params();
|
_check_template_params();
|
||||||
_set_noalias(other);
|
_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 */
|
/** Destructor */
|
||||||
inline ~Matrix() {}
|
inline ~Matrix() {}
|
||||||
|
|
||||||
|
@ -630,6 +630,9 @@ template<typename Derived> class MatrixBase
|
|||||||
template<typename Derived1, typename Derived2>
|
template<typename Derived1, typename Derived2>
|
||||||
Derived& lazyAssign(const SparseProduct<Derived1,Derived2,DenseTimeSparseProduct>& product);
|
Derived& lazyAssign(const SparseProduct<Derived1,Derived2,DenseTimeSparseProduct>& product);
|
||||||
|
|
||||||
|
template<typename OtherDerived,typename OtherEvalType>
|
||||||
|
Derived& operator=(const ReturnByValue<OtherDerived,OtherEvalType>& func);
|
||||||
|
|
||||||
#ifdef EIGEN_MATRIXBASE_PLUGIN
|
#ifdef EIGEN_MATRIXBASE_PLUGIN
|
||||||
#include EIGEN_MATRIXBASE_PLUGIN
|
#include EIGEN_MATRIXBASE_PLUGIN
|
||||||
#endif
|
#endif
|
||||||
|
63
Eigen/src/Core/ReturnByValue.h
Normal file
63
Eigen/src/Core/ReturnByValue.h
Normal file
@ -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
|
@ -56,6 +56,7 @@ template<typename MatrixType, unsigned int Mode> class Extract;
|
|||||||
template<typename ExpressionType> class Cwise;
|
template<typename ExpressionType> class Cwise;
|
||||||
template<typename ExpressionType> class WithFormat;
|
template<typename ExpressionType> class WithFormat;
|
||||||
template<typename MatrixType> struct CommaInitializer;
|
template<typename MatrixType> struct CommaInitializer;
|
||||||
|
template<typename Functor, typename EvalType> class ReturnByValue;
|
||||||
|
|
||||||
|
|
||||||
template<typename Lhs, typename Rhs> struct ei_product_mode;
|
template<typename Lhs, typename Rhs> struct ei_product_mode;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user