diff options
author | Mateusz Chudyk <mateuszchudyk@gmail.com> | 2019-07-09 19:47:04 +0300 |
---|---|---|
committer | Mateusz Chudyk <mateuszchudyk@gmail.com> | 2019-07-09 22:53:05 +0300 |
commit | d8ec8fb83da8eb9dd5adb84663510595c43dfcee (patch) | |
tree | 15aad0bbb410776a72d7bf84caf325f9f28d1fa5 /kernels | |
parent | 04eb35b4bfcc316cc833a2b255ccc4557e3af805 (diff) |
Add Tanh kernel
Diffstat (limited to 'kernels')
-rw-r--r-- | kernels/implementations.inl | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/kernels/implementations.inl b/kernels/implementations.inl index 368fffb..504b650 100644 --- a/kernels/implementations.inl +++ b/kernels/implementations.inl @@ -245,6 +245,22 @@ CPU_ATTR static inline vf sigmoid(vf input) { #endif } +/* + * Tanh + */ +CPU_ATTR static inline vf tanh(vf input) { +#if defined(THIS_IS_SSE2) + assert(false && "SSE2 is not supported"); +#else + const static auto vconst_zero = setzero_ps<vf>(); + + auto e_x = exp_approx_taylor(input); + auto e_minus_x = exp_approx_taylor(sub_ps(vconst_zero, input)); + + return div_ps(sub_ps(e_x, e_minus_x), add_ps(e_x, e_minus_x)); +#endif +} + } } |