12#include <autodiff/forward/real.hpp>
24 static_assert(Coordinates::dim == 2,
"TexLinearInterpolator2D requires 2D coordinates");
58 if (!
owner)
throw std::runtime_error(
"Cannot update data of non-owner interpolator");
60 if constexpr (std::is_same_v<NT2, autodiff::real>)
89 if constexpr (std::is_same_v<ReturnType, autodiff::real>)
90 return std::array<double, 2>{tex2D<float>(
texture, idx_y + 0.5f, idx_x + 0.5f),
91 tex2D<float>(
texture_AD, idx_y + 0.5f, idx_x + 0.5f)};
92 else if constexpr (std::is_same_v<ReturnType, float>)
93 return tex2D<float>(
texture, idx_y + 0.5f, idx_x + 0.5f);
100 idx_x = max(
static_cast<decltype(idx_x)
>(0), min(idx_x,
static_cast<decltype(idx_x)
>(
shape[0] - 1)));
101 idx_y = max(
static_cast<decltype(idx_y)
>(0), min(idx_y,
static_cast<decltype(idx_y)
>(
shape[1] - 1)));
103 uint x1 = min(ceil(idx_x +
static_cast<decltype(idx_x)
>(1e-16)),
static_cast<decltype(idx_x)
>(
shape[0] - 1));
104 const auto x0 = x1 - 1;
105 uint y1 = min(ceil(idx_y +
static_cast<decltype(idx_y)
>(1e-16)),
static_cast<decltype(idx_y)
>(
shape[1] - 1));
106 const auto y0 = y1 - 1;
113 const auto ret = corner00 * (x1 - idx_x) * (y1 - idx_y) + corner01 * (x1 - idx_x) * (idx_y - y0) +
114 corner10 * (idx_x - x0) * (y1 - idx_y) + corner11 * (idx_x - x0) * (idx_y - y0);
116 if constexpr (std::is_same_v<ReturnType, autodiff::real>) {
122 const auto ret_AD = corner00_AD * (x1 - idx_x) * (y1 - idx_y) + corner01_AD * (x1 - idx_x) * (idx_y - y0) +
123 corner10_AD * (idx_x - x0) * (y1 - idx_y) + corner11_AD * (idx_x - x0) * (idx_y - y0);
125 return std::array<double, 2>{{ret, ret_AD}};
126 }
else if constexpr (std::is_same_v<ReturnType, float>)
A linear interpolator for 2D data, using texture memory on the GPU and floating point arithmetic on t...
Definition tex_linear_interpolation_2D.hh:23
cudaArray_t device_array
Definition tex_linear_interpolation_2D.hh:147
__device__ __host__ ReturnType operator()(const float x, const float y) const
Interpolate the data at a given point.
Definition tex_linear_interpolation_2D.hh:85
ReturnType & operator[](const uint i)
cudaTextureObject_t texture_AD
Definition tex_linear_interpolation_2D.hh:152
TexLinearInterpolator2D(const std::vector< NT > &data, const Coordinates &coordinates)
Construct a TexLinearInterpolator2D object from a vector of data and a coordinate system.
typename internal::__TLITypes< NT >::ReturnType ReturnType
Definition tex_linear_interpolation_2D.hh:76
~TexLinearInterpolator2D()
std::shared_ptr< float[]> m_data
Definition tex_linear_interpolation_2D.hh:146
cudaTextureObject_t texture
Definition tex_linear_interpolation_2D.hh:148
std::shared_ptr< float[]> m_data_AD
Definition tex_linear_interpolation_2D.hh:150
const Coordinates & get_coordinates() const
Get the coordinate system of the data.
Definition tex_linear_interpolation_2D.hh:139
TexLinearInterpolator2D(const NT *data, const Coordinates &coordinates)
Construct a TexLinearInterpolator2D object from a pointer to data and a coordinate system.
const Coordinates coordinates
Definition tex_linear_interpolation_2D.hh:144
TexLinearInterpolator2D(const Coordinates &coordinates)
Construct a TexLinearInterpolator2D with internal, zeroed data and a coordinate system.
void update(const NT2 *data)
Definition tex_linear_interpolation_2D.hh:56
const ReturnType & operator[](const uint i) const
TexLinearInterpolator2D(const TexLinearInterpolator2D &other)
Construct a copy of a TexLinearInterpolator2D object.
const bool owner
Definition tex_linear_interpolation_2D.hh:154
const std::array< uint, 2 > shape
Definition tex_linear_interpolation_2D.hh:143
cudaArray_t device_array_AD
Definition tex_linear_interpolation_2D.hh:151
const uint size
Definition tex_linear_interpolation_2D.hh:142
Definition complex_math.hh:14
unsigned int uint
Definition utils.hh:22