Eigen  5.0.1
 
Loading...
Searching...
No Matches
CommonCwiseUnaryOps.inc
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Copyright (C) 2008-2009 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// This file is a base class plugin containing common coefficient wise functions.
13
14#ifndef EIGEN_PARSED_BY_DOXYGEN
15
17using ConjugateReturnType =
18 std::conditional_t<NumTraits<Scalar>::IsComplex,
19 const CwiseUnaryOp<internal::scalar_conjugate_op<Scalar>, const Derived>, const Derived&>;
21using RealReturnType =
22 std::conditional_t<NumTraits<Scalar>::IsComplex,
23 const CwiseUnaryOp<internal::scalar_real_op<Scalar>, const Derived>, const Derived&>;
25using NonConstRealReturnType =
26 std::conditional_t<NumTraits<Scalar>::IsComplex, CwiseUnaryView<internal::scalar_real_ref_op<Scalar>, Derived>,
27 Derived&>;
29using ImagReturnType = CwiseUnaryOp<internal::scalar_imag_op<Scalar>, const Derived>;
33using NonConstImagReturnType =
34 std::conditional_t<NumTraits<Scalar>::IsComplex, CwiseUnaryView<internal::scalar_imag_ref_op<Scalar>, Derived>,
35 ImagReturnType>;
36
37using NegativeReturnType = CwiseUnaryOp<internal::scalar_opposite_op<Scalar>, const Derived>;
38
39#endif // not EIGEN_PARSED_BY_DOXYGEN
40
45EIGEN_DOC_UNARY_ADDONS(operator-, opposite)
47EIGEN_DEVICE_FUNC constexpr inline const NegativeReturnType operator-() const { return NegativeReturnType(derived()); }
48
49template <class NewType>
50struct CastXpr {
51 using Type = typename internal::cast_return_type<
52 Derived, const CwiseUnaryOp<internal::core_cast_op<Scalar, NewType>, const Derived>>::type;
53};
54
60EIGEN_DOC_UNARY_ADDONS(cast, conversion function)
64template <typename NewType>
65EIGEN_DEVICE_FUNC constexpr typename CastXpr<NewType>::Type cast() const {
66 return typename CastXpr<NewType>::Type(derived());
67}
68
71EIGEN_DOC_UNARY_ADDONS(conjugate, complex conjugate)
74EIGEN_DEVICE_FUNC constexpr inline ConjugateReturnType conjugate() const { return ConjugateReturnType(derived()); }
75
78EIGEN_DOC_UNARY_ADDONS(conjugate, complex conjugate)
81template <bool Cond>
82EIGEN_DEVICE_FUNC constexpr inline std::conditional_t<Cond, ConjugateReturnType, const Derived&> conjugateIf() const {
83 typedef std::conditional_t<Cond, ConjugateReturnType, const Derived&> ReturnType;
84 return ReturnType(derived());
85}
86
89EIGEN_DOC_UNARY_ADDONS(real, real part function)
92EIGEN_DEVICE_FUNC constexpr inline RealReturnType real() const { return RealReturnType(derived()); }
93
96EIGEN_DOC_UNARY_ADDONS(imag, imaginary part function)
99EIGEN_DEVICE_FUNC constexpr inline const ImagReturnType imag() const { return ImagReturnType(derived()); }
100
118EIGEN_DOC_UNARY_ADDONS(unaryExpr, unary function)
122template <typename CustomUnaryOp>
123EIGEN_DEVICE_FUNC constexpr inline const CwiseUnaryOp<CustomUnaryOp, const Derived> unaryExpr(
124 const CustomUnaryOp& func = CustomUnaryOp()) const {
125 return CwiseUnaryOp<CustomUnaryOp, const Derived>(derived(), func);
126}
127
137EIGEN_DOC_UNARY_ADDONS(unaryViewExpr, unary function)
141template <typename CustomViewOp>
142EIGEN_DEVICE_FUNC constexpr inline const CwiseUnaryView<CustomViewOp, const Derived> unaryViewExpr(
143 const CustomViewOp& func = CustomViewOp()) const {
144 return CwiseUnaryView<CustomViewOp, const Derived>(derived(), func);
145}
146
152EIGEN_DOC_UNARY_ADDONS(unaryViewExpr, unary function)
156template <typename CustomViewOp>
157EIGEN_DEVICE_FUNC constexpr inline CwiseUnaryView<CustomViewOp, Derived> unaryViewExpr(
158 const CustomViewOp& func = CustomViewOp()) {
159 return CwiseUnaryView<CustomViewOp, Derived>(derived(), func);
160}
161
164EIGEN_DOC_UNARY_ADDONS(real, real part function)
167EIGEN_DEVICE_FUNC constexpr inline NonConstRealReturnType real() { return NonConstRealReturnType(derived()); }
168
173EIGEN_DOC_UNARY_ADDONS(imag, imaginary part function)
176EIGEN_DEVICE_FUNC constexpr inline NonConstImagReturnType imag() { return NonConstImagReturnType(derived()); }