|
6 | 6 | #include <vector> |
7 | 7 |
|
8 | 8 | #include <finufft_common/constants.h> |
| 9 | +#include <finufft_common/utils.h> |
| 10 | +#include <finufft_spread_opts.h> |
9 | 11 |
|
10 | 12 | namespace finufft::kernel { |
11 | 13 |
|
@@ -56,15 +58,34 @@ template<class T, class F> std::vector<T> fit_monomials(F &&f, int n, T a, T b) |
56 | 58 | return c; |
57 | 59 | } |
58 | 60 |
|
59 | | -template<typename T> T evaluate_kernel(T x, T beta, T c) { |
60 | | - /* ES ("exp sqrt") kernel evaluation at single real argument: |
61 | | - phi(x) = exp(beta.(sqrt(1 - (2x/n_s)^2) - 1)), for |x| < nspread/2 |
62 | | - related to an asymptotic approximation to the Kaiser--Bessel, itself an |
63 | | - approximation to prolate spheroidal wavefunction (PSWF) of order 0. |
64 | | - This is the "reference implementation", used by eg finufft/onedim_* 2/17/17. |
65 | | - Rescaled so max is 1, Barnett 7/21/24 |
| 61 | +template<typename T> T evaluate_kernel(T x, T beta, T c, int kernel_type = 0) { |
| 62 | + /* Kernel evaluation at single real argument. |
| 63 | + kernel_type == 0 : ES ("exp sqrt") kernel (default) |
| 64 | + phi_ES(x) = exp(beta*(sqrt(1 - c*x^2) - 1)) |
| 65 | + kernel_type == 1 : Kaiser--Bessel (KB) kernel |
| 66 | + phi_KB(x) = I_0(beta*sqrt(1 - c*x^2)) / I_0(beta) |
| 67 | + Note: `std::cyl_bessel_i` from <cmath> is used for I_0. |
| 68 | + Rescaled so max is 1. |
66 | 69 | */ |
| 70 | + if (kernel_type == 1) { |
| 71 | + // Kaiser--Bessel (normalized by I0(beta)). Use std::cyl_bessel_i from <cmath>. |
| 72 | + const T inner = std::sqrt(T(1) - c * x * x); |
| 73 | + const T arg = beta * inner; |
| 74 | + const double i0_arg = ::finufft::common::cyl_bessel_i(0, static_cast<double>(arg)); |
| 75 | + const double i0_beta = ::finufft::common::cyl_bessel_i(0, static_cast<double>(beta)); |
| 76 | + return static_cast<T>(i0_arg / i0_beta); |
| 77 | + } |
| 78 | + |
| 79 | + // default to ES |
67 | 80 | return std::exp(beta * (std::sqrt(T(1) - c * x * x) - T(1))); |
68 | 81 | } |
69 | 82 |
|
| 83 | +FINUFFT_EXPORT int compute_kernel_ns(double upsampfac, double tol, int kernel_type, |
| 84 | + const finufft_spread_opts &opts); |
| 85 | + |
| 86 | +FINUFFT_EXPORT void initialize_kernel_params(finufft_spread_opts &opts, double upsampfac, |
| 87 | + double tol, int kernel_type); |
| 88 | + |
| 89 | +FINUFFT_EXPORT double sigma_max_tol(double upsampfac, int kernel_type, int max_ns); |
| 90 | + |
70 | 91 | } // namespace finufft::kernel |
0 commit comments