$darkmode
Eigen  5.0.1-dev
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 // IWYU pragma: private
15 #include "./InternalHeaderCheck.h"
16 
17 namespace Eigen {
18 
19 namespace internal {
20 template <typename UnaryOp, typename XprType>
21 struct traits<CwiseUnaryOp<UnaryOp, XprType> > : traits<XprType> {
22  typedef typename result_of<UnaryOp(const typename XprType::Scalar&)>::type Scalar;
23  typedef typename XprType::Nested XprTypeNested;
24  typedef std::remove_reference_t<XprTypeNested> XprTypeNested_;
25  enum { Flags = XprTypeNested_::Flags & RowMajorBit };
26 };
27 } // namespace internal
28 
29 template <typename UnaryOp, typename XprType, typename StorageKind>
30 class CwiseUnaryOpImpl;
31 
51 template <typename UnaryOp, typename XprType>
52 class CwiseUnaryOp : public CwiseUnaryOpImpl<UnaryOp, XprType, typename internal::traits<XprType>::StorageKind>,
53  internal::no_assignment_operator {
54  public:
55  typedef typename CwiseUnaryOpImpl<UnaryOp, XprType, typename internal::traits<XprType>::StorageKind>::Base Base;
56  EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseUnaryOp)
57  typedef typename internal::ref_selector<XprType>::type XprTypeNested;
58  typedef internal::remove_all_t<XprType> NestedExpression;
59 
60  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit CwiseUnaryOp(const XprType& xpr, const UnaryOp& func = UnaryOp())
61  : m_xpr(xpr), m_functor(func) {}
62 
63  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Index rows() const noexcept { return m_xpr.rows(); }
64  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Index cols() const noexcept { return m_xpr.cols(); }
65 
67  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const UnaryOp& functor() const { return m_functor; }
68 
70  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const internal::remove_all_t<XprTypeNested>& nestedExpression() const {
71  return m_xpr;
72  }
73 
75  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE internal::remove_all_t<XprTypeNested>& nestedExpression() { return m_xpr; }
76 
77  protected:
78  XprTypeNested m_xpr;
79  const UnaryOp m_functor;
80 };
81 
82 // Generic API dispatcher
83 template <typename UnaryOp, typename XprType, typename StorageKind>
84 class CwiseUnaryOpImpl : public internal::generic_xpr_base<CwiseUnaryOp<UnaryOp, XprType> >::type {
85  public:
86  typedef typename internal::generic_xpr_base<CwiseUnaryOp<UnaryOp, XprType> >::type Base;
87 };
88 
89 } // end namespace Eigen
90 
91 #endif // EIGEN_CWISE_UNARY_OP_H
Namespace containing all symbols from the Eigen library.
Definition: B01_Experimental.dox:1
const unsigned int RowMajorBit
Definition: Constants.h:70
internal::remove_all_t< XprTypeNested > & nestedExpression()
Definition: CwiseUnaryOp.h:75
const internal::remove_all_t< XprTypeNested > & nestedExpression() const
Definition: CwiseUnaryOp.h:70
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:82
const UnaryOp & functor() const
Definition: CwiseUnaryOp.h:67
Generic expression where a coefficient-wise unary operator is applied to an expression.
Definition: CwiseUnaryOp.h:52