NumCpp  2.12.1
A Templatized Header Only C++ Implementation of the Python NumPy Library
kaiser.hpp
Go to the documentation of this file.
1
28#pragma once
29
30#include <cmath>
31
32#if defined(__cpp_lib_math_special_functions) || !defined(NUMCPP_NO_USE_BOOST)
33
35#include "NumCpp/NdArray.hpp"
37#include "NumCpp/Utils/sqr.hpp"
38
39namespace nc
40{
41 //============================================================================
42 // Method Description:
51 inline NdArray<double> kaiser(int32 m, double beta)
52 {
53 if (m < 1)
54 {
55 return {};
56 }
57
58 const auto mDouble = static_cast<double>(m);
59 const auto mMinus1 = mDouble - 1.;
60 const auto mMinus1Over2 = mMinus1 / 2.;
61 const auto mMinus1Squared = utils::sqr(mMinus1);
62 const auto i0Beta = special::bessel_in(0, beta);
63
64 NdArray<double> result(1, m);
65 int32 i = 0;
66 for (auto n : linspace(-mMinus1Over2, mMinus1Over2, m, EndPoint::YES))
67 {
68 auto value = beta * std::sqrt(1. - (4. * utils::sqr(n)) / mMinus1Squared);
69 result[i++] = special::bessel_in(0, value) / i0Beta;
70 }
71
72 return result;
73 }
74} // namespace nc
75
76#endif // #if defined(__cpp_lib_math_special_functions) || !defined(NUMCPP_NO_USE_BOOST)
dtype beta(GeneratorType &generator, dtype inAlpha, dtype inBeta)
Definition: Random/beta.hpp:61
auto bessel_in(dtype1 inV, dtype2 inX)
Definition: bessel_in.hpp:57
constexpr dtype sqr(dtype inValue) noexcept
Definition: sqr.hpp:42
Definition: Cartesian.hpp:40
NdArray< dtype > linspace(dtype inStart, dtype inStop, uint32 inNum=50, EndPoint endPoint=EndPoint::YES)
Definition: linspace.hpp:61
NdArray< double > kaiser(int32 m, double beta)
Definition: kaiser.hpp:51
std::int32_t int32
Definition: Types.hpp:36
auto sqrt(dtype inValue) noexcept
Definition: sqrt.hpp:48