isce3 0.25.0
Loading...
Searching...
No Matches
Interp1d.h
1#pragma once
2
3#include <isce3/math/complexOperations.h>
4
5#include "../Kernels.h"
6
7namespace isce3::core::detail {
8
22template<typename KernelType>
23void interp1d_coeffs(const Kernel<KernelType>& kernel, const double t,
24 long* low, KernelType coeffs[])
25{
26 int width = int(ceil(kernel.width()));
27 long i0 = 0;
28 if (width % 2 == 0) {
29 i0 = static_cast<long>(ceil(t));
30 } else {
31 i0 = static_cast<long>(round(t));
32 }
33 *low = i0 - width / 2; // integer division implicit floor()
34 for (int i = 0; i < width; ++i) {
35 double ti = i + (*low) - t;
36 coeffs[i] = kernel(ti);
37 }
38}
39
54template<typename DataType>
55const DataType* get_contiguous_view_or_copy(DataType block[], int width,
56 long low, const DataType* data, size_t size, size_t stride,
57 bool periodic)
58{
59 const long high = low + width;
60 if ((stride == 1) and (low >= 0) and (high < size)) {
61 return &data[low];
62 }
63 // else
64 if (periodic) {
65 for (int i = 0; i < width; ++i) {
66 long j = ((low + i) % size) * stride;
67 block[i] = data[j];
68 }
69 } else {
70 for (int i = 0; i < width; ++i) {
71 long j = (low + i) * stride;
72 if ((j >= 0) and (j < size)) {
73 block[i] = data[j];
74 } else {
75 block[i] = static_cast<DataType>(0);
76 }
77 }
78 }
79 return block;
80}
81
90template<typename TX, typename TY>
91auto inner_product(const int width, const TX x[], const TY y[])
92{
93 using namespace isce3::math::complex_operations;
94 using TO = typename std::common_type<TX, TY>::type;
95 TO sum = 0;
96
97 // use SIMD instructions for the loop if possible
98 // seems dumb, but this custom reduction is required for complex
99 #pragma omp declare reduction(cpxsum:TO : omp_out += omp_in) \
100 initializer(omp_priv = 0)
101
102 #pragma omp simd reduction(cpxsum : sum)
103 for (int i = 0; i < width; ++i) {
104 sum += x[i] * y[i];
105 }
106 return sum;
107}
108
109} // namespace isce3::core::detail

Generated for ISCE3.0 by doxygen 1.13.2.