1 | #include <Functions/FunctionMathUnary.h> |
---|---|
2 | #include <Functions/FunctionFactory.h> |
3 | |
4 | namespace DB |
5 | { |
6 | |
7 | struct TanhName { static constexpr auto name = "tanh"; }; |
8 | |
9 | #if USE_FASTOPS |
10 | |
11 | namespace |
12 | { |
13 | struct Impl |
14 | { |
15 | static constexpr auto name = TanhName::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::Tanh<>(src, size, dst); |
23 | } |
24 | }; |
25 | } |
26 | |
27 | using FunctionTanh = FunctionMathUnary<Impl>; |
28 | |
29 | #else |
30 | |
31 | static double tanh(double x) |
32 | { |
33 | return 2 / (1.0 + exp(-2 * x)) - 1; |
34 | } |
35 | |
36 | using FunctionTanh = FunctionMathUnary<UnaryFunctionVectorized<TanhName, tanh>>; |
37 | #endif |
38 | |
39 | void registerFunctionTanh(FunctionFactory & factory) |
40 | { |
41 | factory.registerFunction<FunctionTanh>(FunctionFactory::CaseInsensitive); |
42 | } |
43 | |
44 | } |
45 | |
46 | |
47 |