aboutsummaryrefslogtreecommitdiffhomepage
path: root/Eigen/src/Core/SpecialFunctions.h
blob: d43cf23a185a06f6f9e65fd5df2ea29e05c8fdf1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
// This file is part of Eigen, a lightweight C++ template library
// for linear algebra.
//
// Copyright (C) 2015 Eugene Brevdo <ebrevdo@gmail.com>
//
// This Source Code Form is subject to the terms of the Mozilla
// Public License v. 2.0. If a copy of the MPL was not distributed
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

#ifndef EIGEN_SPECIAL_FUNCTIONS_H
#define EIGEN_SPECIAL_FUNCTIONS_H

namespace Eigen {
namespace internal {

/****************************************************************************
 * Implementation of lgamma                                                 *
 ****************************************************************************/

template<typename Scalar>
struct lgamma_impl
{
  EIGEN_DEVICE_FUNC
  static EIGEN_STRONG_INLINE Scalar run(const Scalar&)
  {
    EIGEN_STATIC_ASSERT((internal::is_same<Scalar, Scalar>::value == false),
                        THIS_TYPE_IS_NOT_SUPPORTED);
    return Scalar(0);
  }
};

template<typename Scalar>
struct lgamma_retval
{
  typedef Scalar type;
};

#ifdef EIGEN_HAS_C99_MATH
template<>
struct lgamma_impl<float>
{
  EIGEN_DEVICE_FUNC
  static EIGEN_STRONG_INLINE double run(const float& x) { return ::lgammaf(x); }
};

template<>
struct lgamma_impl<double>
{
  EIGEN_DEVICE_FUNC
  static EIGEN_STRONG_INLINE double run(const double& x) { return ::lgamma(x); }
};
#endif

/****************************************************************************
 * Implementation of erf                                                    *
 ****************************************************************************/

template<typename Scalar>
struct erf_impl
{
  EIGEN_DEVICE_FUNC
  static EIGEN_STRONG_INLINE Scalar run(const Scalar&)
  {
    EIGEN_STATIC_ASSERT((internal::is_same<Scalar, Scalar>::value == false),
                        THIS_TYPE_IS_NOT_SUPPORTED);
    return Scalar(0);
  }
};

template<typename Scalar>
struct erf_retval
{
  typedef Scalar type;
};

#ifdef EIGEN_HAS_C99_MATH
template<>
struct erf_impl<float>
{
  EIGEN_DEVICE_FUNC
  static EIGEN_STRONG_INLINE float run(const float& x) { return ::erff(x); }
};

template<>
struct erf_impl<double>
{
  EIGEN_DEVICE_FUNC
  static EIGEN_STRONG_INLINE double run(const double& x) { return ::erf(x); }
};
#endif  // EIGEN_HAS_C99_MATH

/***************************************************************************
* Implementation of erfc                                                   *
****************************************************************************/

template<typename Scalar>
struct erfc_impl
{
  EIGEN_DEVICE_FUNC
  static EIGEN_STRONG_INLINE Scalar run(const Scalar&)
  {
    EIGEN_STATIC_ASSERT((internal::is_same<Scalar, Scalar>::value == false),
                        THIS_TYPE_IS_NOT_SUPPORTED);
    return Scalar(0);
  }
};

template<typename Scalar>
struct erfc_retval
{
  typedef Scalar type;
};

#ifdef EIGEN_HAS_C99_MATH
template<>
struct erfc_impl<float>
{
  EIGEN_DEVICE_FUNC
  static EIGEN_STRONG_INLINE float run(const float x) { return ::erfcf(x); }
};

template<>
struct erfc_impl<double>
{
  EIGEN_DEVICE_FUNC
  static EIGEN_STRONG_INLINE double run(const double x) { return ::erfc(x); }
};
#endif  // EIGEN_HAS_C99_MATH

}  // end namespace internal


namespace numext {

template<typename Scalar>
EIGEN_DEVICE_FUNC
inline EIGEN_MATHFUNC_RETVAL(lgamma, Scalar) lgamma(const Scalar& x)
{
  return EIGEN_MATHFUNC_IMPL(lgamma, Scalar)::run(x);
}

template<typename Scalar>
EIGEN_DEVICE_FUNC
inline EIGEN_MATHFUNC_RETVAL(erf, Scalar) erf(const Scalar& x)
{
  return EIGEN_MATHFUNC_IMPL(erf, Scalar)::run(x);
}

template<typename Scalar>
EIGEN_DEVICE_FUNC
inline EIGEN_MATHFUNC_RETVAL(erfc, Scalar) erfc(const Scalar& x)
{
  return EIGEN_MATHFUNC_IMPL(erfc, Scalar)::run(x);
}

}  // end namespace numext

}  // end namespace Eigen

#endif  // EIGEN_SPECIAL_FUNCTIONS_H