CwiseUnaryOp.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-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 
63  typedef typename internal::ref_selector<XprType>::type XprTypeNested;
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
82  nestedExpression() const { return m_xpr; }
83 
85  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
87  nestedExpression() { return m_xpr; }
88 
89  protected:
91  const UnaryOp m_functor;
92 };
93 
94 // Generic API dispatcher
95 template<typename UnaryOp, typename XprType, typename StorageKind>
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
#define EIGEN_GENERIC_PUBLIC_INTERFACE(Derived)
Definition: Macros.h:1149
#define EIGEN_NOEXCEPT
Definition: Macros.h:1260
#define EIGEN_CONSTEXPR
Definition: Macros.h:747
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:883
internal::generic_xpr_base< CwiseUnaryOp< UnaryOp, XprType > >::type Base
Definition: CwiseUnaryOp.h:100
Generic expression where a coefficient-wise unary operator is applied to an expression.
Definition: CwiseUnaryOp.h:58
CwiseUnaryOpImpl< UnaryOp, XprType, typename internal::traits< XprType >::StorageKind >::Base Base
Definition: CwiseUnaryOp.h:61
internal::remove_all_t< XprType > NestedExpression
Definition: CwiseUnaryOp.h:64
EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
Definition: CwiseUnaryOp.h:73
internal::ref_selector< XprType >::type XprTypeNested
Definition: CwiseUnaryOp.h:63
const UnaryOp m_functor
Definition: CwiseUnaryOp.h:91
XprTypeNested m_xpr
Definition: CwiseUnaryOp.h:90
const UnaryOp & functor() const
Definition: CwiseUnaryOp.h:77
const internal::remove_all_t< XprTypeNested > & nestedExpression() const
Definition: CwiseUnaryOp.h:82
EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Definition: CwiseUnaryOp.h:71
internal::remove_all_t< XprTypeNested > & nestedExpression()
Definition: CwiseUnaryOp.h:87
const unsigned int RowMajorBit
Definition: Constants.h:68
typename remove_all< T >::type remove_all_t
Definition: Meta.h:119
: InteropHeaders
Definition: Core:139
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:82