GlobalFunctions.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2010 Gael Guennebaud <gael.guennebaud@inria.fr>
5 // Copyright (C) 2010 Benoit Jacob <jacob.benoit.1@gmail.com>
6 //
7 // Eigen is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU Lesser General Public
9 // License as published by the Free Software Foundation; either
10 // version 3 of the License, or (at your option) any later version.
11 //
12 // Alternatively, you can redistribute it and/or
13 // modify it under the terms of the GNU General Public License as
14 // published by the Free Software Foundation; either version 2 of
15 // the License, or (at your option) any later version.
16 //
17 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
18 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
20 // GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU Lesser General Public
23 // License and a copy of the GNU General Public License along with
24 // Eigen. If not, see <http://www.gnu.org/licenses/>.
25 
26 #ifndef EIGEN_GLOBAL_FUNCTIONS_H
27 #define EIGEN_GLOBAL_FUNCTIONS_H
28 
29 #define EIGEN_ARRAY_DECLARE_GLOBAL_STD_UNARY(NAME,FUNCTOR) \
30  template<typename Derived> \
31  inline const Eigen::CwiseUnaryOp<Eigen::internal::FUNCTOR<typename Derived::Scalar>, const Derived> \
32  NAME(const Eigen::ArrayBase<Derived>& x) { \
33  return x.derived(); \
34  }
35 
36 #define EIGEN_ARRAY_DECLARE_GLOBAL_EIGEN_UNARY(NAME,FUNCTOR) \
37  \
38  template<typename Derived> \
39  struct NAME##_retval<ArrayBase<Derived> > \
40  { \
41  typedef const Eigen::CwiseUnaryOp<Eigen::internal::FUNCTOR<typename Derived::Scalar>, const Derived> type; \
42  }; \
43  template<typename Derived> \
44  struct NAME##_impl<ArrayBase<Derived> > \
45  { \
46  static inline typename NAME##_retval<ArrayBase<Derived> >::type run(const Eigen::ArrayBase<Derived>& x) \
47  { \
48  return x.derived(); \
49  } \
50  };
51 
52 
53 namespace std
54 {
66 
67  template<typename Derived>
69  pow(const Eigen::ArrayBase<Derived>& x, const typename Derived::Scalar& exponent) {
70  return x.derived().pow(exponent);
71  }
72 
73  template<typename Derived>
76  {
78  x.derived(),
79  exponents.derived()
80  );
81  }
82 }
83 
84 namespace Eigen
85 {
89  template <typename Derived>
91  operator/(typename Derived::Scalar s, const Eigen::ArrayBase<Derived>& a)
92  {
94  a.derived(),
95  Eigen::internal::scalar_inverse_mult_op<typename Derived::Scalar>(s)
96  );
97  }
98 
99  namespace internal
100  {
113  }
114 }
115 
116 // TODO: cleanly disable those functions that are not supported on Array (internal::real_ref, internal::random, internal::isApprox...)
117 
118 #endif // EIGEN_GLOBAL_FUNCTIONS_H