This repository has been archived by the owner on Nov 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
/
math_functions-inl.h
146 lines (103 loc) · 3.01 KB
/
math_functions-inl.h
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
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/*!
* \file special_functions-inl.h
* \brief
* \author Matthias Seeger
*/
#ifndef MXNET_OPERATOR_MATH_FUNCTIONS_INL_H_
#define MXNET_OPERATOR_MATH_FUNCTIONS_INL_H_
#include "math.h"
namespace mxnet {
namespace op {
namespace math {
// Wrappers for math.h unary and binary functions
// - For DType != double: math::name(a) does computation in float
// and returns float
// - For DType == double: math::name(a) does computation in double
// and returns double
#define MXNET_UNARY_MATH_FUNC(name) \
template<typename DType> MSHADOW_XINLINE \
float name(DType a) { \
return ::name##f(static_cast<float>(a)); \
} \
MSHADOW_XINLINE \
double name(double a) { \
return ::name(a); \
}
#define MXNET_BINARY_MATH_FUNC(name) \
template<typename DType> MSHADOW_XINLINE \
float name(DType a, DType b) { \
return ::name##f(static_cast<float>(a), static_cast<float>(b)); \
} \
MSHADOW_XINLINE \
double name(double a, double b) { \
return ::name(a, b); \
}
MXNET_UNARY_MATH_FUNC(erf)
MXNET_UNARY_MATH_FUNC(exp)
MXNET_UNARY_MATH_FUNC(expm1)
MXNET_UNARY_MATH_FUNC(tanh)
MXNET_UNARY_MATH_FUNC(log1p)
MXNET_UNARY_MATH_FUNC(log)
MXNET_UNARY_MATH_FUNC(log10)
MXNET_UNARY_MATH_FUNC(log2)
MXNET_UNARY_MATH_FUNC(sin)
MXNET_UNARY_MATH_FUNC(cos)
MXNET_UNARY_MATH_FUNC(tan)
MXNET_UNARY_MATH_FUNC(asin)
MXNET_UNARY_MATH_FUNC(sqrt)
MXNET_UNARY_MATH_FUNC(acos)
MXNET_UNARY_MATH_FUNC(atan)
MXNET_UNARY_MATH_FUNC(sinh)
MXNET_UNARY_MATH_FUNC(cosh)
MXNET_UNARY_MATH_FUNC(asinh)
MXNET_UNARY_MATH_FUNC(acosh)
MXNET_UNARY_MATH_FUNC(atanh)
MXNET_UNARY_MATH_FUNC(fabs)
MXNET_UNARY_MATH_FUNC(cbrt)
MXNET_UNARY_MATH_FUNC(round)
MXNET_UNARY_MATH_FUNC(ceil)
MXNET_UNARY_MATH_FUNC(floor)
MXNET_UNARY_MATH_FUNC(trunc)
MXNET_UNARY_MATH_FUNC(tgamma)
MXNET_UNARY_MATH_FUNC(lgamma)
MXNET_BINARY_MATH_FUNC(hypot)
MXNET_BINARY_MATH_FUNC(pow)
template<typename DType> MSHADOW_XINLINE
float id(DType a) {
return static_cast<float>(a);
}
MSHADOW_XINLINE
double id(double a) {
return a;
}
template<typename DType> MSHADOW_XINLINE
float sqr(DType a) {
float af(static_cast<float>(a));
return af * af;
}
MSHADOW_XINLINE
double sqr(double a) {
return a * a;
}
} // namespace math
} // namespace op
} // namespace mxnet
#endif // MXNET_OPERATOR_MATH_FUNCTIONS_INL_H_