ReturnByValue.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
5 // Copyright (C) 2009-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
6 //
7 // This Source Code Form is subject to the terms of the Mozilla
8 // Public License v. 2.0. If a copy of the MPL was not distributed
9 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 
11 #ifndef EIGEN_RETURNBYVALUE_H
12 #define EIGEN_RETURNBYVALUE_H
13 
14 namespace Eigen {
15 
16 namespace internal {
17 
18 template<typename Derived>
19 struct traits<ReturnByValue<Derived> >
20  : public traits<typename traits<Derived>::ReturnType>
21 {
22  enum {
23  // We're disabling the DirectAccess because e.g. the constructor of
24  // the Block-with-DirectAccess expression requires to have a coeffRef method.
25  // Also, we don't want to have to implement the stride stuff.
28  };
29 };
30 
31 /* The ReturnByValue object doesn't even have a coeff() method.
32  * So the only way that nesting it in an expression can work, is by evaluating it into a plain matrix.
33  * So internal::nested always gives the plain return matrix type.
34  *
35  * FIXME: I don't understand why we need this specialization: isn't this taken care of by the EvalBeforeNestingBit ??
36  * Answer: EvalBeforeNestingBit should be deprecated since we have the evaluators
37  */
38 template<typename Derived,int n,typename PlainObject>
39 struct nested_eval<ReturnByValue<Derived>, n, PlainObject>
40 {
42 };
43 
44 } // end namespace internal
45 
50 template<typename Derived> class ReturnByValue
51  : public internal::dense_xpr_base< ReturnByValue<Derived> >::type, internal::no_assignment_operator
52 {
53  public:
55 
58 
59  template<typename Dest>
60  EIGEN_DEVICE_FUNC
61  inline void evalTo(Dest& dst) const
62  { static_cast<const Derived*>(this)->evalTo(dst); }
63  EIGEN_DEVICE_FUNC inline Index rows() const { return static_cast<const Derived*>(this)->rows(); }
64  EIGEN_DEVICE_FUNC inline Index cols() const { return static_cast<const Derived*>(this)->cols(); }
65 
66 #ifndef EIGEN_PARSED_BY_DOXYGEN
67 #define Unusable YOU_ARE_TRYING_TO_ACCESS_A_SINGLE_COEFFICIENT_IN_A_SPECIAL_EXPRESSION_WHERE_THAT_IS_NOT_ALLOWED_BECAUSE_THAT_WOULD_BE_INEFFICIENT
68  class Unusable{
69  Unusable(const Unusable&) {}
70  Unusable& operator=(const Unusable&) {return *this;}
71  };
72  const Unusable& coeff(Index) const { return *reinterpret_cast<const Unusable*>(this); }
73  const Unusable& coeff(Index,Index) const { return *reinterpret_cast<const Unusable*>(this); }
74  Unusable& coeffRef(Index) { return *reinterpret_cast<Unusable*>(this); }
75  Unusable& coeffRef(Index,Index) { return *reinterpret_cast<Unusable*>(this); }
76 #undef Unusable
77 #endif
78 };
79 
80 template<typename Derived>
81 template<typename OtherDerived>
83 {
84  other.evalTo(derived());
85  return derived();
86 }
87 
88 namespace internal {
89 
90 // Expression is evaluated in a temporary; default implementation of Assignment is bypassed so that
91 // when a ReturnByValue expression is assigned, the evaluator is not constructed.
92 // TODO: Finalize port to new regime; ReturnByValue should not exist in the expression world
93 
94 template<typename Derived>
95 struct evaluator<ReturnByValue<Derived> >
96  : public evaluator<typename internal::traits<Derived>::ReturnType>
97 {
101 
102  EIGEN_DEVICE_FUNC explicit evaluator(const XprType& xpr)
103  : m_result(xpr.rows(), xpr.cols())
104  {
105  ::new (static_cast<Base*>(this)) Base(m_result);
106  xpr.evalTo(m_result);
107  }
108 
109 protected:
111 };
112 
113 } // end namespace internal
114 
115 } // end namespace Eigen
116 
117 #endif // EIGEN_RETURNBYVALUE_H
Eigen::internal::evaluator::Base
unary_evaluator< T > Base
Definition: CoreEvaluators.h:92
Eigen::ReturnByValue::rows
EIGEN_DEVICE_FUNC Index rows() const
Definition: ReturnByValue.h:63
Eigen
Definition: common.h:73
Eigen::ReturnByValue::Unusable::Unusable
Unusable(const Unusable &)
Definition: ReturnByValue.h:69
Eigen::ReturnByValue
Definition: ReturnByValue.h:50
Eigen::ReturnByValue::Base
internal::dense_xpr_base< ReturnByValue >::type Base
Definition: ReturnByValue.h:56
Eigen::internal::dense_xpr_base
Definition: XprHelper.h:463
EIGEN_DENSE_PUBLIC_INTERFACE
#define EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
Definition: Macros.h:870
Eigen::internal::nested_eval
Definition: XprHelper.h:437
Eigen::internal::evaluator< ReturnByValue< Derived > >::PlainObject
internal::traits< Derived >::ReturnType PlainObject
Definition: ReturnByValue.h:99
Unusable
#define Unusable
Definition: ReturnByValue.h:67
Eigen::ReturnByValue::coeff
const Unusable & coeff(Index, Index) const
Definition: ReturnByValue.h:73
Eigen::DirectAccessBit
const unsigned int DirectAccessBit
Definition: Constants.h:150
Eigen::ReturnByValue::evalTo
EIGEN_DEVICE_FUNC void evalTo(Dest &dst) const
Definition: ReturnByValue.h:61
Eigen::ReturnByValue::cols
EIGEN_DEVICE_FUNC Index cols() const
Definition: ReturnByValue.h:64
Eigen::ReturnByValue::coeff
const Unusable & coeff(Index) const
Definition: ReturnByValue.h:72
Eigen::ReturnByValue::Unusable
Definition: ReturnByValue.h:68
Eigen::ReturnByValue::Unusable::operator=
Unusable & operator=(const Unusable &)
Definition: ReturnByValue.h:70
Eigen::internal::evaluator< ReturnByValue< Derived > >::evaluator
EIGEN_DEVICE_FUNC evaluator(const XprType &xpr)
Definition: ReturnByValue.h:102
Eigen::internal::evaluator
Definition: CoreEvaluators.h:90
Eigen::ReturnByValue::ReturnType
internal::traits< Derived >::ReturnType ReturnType
Definition: ReturnByValue.h:54
Eigen::internal::traits
Definition: ForwardDeclarations.h:17
Eigen::DenseBase::operator=
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived & operator=(const DenseBase< OtherDerived > &other)
Definition: Assign.h:39
Eigen::internal::evaluator< ReturnByValue< Derived > >::XprType
ReturnByValue< Derived > XprType
Definition: ReturnByValue.h:98
Eigen::internal::nested_eval< ReturnByValue< Derived >, n, PlainObject >::type
traits< Derived >::ReturnType type
Definition: ReturnByValue.h:41
Eigen::ReturnByValue::coeffRef
Unusable & coeffRef(Index)
Definition: ReturnByValue.h:74
Eigen::internal::evaluator< ReturnByValue< Derived > >::m_result
PlainObject m_result
Definition: ReturnByValue.h:110
Eigen::internal::no_assignment_operator
Definition: XprHelper.h:89
internal
Definition: BandTriangularSolver.h:13
n
PlainMatrixType mat * n
Definition: eigenvalues.cpp:41
Eigen::EvalBeforeNestingBit
const unsigned int EvalBeforeNestingBit
Definition: Constants.h:65
Eigen::internal::evaluator< ReturnByValue< Derived > >::Base
evaluator< PlainObject > Base
Definition: ReturnByValue.h:100
Eigen::ReturnByValue::coeffRef
Unusable & coeffRef(Index, Index)
Definition: ReturnByValue.h:75
Eigen::Index
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33


control_box_rst
Author(s): Christoph Rösmann
autogenerated on Wed Mar 2 2022 00:06:09