Medial Code Documentation
Loading...
Searching...
No Matches
GlobalFunctions.h
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Copyright (C) 2010-2012 Gael Guennebaud <gael.guennebaud@inria.fr>
5// Copyright (C) 2010 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_GLOBAL_FUNCTIONS_H
12#define EIGEN_GLOBAL_FUNCTIONS_H
13
14#define EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(NAME,FUNCTOR) \
15 template<typename Derived> \
16 inline const Eigen::CwiseUnaryOp<Eigen::internal::FUNCTOR<typename Derived::Scalar>, const Derived> \
17 (NAME)(const Eigen::ArrayBase<Derived>& x) { \
18 return Eigen::CwiseUnaryOp<Eigen::internal::FUNCTOR<typename Derived::Scalar>, const Derived>(x.derived()); \
19 }
20
21#define EIGEN_ARRAY_DECLARE_GLOBAL_EIGEN_UNARY(NAME,FUNCTOR) \
22 \
23 template<typename Derived> \
24 struct NAME##_retval<ArrayBase<Derived> > \
25 { \
26 typedef const Eigen::CwiseUnaryOp<Eigen::internal::FUNCTOR<typename Derived::Scalar>, const Derived> type; \
27 }; \
28 template<typename Derived> \
29 struct NAME##_impl<ArrayBase<Derived> > \
30 { \
31 static inline typename NAME##_retval<ArrayBase<Derived> >::type run(const Eigen::ArrayBase<Derived>& x) \
32 { \
33 return typename NAME##_retval<ArrayBase<Derived> >::type(x.derived()); \
34 } \
35 };
36
37namespace Eigen
38{
39 EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(real,scalar_real_op)
40 EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(imag,scalar_imag_op)
41 EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(conj,scalar_conjugate_op)
42 EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(inverse,scalar_inverse_op)
43 EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(sin,scalar_sin_op)
44 EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(cos,scalar_cos_op)
45 EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(tan,scalar_tan_op)
46 EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(atan,scalar_atan_op)
47 EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(asin,scalar_asin_op)
48 EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(acos,scalar_acos_op)
49 EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(sinh,scalar_sinh_op)
50 EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(cosh,scalar_cosh_op)
51 EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(tanh,scalar_tanh_op)
52 EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(lgamma,scalar_lgamma_op)
53 EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(erf,scalar_erf_op)
54 EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(erfc,scalar_erfc_op)
55 EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(exp,scalar_exp_op)
56 EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(log,scalar_log_op)
57 EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(log10,scalar_log10_op)
58 EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(abs,scalar_abs_op)
59 EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(abs2,scalar_abs2_op)
60 EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(arg,scalar_arg_op)
61 EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(sqrt,scalar_sqrt_op)
62 EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(square,scalar_square_op)
63 EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(cube,scalar_cube_op)
64 EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(round,scalar_round_op)
65 EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(floor,scalar_floor_op)
66 EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(ceil,scalar_ceil_op)
67 EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(isnan,scalar_isnan_op)
68 EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(isinf,scalar_isinf_op)
69 EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(isfinite,scalar_isfinite_op)
70 EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(sign,scalar_sign_op)
71
72 template<typename Derived>
74 pow(const Eigen::ArrayBase<Derived>& x, const typename Derived::Scalar& exponent) {
75 return x.derived().pow(exponent);
76 }
77
87 template<typename Derived,typename ExponentDerived>
90 {
92 x.derived(),
93 exponents.derived()
94 );
95 }
96
107 template<typename Derived>
108 inline const Eigen::CwiseBinaryOp<Eigen::internal::scalar_binary_pow_op<typename Derived::Scalar, typename Derived::Scalar>, const typename Derived::ConstantReturnType, const Derived>
109 pow(const typename Derived::Scalar& x, const Eigen::ArrayBase<Derived>& exponents)
110 {
111 typename Derived::ConstantReturnType constant_x(exponents.rows(), exponents.cols(), x);
113 constant_x,
114 exponents.derived()
115 );
116 }
117
121 template <typename Derived>
123 operator/(const typename Derived::Scalar& s, const Eigen::ArrayBase<Derived>& a)
124 {
126 a.derived(),
128 );
129 }
130
131 namespace internal
132 {
133 EIGEN_ARRAY_DECLARE_GLOBAL_EIGEN_UNARY(real,scalar_real_op)
134 EIGEN_ARRAY_DECLARE_GLOBAL_EIGEN_UNARY(imag,scalar_imag_op)
135 EIGEN_ARRAY_DECLARE_GLOBAL_EIGEN_UNARY(abs2,scalar_abs2_op)
136 }
137}
138
139// TODO: cleanly disable those functions that are not supported on Array (numext::real_ref, internal::random, internal::isApprox...)
140
141#endif // EIGEN_GLOBAL_FUNCTIONS_H
Pseudo expression representing a solving operation.
Definition Solve.h:63
Definition BinaryFunctors.h:510