TR-mbed 1.0
Loading...
Searching...
No Matches
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
14namespace Eigen {
15
16namespace internal {
17
18template<typename Derived>
19struct 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 */
38template<typename Derived,int n,typename PlainObject>
39struct nested_eval<ReturnByValue<Derived>, n, PlainObject>
40{
42};
43
44} // end namespace internal
45
50template<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>
61 inline void evalTo(Dest& dst) const
62 { static_cast<const Derived*>(this)->evalTo(dst); }
64 inline Index rows() const EIGEN_NOEXCEPT { return static_cast<const Derived*>(this)->rows(); }
66 inline Index cols() const EIGEN_NOEXCEPT { return static_cast<const Derived*>(this)->cols(); }
67
68#ifndef EIGEN_PARSED_BY_DOXYGEN
69#define Unusable YOU_ARE_TRYING_TO_ACCESS_A_SINGLE_COEFFICIENT_IN_A_SPECIAL_EXPRESSION_WHERE_THAT_IS_NOT_ALLOWED_BECAUSE_THAT_WOULD_BE_INEFFICIENT
70 class Unusable{
71 Unusable(const Unusable&) {}
72 Unusable& operator=(const Unusable&) {return *this;}
73 };
74 const Unusable& coeff(Index) const { return *reinterpret_cast<const Unusable*>(this); }
75 const Unusable& coeff(Index,Index) const { return *reinterpret_cast<const Unusable*>(this); }
76 Unusable& coeffRef(Index) { return *reinterpret_cast<Unusable*>(this); }
77 Unusable& coeffRef(Index,Index) { return *reinterpret_cast<Unusable*>(this); }
78#undef Unusable
79#endif
80};
81
82template<typename Derived>
83template<typename OtherDerived>
85{
86 other.evalTo(derived());
87 return derived();
88}
89
90namespace internal {
91
92// Expression is evaluated in a temporary; default implementation of Assignment is bypassed so that
93// when a ReturnByValue expression is assigned, the evaluator is not constructed.
94// TODO: Finalize port to new regime; ReturnByValue should not exist in the expression world
95
96template<typename Derived>
97struct evaluator<ReturnByValue<Derived> >
98 : public evaluator<typename internal::traits<Derived>::ReturnType>
99{
101 typedef typename internal::traits<Derived>::ReturnType PlainObject;
102 typedef evaluator<PlainObject> Base;
103
104 EIGEN_DEVICE_FUNC explicit evaluator(const XprType& xpr)
105 : m_result(xpr.rows(), xpr.cols())
106 {
107 ::new (static_cast<Base*>(this)) Base(m_result);
108 xpr.evalTo(m_result);
109 }
110
111protected:
112 PlainObject m_result;
113};
114
115} // end namespace internal
116
117} // end namespace Eigen
118
119#endif // EIGEN_RETURNBYVALUE_H
int n
Definition BiCGSTAB_simple.cpp:1
#define EIGEN_NOEXCEPT
Definition Macros.h:1418
#define EIGEN_CONSTEXPR
Definition Macros.h:787
#define EIGEN_DEVICE_FUNC
Definition Macros.h:976
#define EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
Definition Macros.h:1283
int rows
Definition Tutorial_commainit_02.cpp:1
int cols
Definition Tutorial_commainit_02.cpp:1
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived & operator=(const DenseBase< OtherDerived > &other)
Definition Assign.h:39
Definition ReturnByValue.h:70
Definition ReturnByValue.h:52
Unusable & coeffRef(Index, Index)
Definition ReturnByValue.h:77
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Definition ReturnByValue.h:64
const Unusable & coeff(Index) const
Definition ReturnByValue.h:74
internal::dense_xpr_base< ReturnByValue >::type Base
Definition ReturnByValue.h:56
internal::traits< Derived >::ReturnType ReturnType
Definition ReturnByValue.h:54
const Unusable & coeff(Index, Index) const
Definition ReturnByValue.h:75
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
Definition ReturnByValue.h:66
Unusable & coeffRef(Index)
Definition ReturnByValue.h:76
EIGEN_DEVICE_FUNC void evalTo(Dest &dst) const
Definition ReturnByValue.h:61
Definition XprHelper.h:110
const unsigned int EvalBeforeNestingBit
Definition Constants.h:70
const unsigned int DirectAccessBit
Definition Constants.h:155
Namespace containing all symbols from the Eigen library.
Definition bench_norm.cpp:85
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:74
Definition BandTriangularSolver.h:13
CwiseBinaryOp< internal::scalar_sum_op< double, double >, const CpyMatrixXd, const CpyMatrixXd > XprType
Definition nestbyvalue.cpp:15
Definition XprHelper.h:484
unary_evaluator< T > Base
Definition CoreEvaluators.h:92
traits< Derived >::ReturnType type
Definition ReturnByValue.h:41
Definition XprHelper.h:458
Definition ForwardDeclarations.h:17