25
support_inplace = true;
28
int UnaryOp::load_param(const ParamDict& pd)
30
op_type = pd.get(0, 0);
36
static int unary_op_inplace(Mat& a, const Option& opt)
40
int size = static_cast<int>(a.total());
42
#pragma omp parallel for num_threads(opt.num_threads)
43
for (int i = 0; i < size; i++)
53
float operator()(const float& x) const
55
return (float)fabsf(x);
61
float operator()(const float& x) const
69
float operator()(const float& x) const
71
return (float)floorf(x);
77
float operator()(const float& x) const
79
return (float)ceilf(x);
85
float operator()(const float& x) const
93
float operator()(const float& x) const
95
return (float)sqrtf(x);
101
float operator()(const float& x) const
103
return 1.f / sqrtf(x);
109
float operator()(const float& x) const
111
return (float)expf(x);
117
float operator()(const float& x) const
119
return (float)logf(x);
125
float operator()(const float& x) const
127
return (float)sinf(x);
133
float operator()(const float& x) const
135
return (float)cosf(x);
141
float operator()(const float& x) const
143
return (float)tanf(x);
149
float operator()(const float& x) const
151
return (float)asinf(x);
157
float operator()(const float& x) const
159
return (float)acosf(x);
165
float operator()(const float& x) const
167
return (float)atanf(x);
171
struct unary_op_reciprocal
173
float operator()(const float& x) const
181
float operator()(const float& x) const
183
return (float)tanhf(x);
189
float operator()(const float& x) const
191
return (float)log10f(x);
197
float operator()(const float& x) const
201
int old_rm = fegetround();
202
fesetround(FE_TONEAREST);
204
float y = nearbyintf(x);
214
float operator()(const float& x) const
216
return (float)truncf(x);
220
int UnaryOp::forward_inplace(Mat& bottom_top_blob, const Option& opt) const
222
if (op_type == Operation_ABS)
223
return unary_op_inplace<unary_op_abs>(bottom_top_blob, opt);
225
if (op_type == Operation_NEG)
226
return unary_op_inplace<unary_op_neg>(bottom_top_blob, opt);
228
if (op_type == Operation_FLOOR)
229
return unary_op_inplace<unary_op_floor>(bottom_top_blob, opt);
231
if (op_type == Operation_CEIL)
232
return unary_op_inplace<unary_op_ceil>(bottom_top_blob, opt);
234
if (op_type == Operation_SQUARE)
235
return unary_op_inplace<unary_op_square>(bottom_top_blob, opt);
237
if (op_type == Operation_SQRT)
238
return unary_op_inplace<unary_op_sqrt>(bottom_top_blob, opt);
240
if (op_type == Operation_RSQRT)
241
return unary_op_inplace<unary_op_rsqrt>(bottom_top_blob, opt);
243
if (op_type == Operation_EXP)
244
return unary_op_inplace<unary_op_exp>(bottom_top_blob, opt);
246
if (op_type == Operation_LOG)
247
return unary_op_inplace<unary_op_log>(bottom_top_blob, opt);
249
if (op_type == Operation_SIN)
250
return unary_op_inplace<unary_op_sin>(bottom_top_blob, opt);
252
if (op_type == Operation_COS)
253
return unary_op_inplace<unary_op_cos>(bottom_top_blob, opt);
255
if (op_type == Operation_TAN)
256
return unary_op_inplace<unary_op_tan>(bottom_top_blob, opt);
258
if (op_type == Operation_ASIN)
259
return unary_op_inplace<unary_op_asin>(bottom_top_blob, opt);
261
if (op_type == Operation_ACOS)
262
return unary_op_inplace<unary_op_acos>(bottom_top_blob, opt);
264
if (op_type == Operation_ATAN)
265
return unary_op_inplace<unary_op_atan>(bottom_top_blob, opt);
267
if (op_type == Operation_RECIPROCAL)
268
return unary_op_inplace<unary_op_reciprocal>(bottom_top_blob, opt);
270
if (op_type == Operation_TANH)
271
return unary_op_inplace<unary_op_tanh>(bottom_top_blob, opt);
273
if (op_type == Operation_LOG10)
274
return unary_op_inplace<unary_op_log10>(bottom_top_blob, opt);
276
if (op_type == Operation_ROUND)
277
return unary_op_inplace<unary_op_round>(bottom_top_blob, opt);
279
if (op_type == Operation_TRUNC)
280
return unary_op_inplace<unary_op_trunc>(bottom_top_blob, opt);