Eigen  3.4.90 (git rev 67eeba6e720c5745abc77ae6c92ce0a44aa7b7ae)
CwiseUnaryOp.h
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2008-2014 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_CWISE_UNARY_OP_H
12 #define EIGEN_CWISE_UNARY_OP_H
13 
14 #include "./InternalHeaderCheck.h"
15 
16 namespace Eigen {
17 
18 namespace internal {
19 template<typename UnaryOp, typename XprType>
20 struct traits<CwiseUnaryOp<UnaryOp, XprType> >
21  : traits<XprType>
22 {
23  typedef typename result_of<
24  UnaryOp(const typename XprType::Scalar&)
25  >::type Scalar;
26  typedef typename XprType::Nested XprTypeNested;
27  typedef std::remove_reference_t<XprTypeNested> XprTypeNested_;
28  enum {
29  Flags = XprTypeNested_::Flags & RowMajorBit
30  };
31 };
32 }
33 
34 template<typename UnaryOp, typename XprType, typename StorageKind>
35 class CwiseUnaryOpImpl;
36 
56 template<typename UnaryOp, typename XprType>
57 class CwiseUnaryOp : public CwiseUnaryOpImpl<UnaryOp, XprType, typename internal::traits<XprType>::StorageKind>, internal::no_assignment_operator
58 {
59  public:
60 
61  typedef typename CwiseUnaryOpImpl<UnaryOp, XprType,typename internal::traits<XprType>::StorageKind>::Base Base;
62  EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseUnaryOp)
63  typedef typename internal::ref_selector<XprType>::type XprTypeNested;
64  typedef internal::remove_all_t<XprType> NestedExpression;
65 
66  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
67  explicit CwiseUnaryOp(const XprType& xpr, const UnaryOp& func = UnaryOp())
68  : m_xpr(xpr), m_functor(func) {}
69 
70  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
71  Index rows() const EIGEN_NOEXCEPT { return m_xpr.rows(); }
72  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
73  Index cols() const EIGEN_NOEXCEPT { return m_xpr.cols(); }
74 
76  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
77  const UnaryOp& functor() const { return m_functor; }
78 
80  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
81  const internal::remove_all_t<XprTypeNested>&
82  nestedExpression() const { return m_xpr; }
83 
85  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
86  internal::remove_all_t<XprTypeNested>&
87  nestedExpression() { return m_xpr; }
88 
89  protected:
90  XprTypeNested m_xpr;
91  const UnaryOp m_functor;
92 };
93 
94 // Generic API dispatcher
95 template<typename UnaryOp, typename XprType, typename StorageKind>
96 class CwiseUnaryOpImpl
97  : public internal::generic_xpr_base<CwiseUnaryOp<UnaryOp, XprType> >::type
98 {
99 public:
100  typedef typename internal::generic_xpr_base<CwiseUnaryOp<UnaryOp, XprType> >::type Base;
101 };
102 
103 } // end namespace Eigen
104 
105 #endif // EIGEN_CWISE_UNARY_OP_H
Generic expression where a coefficient-wise unary operator is applied to an expression.
Definition: CwiseUnaryOp.h:58
const UnaryOp & functor() const
Definition: CwiseUnaryOp.h:77
const internal::remove_all_t< XprTypeNested > & nestedExpression() const
Definition: CwiseUnaryOp.h:82
internal::remove_all_t< XprTypeNested > & nestedExpression()
Definition: CwiseUnaryOp.h:87
const unsigned int RowMajorBit
Definition: Constants.h:68
Namespace containing all symbols from the Eigen library.
Definition: Core:139
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:59