kfr

Fast, modern C++ DSP framework, FFT, Sample Rate Conversion, FIR/IIR/Biquad Filters (SSE, AVX, AVX-512, ARM NEON)
Log | Files | Refs | README

commit eed5485a44374c0ac3d505796156ab30512f63cb
parent be4f1881851275d946fdcd97c0caa51036976706
Author: [email protected] <[email protected]>
Date:   Wed, 20 Jul 2016 15:09:39 +0300

Added more hyperbolic functions

Diffstat:
Minclude/kfr/all.hpp | 2+-
Minclude/kfr/base/complex.hpp | 8++++----
Ainclude/kfr/base/hyperbolic.hpp | 183+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dinclude/kfr/base/sinh_cosh.hpp | 143-------------------------------------------------------------------------------
Minclude/kfr/math.hpp | 2+-
Msources.cmake | 2+-
6 files changed, 190 insertions(+), 150 deletions(-)

diff --git a/include/kfr/all.hpp b/include/kfr/all.hpp @@ -43,7 +43,7 @@ #include "base/select.hpp" #include "base/shuffle.hpp" #include "base/sin_cos.hpp" -#include "base/sinh_cosh.hpp" +#include "kfr/base/hyperbolic.hpp" #include "base/sqrt.hpp" #include "base/tan.hpp" #include "base/types.hpp" diff --git a/include/kfr/base/complex.hpp b/include/kfr/base/complex.hpp @@ -30,7 +30,7 @@ #include "operators.hpp" #include "select.hpp" #include "sin_cos.hpp" -#include "sinh_cosh.hpp" +#include "hyperbolic.hpp" #include "sqrt.hpp" #pragma clang diagnostic push @@ -263,14 +263,14 @@ namespace internal { template <cpu_t c = cpu_t::native> -struct in_complex : in_select<c>, in_sin_cos<c>, in_sinh_cosh<c>, in_sqrt<c>, in_atan<c>, in_log_exp<c> +struct in_complex : in_select<c>, in_sin_cos<c>, in_hyperbolic<c>, in_sqrt<c>, in_atan<c>, in_log_exp<c> { constexpr static cpu_t cur = c; using in_sqrt<c>::sqrt; using in_sin_cos<c>::sincos; using in_sin_cos<c>::cossin; - using in_sinh_cosh<c>::sinhcosh; - using in_sinh_cosh<c>::coshsinh; + using in_hyperbolic<c>::sinhcosh; + using in_hyperbolic<c>::coshsinh; using in_atan<c>::atan2; using in_log_exp<c>::log; using in_log_exp<c>::log2; diff --git a/include/kfr/base/hyperbolic.hpp b/include/kfr/base/hyperbolic.hpp @@ -0,0 +1,183 @@ +/** + * Copyright (C) 2016 D Levin (http://www.kfrlib.com) + * This file is part of KFR + * + * KFR is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * KFR is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with KFR. + * + * If GPL is not suitable for your project, you must purchase a commercial license to use KFR. + * Buying a commercial license is mandatory as soon as you develop commercial activities without + * disclosing the source code of your own applications. + * See http://www.kfrlib.com for details. + */ +#pragma once +#include "abs.hpp" +#include "constants.hpp" +#include "function.hpp" +#include "log_exp.hpp" +#include "min_max.hpp" +#include "operators.hpp" +#include "select.hpp" + +namespace kfr +{ + +namespace internal +{ + +template <cpu_t c = cpu_t::native> +struct in_hyperbolic : in_log_exp<c> +{ + constexpr static cpu_t cur = c; + +private: + using in_log_exp<c>::exp; + +public: + template <typename T, size_t N> + KFR_SINTRIN vec<T, N> sinh(vec<T, N> x) + { + return (exp(x) - exp(-x)) * T(0.5); + } + + template <typename T, size_t N> + KFR_SINTRIN vec<T, N> cosh(vec<T, N> x) + { + return (exp(x) + exp(-x)) * T(0.5); + } + + template <typename T, size_t N> + KFR_SINTRIN vec<T, N> tanh(vec<T, N> x) + { + x = -2 * x; + return (1 - exp(x)) / (1 + exp(x)); + } + + template <typename T, size_t N> + KFR_SINTRIN vec<T, N> coth(vec<T, N> x) + { + x = -2 * x; + return (1 + exp(x)) / (1 - exp(x)); + } + + template <typename T, size_t N, KFR_ENABLE_IF(N > 1)> + KFR_SINTRIN vec<T, N> sinhcosh(vec<T, N> x) + { + const vec<T, N> a = exp(x); + const vec<T, N> b = exp(-x); + return subadd(a, b) * T(0.5); + } + + template <typename T, size_t N, KFR_ENABLE_IF(N > 1)> + KFR_SINTRIN vec<T, N> coshsinh(vec<T, N> x) + { + const vec<T, N> a = exp(x); + const vec<T, N> b = exp(-x); + return addsub(a, b) * T(0.5); + } + KFR_HANDLE_SCALAR(sinh) + KFR_HANDLE_SCALAR(cosh) + KFR_HANDLE_SCALAR(tanh) + KFR_HANDLE_SCALAR(coth) + KFR_HANDLE_SCALAR(sinhcosh) + KFR_HANDLE_SCALAR(coshsinh) + KFR_SPEC_FN(in_hyperbolic, sinh) + KFR_SPEC_FN(in_hyperbolic, cosh) + KFR_SPEC_FN(in_hyperbolic, tanh) + KFR_SPEC_FN(in_hyperbolic, coth) + KFR_SPEC_FN(in_hyperbolic, sinhcosh) + KFR_SPEC_FN(in_hyperbolic, coshsinh) +}; +} + +namespace native +{ +using fn_sinh = internal::in_hyperbolic<>::fn_sinh; +template <typename T1, KFR_ENABLE_IF(is_numeric<T1>::value)> +KFR_INTRIN ftype<T1> sinh(const T1& x) +{ + return internal::in_hyperbolic<>::sinh(x); +} + +template <typename E1, KFR_ENABLE_IF(is_input_expression<E1>::value)> +KFR_INTRIN expr_func<fn_sinh, E1> sinh(E1&& x) +{ + return { fn_sinh(), std::forward<E1>(x) }; +} + +using fn_cosh = internal::in_hyperbolic<>::fn_cosh; +template <typename T1, KFR_ENABLE_IF(is_numeric<T1>::value)> +KFR_INTRIN ftype<T1> cosh(const T1& x) +{ + return internal::in_hyperbolic<>::cosh(x); +} + +template <typename E1, KFR_ENABLE_IF(is_input_expression<E1>::value)> +KFR_INTRIN expr_func<fn_cosh, E1> cosh(E1&& x) +{ + return { fn_cosh(), std::forward<E1>(x) }; +} + +using fn_tanh = internal::in_hyperbolic<>::fn_tanh; +template <typename T1, KFR_ENABLE_IF(is_numeric<T1>::value)> +KFR_INTRIN ftype<T1> tanh(const T1& x) +{ + return internal::in_hyperbolic<>::tanh(x); +} + +template <typename E1, KFR_ENABLE_IF(is_input_expression<E1>::value)> +KFR_INTRIN expr_func<fn_tanh, E1> tanh(E1&& x) +{ + return { fn_tanh(), std::forward<E1>(x) }; +} + +using fn_coth = internal::in_hyperbolic<>::fn_coth; +template <typename T1, KFR_ENABLE_IF(is_numeric<T1>::value)> +KFR_INTRIN ftype<T1> coth(const T1& x) +{ + return internal::in_hyperbolic<>::coth(x); +} + +template <typename E1, KFR_ENABLE_IF(is_input_expression<E1>::value)> +KFR_INTRIN expr_func<fn_coth, E1> coth(E1&& x) +{ + return { fn_coth(), std::forward<E1>(x) }; +} + +using fn_sinhcosh = internal::in_hyperbolic<>::fn_sinhcosh; +template <typename T1, KFR_ENABLE_IF(is_numeric<T1>::value)> +KFR_INTRIN ftype<T1> sinhcosh(const T1& x) +{ + return internal::in_hyperbolic<>::sinhcosh(x); +} + +template <typename E1, KFR_ENABLE_IF(is_input_expression<E1>::value)> +KFR_INTRIN expr_func<fn_sinhcosh, E1> sinhcosh(E1&& x) +{ + return { fn_sinhcosh(), std::forward<E1>(x) }; +} + +using fn_coshsinh = internal::in_hyperbolic<>::fn_coshsinh; +template <typename T1, KFR_ENABLE_IF(is_numeric<T1>::value)> +KFR_INTRIN ftype<T1> coshsinh(const T1& x) +{ + return internal::in_hyperbolic<>::coshsinh(x); +} + +template <typename E1, KFR_ENABLE_IF(is_input_expression<E1>::value)> +KFR_INTRIN expr_func<fn_coshsinh, E1> coshsinh(E1&& x) +{ + return { fn_coshsinh(), std::forward<E1>(x) }; +} +} +} diff --git a/include/kfr/base/sinh_cosh.hpp b/include/kfr/base/sinh_cosh.hpp @@ -1,143 +0,0 @@ -/** - * Copyright (C) 2016 D Levin (http://www.kfrlib.com) - * This file is part of KFR - * - * KFR is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * KFR is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with KFR. - * - * If GPL is not suitable for your project, you must purchase a commercial license to use KFR. - * Buying a commercial license is mandatory as soon as you develop commercial activities without - * disclosing the source code of your own applications. - * See http://www.kfrlib.com for details. - */ -#pragma once -#include "abs.hpp" -#include "constants.hpp" -#include "function.hpp" -#include "log_exp.hpp" -#include "min_max.hpp" -#include "operators.hpp" -#include "select.hpp" - -namespace kfr -{ - -namespace internal -{ - -template <cpu_t c = cpu_t::native> -struct in_sinh_cosh : in_log_exp<c> -{ - constexpr static cpu_t cur = c; - -private: - using in_log_exp<c>::exp; - -public: - template <typename T, size_t N> - KFR_SINTRIN vec<T, N> sinh(vec<T, N> x) - { - return (exp(x) - exp(-x)) * T(0.5); - } - - template <typename T, size_t N> - KFR_SINTRIN vec<T, N> cosh(vec<T, N> x) - { - return (exp(x) + exp(-x)) * T(0.5); - } - - template <typename T, size_t N, KFR_ENABLE_IF(N > 1)> - KFR_SINTRIN vec<T, N> sinhcosh(vec<T, N> x) - { - const vec<T, N> a = exp(x); - const vec<T, N> b = exp(-x); - return subadd(a, b) * T(0.5); - } - - template <typename T, size_t N, KFR_ENABLE_IF(N > 1)> - KFR_SINTRIN vec<T, N> coshsinh(vec<T, N> x) - { - const vec<T, N> a = exp(x); - const vec<T, N> b = exp(-x); - return addsub(a, b) * T(0.5); - } - KFR_SPEC_FN(in_sinh_cosh, sinh) - KFR_SPEC_FN(in_sinh_cosh, cosh) - KFR_SPEC_FN(in_sinh_cosh, sinhcosh) - KFR_SPEC_FN(in_sinh_cosh, coshsinh) -}; -} - -namespace native -{ -using fn_sinh = internal::in_sinh_cosh<>::fn_sinh; -template <typename T1, KFR_ENABLE_IF(is_numeric<T1>::value)> - -KFR_INTRIN ftype<T1> sinh(const T1& x) -{ - return internal::in_sinh_cosh<>::sinh(x); -} - -template <typename E1, KFR_ENABLE_IF(is_input_expression<E1>::value)> - -KFR_INTRIN expr_func<fn_sinh, E1> sinh(E1&& x) -{ - return { fn_sinh(), std::forward<E1>(x) }; -} - -using fn_cosh = internal::in_sinh_cosh<>::fn_cosh; -template <typename T1, KFR_ENABLE_IF(is_numeric<T1>::value)> - -KFR_INTRIN ftype<T1> cosh(const T1& x) -{ - return internal::in_sinh_cosh<>::cosh(x); -} - -template <typename E1, KFR_ENABLE_IF(is_input_expression<E1>::value)> - -KFR_INTRIN expr_func<fn_cosh, E1> cosh(E1&& x) -{ - return { fn_cosh(), std::forward<E1>(x) }; -} - -using fn_sinhcosh = internal::in_sinh_cosh<>::fn_sinhcosh; -template <typename T1, KFR_ENABLE_IF(is_numeric<T1>::value)> - -KFR_INTRIN ftype<T1> sinhcosh(const T1& x) -{ - return internal::in_sinh_cosh<>::sinhcosh(x); -} - -template <typename E1, KFR_ENABLE_IF(is_input_expression<E1>::value)> - -KFR_INTRIN expr_func<fn_sinhcosh, E1> sinhcosh(E1&& x) -{ - return { fn_sinhcosh(), std::forward<E1>(x) }; -} - -using fn_coshsinh = internal::in_sinh_cosh<>::fn_coshsinh; -template <typename T1, KFR_ENABLE_IF(is_numeric<T1>::value)> - -KFR_INTRIN ftype<T1> coshsinh(const T1& x) -{ - return internal::in_sinh_cosh<>::coshsinh(x); -} - -template <typename E1, KFR_ENABLE_IF(is_input_expression<E1>::value)> - -KFR_INTRIN expr_func<fn_coshsinh, E1> coshsinh(E1&& x) -{ - return { fn_coshsinh(), std::forward<E1>(x) }; -} -} -} diff --git a/include/kfr/math.hpp b/include/kfr/math.hpp @@ -41,7 +41,7 @@ #include "base/select.hpp" #include "base/shuffle.hpp" #include "base/sin_cos.hpp" -#include "base/sinh_cosh.hpp" +#include "kfr/base/hyperbolic.hpp" #include "base/sqrt.hpp" #include "base/tan.hpp" diff --git a/sources.cmake b/sources.cmake @@ -38,7 +38,7 @@ set( ${PROJECT_SOURCE_DIR}/include/kfr/base/select.hpp ${PROJECT_SOURCE_DIR}/include/kfr/base/shuffle.hpp ${PROJECT_SOURCE_DIR}/include/kfr/base/sin_cos.hpp - ${PROJECT_SOURCE_DIR}/include/kfr/base/sinh_cosh.hpp + ${PROJECT_SOURCE_DIR}/include/kfr/base/hyperbolic.hpp ${PROJECT_SOURCE_DIR}/include/kfr/base/sqrt.hpp ${PROJECT_SOURCE_DIR}/include/kfr/base/tan.hpp ${PROJECT_SOURCE_DIR}/include/kfr/base/types.hpp