Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
Eigen
src
Core
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
{
55
EIGEN_ARRAY_DECLARE_GLOBAL_STD_UNARY
(
real
,scalar_real_op)
56
EIGEN_ARRAY_DECLARE_GLOBAL_STD_UNARY
(
imag
,scalar_imag_op)
57
EIGEN_ARRAY_DECLARE_GLOBAL_STD_UNARY
(
sin
,scalar_sin_op)
58
EIGEN_ARRAY_DECLARE_GLOBAL_STD_UNARY
(
cos
,scalar_cos_op)
59
EIGEN_ARRAY_DECLARE_GLOBAL_STD_UNARY
(
asin
,scalar_asin_op)
60
EIGEN_ARRAY_DECLARE_GLOBAL_STD_UNARY
(
acos
,scalar_acos_op)
61
EIGEN_ARRAY_DECLARE_GLOBAL_STD_UNARY
(
tan
,scalar_tan_op)
62
EIGEN_ARRAY_DECLARE_GLOBAL_STD_UNARY
(
exp
,scalar_exp_op)
63
EIGEN_ARRAY_DECLARE_GLOBAL_STD_UNARY
(
log
,scalar_log_op)
64
EIGEN_ARRAY_DECLARE_GLOBAL_STD_UNARY
(
abs
,scalar_abs_op)
65
EIGEN_ARRAY_DECLARE_GLOBAL_STD_UNARY
(
sqrt
,scalar_sqrt_op)
66
67
template
<
typename
Derived>
68
inline
const
Eigen::CwiseUnaryOp<Eigen::internal::scalar_pow_op<typename Derived::Scalar>
,
const
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>
74
inline
const
Eigen::CwiseBinaryOp<Eigen::internal::scalar_binary_pow_op<typename Derived::Scalar, typename Derived::Scalar>
,
const
Derived,
const
Derived>
75
pow
(
const
Eigen::ArrayBase<Derived>
& x,
const
Eigen::ArrayBase<Derived>
& exponents)
76
{
77
return
Eigen::CwiseBinaryOp<Eigen::internal::scalar_binary_pow_op<typename Derived::Scalar, typename Derived::Scalar>
,
const
Derived,
const
Derived>(
78
x.derived(),
79
exponents.derived()
80
);
81
}
82
}
83
84
namespace
Eigen
85
{
89
template
<
typename
Derived>
90
inline
const
Eigen::CwiseUnaryOp<Eigen::internal::scalar_inverse_mult_op<typename Derived::Scalar>
,
const
Derived>
91
operator/
(
typename
Derived::Scalar s,
const
Eigen::ArrayBase<Derived>
& a)
92
{
93
return
Eigen::CwiseUnaryOp<Eigen::internal::scalar_inverse_mult_op<typename Derived::Scalar>
,
const
Derived>(
94
a.derived(),
95
Eigen::internal::scalar_inverse_mult_op<typename Derived::Scalar>(s)
96
);
97
}
98
99
namespace
internal
100
{
101
EIGEN_ARRAY_DECLARE_GLOBAL_EIGEN_UNARY
(
real
,scalar_real_op)
102
EIGEN_ARRAY_DECLARE_GLOBAL_EIGEN_UNARY
(
imag
,scalar_imag_op)
103
EIGEN_ARRAY_DECLARE_GLOBAL_EIGEN_UNARY
(
sin
,scalar_sin_op)
104
EIGEN_ARRAY_DECLARE_GLOBAL_EIGEN_UNARY
(
cos
,scalar_cos_op)
105
EIGEN_ARRAY_DECLARE_GLOBAL_EIGEN_UNARY
(
asin
,scalar_asin_op)
106
EIGEN_ARRAY_DECLARE_GLOBAL_EIGEN_UNARY
(
acos
,scalar_acos_op)
107
EIGEN_ARRAY_DECLARE_GLOBAL_EIGEN_UNARY
(
tan
,scalar_tan_op)
108
EIGEN_ARRAY_DECLARE_GLOBAL_EIGEN_UNARY
(
exp
,scalar_exp_op)
109
EIGEN_ARRAY_DECLARE_GLOBAL_EIGEN_UNARY
(
log
,scalar_log_op)
110
EIGEN_ARRAY_DECLARE_GLOBAL_EIGEN_UNARY
(
abs
,scalar_abs_op)
111
EIGEN_ARRAY_DECLARE_GLOBAL_EIGEN_UNARY
(
abs2
,scalar_abs2_op)
112
EIGEN_ARRAY_DECLARE_GLOBAL_EIGEN_UNARY
(
sqrt
,scalar_sqrt_op)
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
Generated on Wed Jun 13 2012 04:59:31 for Eigen by
1.8.1