NestByValue.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) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
5 // Copyright (C) 2006-2008 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_NESTBYVALUE_H
12 #define EIGEN_NESTBYVALUE_H
13 
14 #include "./InternalHeaderCheck.h"
15 
16 namespace Eigen {
17 
18 namespace internal {
19 template<typename ExpressionType>
20 struct traits<NestByValue<ExpressionType> > : public traits<ExpressionType>
21 {
22  enum {
23  Flags = traits<ExpressionType>::Flags & ~NestByRefBit
24  };
25 };
26 }
27 
40 template<typename ExpressionType> class NestByValue
41  : public internal::dense_xpr_base< NestByValue<ExpressionType> >::type
42 {
43  public:
44 
45  typedef typename internal::dense_xpr_base<NestByValue>::type Base;
46  static constexpr bool HasDirectAccess = internal::has_direct_access<ExpressionType>::ret;
47 
49 
50  EIGEN_DEVICE_FUNC explicit inline NestByValue(const ExpressionType& matrix) : m_expression(matrix) {}
51 
54 
55  EIGEN_DEVICE_FUNC operator const ExpressionType&() const { return m_expression; }
56 
57  EIGEN_DEVICE_FUNC const ExpressionType& nestedExpression() const { return m_expression; }
58 
59  EIGEN_DEVICE_FUNC typename std::enable_if<HasDirectAccess, const Scalar*>::type data() const {
60  return m_expression.data();
61  }
62 
63  EIGEN_DEVICE_FUNC typename std::enable_if<HasDirectAccess, Index>::type innerStride() const {
64  return m_expression.innerStride();
65  }
66 
67  EIGEN_DEVICE_FUNC typename std::enable_if<HasDirectAccess, Index>::type outerStride() const {
68  return m_expression.outerStride();
69  }
70 
71  protected:
72  const ExpressionType m_expression;
73 };
74 
77 template<typename Derived>
80 {
81  return NestByValue<Derived>(derived());
82 }
83 
84 namespace internal {
85 
86 // Evaluator of Solve -> eval into a temporary
87 template<typename ArgType>
88 struct evaluator<NestByValue<ArgType> >
89  : public evaluator<ArgType>
90 {
91  typedef evaluator<ArgType> Base;
92 
93  EIGEN_DEVICE_FUNC explicit evaluator(const NestByValue<ArgType>& xpr)
94  : Base(xpr.nestedExpression())
95  {}
96 };
97 }
98 
99 } // end namespace Eigen
100 
101 #endif // EIGEN_NESTBYVALUE_H
#define EIGEN_NOEXCEPT
Definition: Macros.h:1260
#define EIGEN_CONSTEXPR
Definition: Macros.h:747
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:883
#define EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
Definition: Macros.h:1168
const NestByValue< Derived > nestByValue() const
Definition: NestByValue.h:79
Expression which must be nested by value.
Definition: NestByValue.h:42
internal::dense_xpr_base< NestByValue >::type Base
Definition: NestByValue.h:45
std::enable_if< HasDirectAccess, Index >::type innerStride() const
Definition: NestByValue.h:63
std::enable_if< HasDirectAccess, Index >::type outerStride() const
Definition: NestByValue.h:67
std::enable_if< HasDirectAccess, const Scalar * >::type data() const
Definition: NestByValue.h:59
const ExpressionType & nestedExpression() const
Definition: NestByValue.h:57
EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Definition: NestByValue.h:52
const ExpressionType m_expression
Definition: NestByValue.h:72
EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
Definition: NestByValue.h:53
static constexpr bool HasDirectAccess
Definition: NestByValue.h:46
: InteropHeaders
Definition: Core:139
const unsigned int NestByRefBit
Definition: Constants.h:171
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:82