1 | #include <Functions/FunctionMathUnary.h> |
2 | #include <Functions/FunctionFactory.h> |
3 | |
4 | namespace DB |
5 | { |
6 | |
7 | struct SigmoidName { static constexpr auto name = "sigmoid" ; }; |
8 | |
9 | #if USE_FASTOPS |
10 | |
11 | namespace |
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 | |
27 | using FunctionSigmoid = FunctionMathUnary<Impl>; |
28 | |
29 | #else |
30 | |
31 | static double sigmoid(double x) |
32 | { |
33 | return 1.0 / (1.0 + exp(-x)); |
34 | } |
35 | |
36 | using FunctionSigmoid = FunctionMathUnary<UnaryFunctionVectorized<SigmoidName, sigmoid>>; |
37 | |
38 | #endif |
39 | |
40 | void registerFunctionSigmoid(FunctionFactory & factory) |
41 | { |
42 | factory.registerFunction<FunctionSigmoid>(); |
43 | } |
44 | |
45 | } |
46 | |
47 | |