Skip to content

Commit

Permalink
remove old interpolator
Browse files Browse the repository at this point in the history
  • Loading branch information
philippwindischhofer committed Feb 2, 2024
1 parent b2b2bce commit 42c1342
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 103 deletions.
101 changes: 0 additions & 101 deletions include/Eisvogel/Interpolator.hh
Original file line number Diff line number Diff line change
@@ -1,52 +1,10 @@
#ifndef __INTERPOLATOR_HH
#define __INTERPOLATOR_HH

#include <cmath>
#include <iostream>
#include <type_traits>

#include "Common.hh"
#include "Kernels.hh"
#include "NDArray.hh"
#include "IteratorUtils.hh"

#include "CoordUtils.hh"

template <typename FuncT, typename KernelT,
typename ValueT = std::invoke_result_t<FuncT, GridVector&>>
ValueT InterpolateFunc(FuncT func, KernelT& kernel, CoordVector& target_inds) {

std::size_t dims = target_inds.size();

GridVector start_inds(dims, 0);
GridVector end_inds(dims, 0);

for(std::size_t i = 0; i < dims; i++) {
scalar_t start_ind = std::ceil(target_inds(i) - kernel.Support());
scalar_t end_ind = std::floor(target_inds(i) + kernel.Support() + 1);

start_inds(i) = int(start_ind);
end_inds(i) = int(end_ind);
}

ValueT interpolated_value = ValueT();

// iterate over all dimensions
for(GridCounter cnt(start_inds, end_inds); cnt.running(); ++cnt) {

scalar_t kernel_weight = 1.0;
for(std::size_t i = 0; i < dims; i++) {
kernel_weight *= kernel(target_inds(i) - cnt(i));
}

ValueT cur_val = func(cnt.index());

interpolated_value += cur_val * kernel_weight;
}

return interpolated_value;
}

template <typename KernelT, typename FuncT,
typename ValueT = std::invoke_result_t<FuncT, GridVector&>>
ValueT InterpolateFuncNew(FuncT func, CoordVector& target_inds) {
Expand Down Expand Up @@ -82,63 +40,4 @@ ValueT InterpolateFuncNew(FuncT func, CoordVector& target_inds) {
return interpolated_value;
}

template <template<typename, std::size_t> class ArrayT, typename ValueT, std::size_t dims>
class Interpolator {

public:

Interpolator(ArrayT<ValueT, dims>& data, const Kernel& kernel) :
m_data(data), m_kernel(kernel) { };

template <typename... FracInds>
ValueT Interpolate(FracInds... frac_inds) const requires(sizeof...(FracInds) == dims) {
DenseVector<scalar_t> target_inds({static_cast<scalar_t>(frac_inds)...});
return Interpolate(target_inds);
}

ValueT Interpolate(const DenseVector<scalar_t>& target_inds) const {
IndexVector start_inds(dims, 0);
IndexVector end_inds(dims, 0);

for(std::size_t i = 0; i < dims; i++) {
scalar_t start_ind = std::ceil(target_inds(i) - m_kernel.Support());
scalar_t end_ind = std::floor(target_inds(i) + m_kernel.Support() + 1);

// extrapolation is not permitted
if((start_ind < 0) || (end_ind > m_data.shape(i))) {
std::cerr << "Extrapolation is not permitted" << std::endl;
throw;
}

start_inds(i) = std::size_t(start_ind);
end_inds(i) = std::size_t(end_ind);
}

ValueT interpolated_value = ValueT();

// iterate over all dimensions
for(IndexCounter cnt(start_inds, end_inds); cnt.running(); ++cnt) {

ValueT kernel_weight = 1.0;
for(std::size_t i = 0; i < dims; i++) {
kernel_weight *= m_kernel(target_inds(i) - cnt(i));
}

scalar_t cur_val = m_data(cnt.index());
if(std::isnan(cur_val)) {
std::cout << "Unallowed region" << std::endl;
throw;
}
interpolated_value += cur_val * kernel_weight;
}

return interpolated_value;
}

private:

ArrayT<ValueT, dims>& m_data;
const Kernel& m_kernel;
};

#endif
2 changes: 0 additions & 2 deletions src/Interpolator.cxx

This file was deleted.

0 comments on commit 42c1342

Please sign in to comment.