Eigen  5.0.1
 
Loading...
Searching...
No Matches
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// SPDX-License-Identifier: MPL-2.0
11
12#ifndef EIGEN_CWISE_UNARY_OP_H
13#define EIGEN_CWISE_UNARY_OP_H
14
15// IWYU pragma: private
16#include "./InternalHeaderCheck.h"
17
18namespace Eigen {
19
20namespace internal {
21template <typename UnaryOp, typename XprType>
22struct traits<CwiseUnaryOp<UnaryOp, XprType> > : traits<XprType> {
23 using Scalar = typename result_of<UnaryOp(const typename XprType::Scalar&)>::type;
24 using XprTypeNested = typename XprType::Nested;
25 using XprTypeNested_ = std::remove_reference_t<XprTypeNested>;
26 enum { Flags = XprTypeNested_::Flags & RowMajorBit };
27};
28} // namespace internal
29
30template <typename UnaryOp, typename XprType, typename StorageKind>
31class CwiseUnaryOpImpl;
32
53template <typename UnaryOp, typename XprType>
54class CwiseUnaryOp : public CwiseUnaryOpImpl<UnaryOp, XprType, typename internal::traits<XprType>::StorageKind>,
55 internal::no_assignment_operator {
56 public:
57 using Base = typename CwiseUnaryOpImpl<UnaryOp, XprType, typename internal::traits<XprType>::StorageKind>::Base;
58 EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseUnaryOp)
59 using XprTypeNested = typename internal::ref_selector<XprType>::type;
60 using NestedExpression = internal::remove_all_t<XprType>;
61
62 EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE explicit CwiseUnaryOp(const XprType& xpr,
63 const UnaryOp& func = UnaryOp())
64 : m_xpr(xpr), m_functor(func) {}
65
66 EIGEN_DEVICE_FUNC constexpr Index rows() const noexcept { return m_xpr.rows(); }
67 EIGEN_DEVICE_FUNC constexpr Index cols() const noexcept { return m_xpr.cols(); }
68
70 EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE const UnaryOp& functor() const { return m_functor; }
71
73 EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE const internal::remove_all_t<XprTypeNested>& nestedExpression()
74 const {
75 return m_xpr;
76 }
77
79 EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE internal::remove_all_t<XprTypeNested>& nestedExpression() {
80 return m_xpr;
81 }
82
83 protected:
84 XprTypeNested m_xpr;
85 const UnaryOp m_functor;
86};
87
88// Generic API dispatcher
89template <typename UnaryOp, typename XprType, typename StorageKind>
90class CwiseUnaryOpImpl : public internal::generic_xpr_base<CwiseUnaryOp<UnaryOp, XprType> >::type {
91 public:
92 using Base = typename internal::generic_xpr_base<CwiseUnaryOp<UnaryOp, XprType>>::type;
93};
94
95} // end namespace Eigen
96
97#endif // EIGEN_CWISE_UNARY_OP_H
constexpr internal::remove_all_t< XprTypeNested > & nestedExpression()
Definition CwiseUnaryOp.h:79
constexpr const internal::remove_all_t< XprTypeNested > & nestedExpression() const
Definition CwiseUnaryOp.h:73
constexpr const UnaryOp & functor() const
Definition CwiseUnaryOp.h:70
constexpr unsigned int RowMajorBit
Definition Constants.h:71