Eigen  3.2.91
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 
37 namespace 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(exp,scalar_exp_op)
53  EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(log,scalar_log_op)
54  EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(log10,scalar_log10_op)
55  EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(abs,scalar_abs_op)
56  EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(abs2,scalar_abs2_op)
57  EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(arg,scalar_arg_op)
58  EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(sqrt,scalar_sqrt_op)
59  EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(square,scalar_square_op)
60  EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(cube,scalar_cube_op)
61  EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(round,scalar_round_op)
62  EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(floor,scalar_floor_op)
63  EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(ceil,scalar_ceil_op)
64  EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(isnan,scalar_isnan_op)
65  EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(isinf,scalar_isinf_op)
66  EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(isfinite,scalar_isfinite_op)
67 
68  template<typename Derived>
69  inline const Eigen::CwiseUnaryOp<Eigen::internal::scalar_pow_op<typename Derived::Scalar>, const Derived>
70  pow(const Eigen::ArrayBase<Derived>& x, const typename Derived::Scalar& exponent) {
71  return x.derived().pow(exponent);
72  }
73 
83  template<typename Derived,typename ExponentDerived>
85  pow(const Eigen::ArrayBase<Derived>& x, const Eigen::ArrayBase<ExponentDerived>& exponents)
86  {
88  x.derived(),
89  exponents.derived()
90  );
91  }
92 
103  template<typename Derived>
104  inline const Eigen::CwiseBinaryOp<Eigen::internal::scalar_binary_pow_op<typename Derived::Scalar, typename Derived::Scalar>, const typename Derived::ConstantReturnType, const Derived>
105  pow(const typename Derived::Scalar& x, const Eigen::ArrayBase<Derived>& exponents)
106  {
107  typename Derived::ConstantReturnType constant_x(exponents.rows(), exponents.cols(), x);
108  return Eigen::CwiseBinaryOp<Eigen::internal::scalar_binary_pow_op<typename Derived::Scalar, typename Derived::Scalar>, const typename Derived::ConstantReturnType, const Derived>(
109  constant_x,
110  exponents.derived()
111  );
112  }
113 
117  template <typename Derived>
119  operator/(const typename Derived::Scalar& s, const Eigen::ArrayBase<Derived>& a)
120  {
122  a.derived(),
123  Eigen::internal::scalar_inverse_mult_op<typename Derived::Scalar>(s)
124  );
125  }
126 
127  namespace internal
128  {
129  EIGEN_ARRAY_DECLARE_GLOBAL_EIGEN_UNARY(real,scalar_real_op)
130  EIGEN_ARRAY_DECLARE_GLOBAL_EIGEN_UNARY(imag,scalar_imag_op)
131  EIGEN_ARRAY_DECLARE_GLOBAL_EIGEN_UNARY(abs2,scalar_abs2_op)
132  }
133 }
134 
135 // TODO: cleanly disable those functions that are not supported on Array (numext::real_ref, internal::random, internal::isApprox...)
136 
137 #endif // EIGEN_GLOBAL_FUNCTIONS_H
Definition: LDLT.h:16
Generic expression where a coefficient-wise binary operator is applied to two expressions.
Definition: CwiseBinaryOp.h:78
Base class for all 1D and 2D array, and related expressions.
Definition: ArrayBase.h:39
Definition: Eigen_Colamd.h:54
Generic expression where a coefficient-wise unary operator is applied to an expression.
Definition: CwiseUnaryOp.h:56