3#include <isce3/except/Error.h>
4#include <isce3/math/Sinc.h>
6namespace isce3 {
namespace cuda {
namespace core {
11CUDA_HOSTDEV
inline T samplingWindow(T t, T halfwidth, T bandwidth)
13 auto c = T(M_PI) * halfwidth * (1 - bandwidth);
14 auto tf = t / halfwidth;
15 auto y = std::sqrt(1 - tf * tf);
16 return std::cosh(c * y) / std::cosh(c);
21template<
typename T,
class Derived>
24 return static_cast<const Derived*
>(
this)->eval(t);
28constexpr T BartlettKernel<T>::eval(
double t)
const
30 double t2 = std::abs(t / Base::halfwidth());
31 return (t2 > 1.) ? T(0.) : T(1. - t2);
39 throw isce3::except::RuntimeError(ISCE_SRCINFO(),
40 "Require 0 < bandwidth < 1");
45CUDA_HOSTDEV
inline T KnabKernel<T>::eval(
double t)
const
47 using isce3::math::sinc;
48 auto x =
static_cast<T
>(t);
49 return sinc(x) * detail::samplingWindow(t, Base::halfwidth(), bandwidth());
54 : Base(kernel.width()), _table(kernel._table.data().get()),
55 _imax(kernel._imax), _rdx(kernel._rdx)
59CUDA_DEV
inline T TabulatedKernelView<T>::eval(
double t)
const
62 auto at = std::abs(t);
63 if (at > Base::halfwidth()) {
71 auto i =
static_cast<int>(std::floor(x));
72 i = std::min(i, _imax);
76 auto y1 = _table[i + 1];
77 return y0 + (x - i) * (y1 - y0);
81template<
class OtherKernel>
83 : Base(kernel.
width())
86 throw isce3::except::LengthError(ISCE_SRCINFO(),
87 "Require table size >= 2");
97 std::vector<T> h_table(n);
98 for (
int i = 0; i < n; ++i) {
100 h_table[i] =
static_cast<T
>(kernel(x));
109 : Base(other.
width()), _table(other.table())
111 auto n =
static_cast<int>(other.table().size());
119CUDA_DEV
inline T TabulatedKernel<T>::eval(
double t)
const
125ChebyKernelView<T>::ChebyKernelView(
const ChebyKernel<T>& kernel)
126 : Base(kernel.width()), _coeffs(kernel._coeffs.data().get()),
127 _n(static_cast<int>(kernel._coeffs.size())), _scale(kernel._scale)
131CUDA_DEV
inline T ChebyKernelView<T>::eval(
double t)
const
134 auto at = std::abs(t);
135 if (at > Base::halfwidth()) {
140 auto q = (T(at) * _scale) - T(1.);
141 auto twoq = T(2.) * q;
144 T bk = 0., bk1 = 0., bk2 = 0.;
145 for (
int i = _n - 1; i > 0; --i) {
146 bk = _coeffs[i] + twoq * bk1 - bk2;
150 return _coeffs[0] + q * bk1 - bk2;
154template<
class OtherKernel>
156 : Base(kernel.
width()), _scale(4. / kernel.
width())
159 throw isce3::except::LengthError(ISCE_SRCINFO(),
160 "Need at least one coefficient");
166 std::vector<T> q(n), fx(n);
167 for (
int i = 0; i < n; ++i) {
168 q[i] = M_PI * (2. * i + 1.) / (2. * n);
171 auto x = (std::cos(q[i]) + 1.) / _scale;
173 fx[i] =
static_cast<T
>(kernel(x));
176 std::vector<T> h_coeffs(n);
177 for (
int i = 0; i < n; ++i) {
179 for (
int j = 0; j < n; ++j) {
180 T w = std::cos(i * q[j]);
181 h_coeffs[i] += w * fx[j];
183 h_coeffs[i] *= 2. / n;
192CUDA_DEV
inline T ChebyKernel<T>::eval(
double t)
const
Tabulated Kernel.
Definition Kernels.h:133
A non-owning reference to a ChebyKernel object.
Definition Kernels.h:204
ChebyKernel(const OtherKernel &kernel, int n)
Construct a new ChebyKernel object by computing a fit to another kernel.
Definition Kernels.icc:155
CUDA_HOSTDEV T operator()(double t) const
Evaluate the kernel at a given location in [-halfwidth, halfwidth].
Definition Kernels.icc:22
constexpr double width() const noexcept
Definition Kernels.h:41
constexpr double halfwidth() const noexcept
Definition Kernels.h:34
constexpr KnabKernel(double width, double bandwidth)
Construct a new KnabKernel object.
Definition Kernels.icc:35
constexpr double bandwidth() const noexcept
Get bandwidth of the kernel.
Definition Kernels.h:118
A non-owning reference to a TabulatedKernel object.
Definition Kernels.h:130
Tabulated kernel.
Definition Kernels.h:161
TabulatedKernel(const OtherKernel &kernel, int n)
Construct a new TabulatedKernel object.
Definition Kernels.icc:82
base interpolator is an abstract base class
Definition BinarySearchFunc.cpp:5