1#include <Functions/FunctionMathUnary.h>
2#include <Functions/FunctionFactory.h>
3
4namespace DB
5{
6
7struct SigmoidName { static constexpr auto name = "sigmoid"; };
8
9#if USE_FASTOPS
10
11namespace
12{
13 struct Impl
14 {
15 static constexpr auto name = SigmoidName::name;
16 static constexpr auto rows_per_iteration = 0;
17 static constexpr bool always_returns_float64 = false;
18
19 template <typename T>
20 static void execute(const T * src, size_t size, T * dst)
21 {
22 NFastOps::Sigmoid<>(src, size, dst);
23 }
24 };
25}
26
27using FunctionSigmoid = FunctionMathUnary<Impl>;
28
29#else
30
31static double sigmoid(double x)
32{
33 return 1.0 / (1.0 + exp(-x));
34}
35
36using FunctionSigmoid = FunctionMathUnary<UnaryFunctionVectorized<SigmoidName, sigmoid>>;
37
38#endif
39
40void registerFunctionSigmoid(FunctionFactory & factory)
41{
42 factory.registerFunction<FunctionSigmoid>();
43}
44
45}
46
47