Skip to content
Snippets Groups Projects

ENH: Allow `Splinterpolator` instances to be created from an existing set of spline coefficients, and extend extrapolation options

Merged Paul McCarthy requested to merge enh/splinterpolator into master
Compare and Show latest version
1 file
+ 23
5
Compare changes
  • Side-by-side
  • Inline
+ 23
5
@@ -64,8 +64,7 @@ public:
ExtrapolationType et=Zeros,
unsigned int order=3,
bool copy_low_order=true,
Utilities::NoOfThreads
nthr=Utilities::NoOfThreads(1),
Utilities::NoOfThreads nthr=Utilities::NoOfThreads(1),
double prec=1e-8,
bool data_are_coefs=false)
: _valid(false), _own_coef(false), _coef(0), _cptr(0), _ndim(0), _nthr(nthr._n)
@@ -84,6 +83,22 @@ public:
Splinterpolator& operator=(const Splinterpolator& src)
{ if(_own_coef) delete [] _coef; assign(src); return(*this); }
// Copy the spline coefficients into dest.
void Copy(std::vector<T>& dest)
{
unsigned int N = 1;
for (auto d : _dim) {
N *= d;
}
dest.resize(N);
auto coefs = coef_ptr();
for (unsigned int i = 0; i < N; i++) {
dest[i] = coefs[i];
}
}
// Set new data in Splinterpolator.
void Set(const T *data_or_coefs,
const std::vector<unsigned int>& dim,
@@ -1439,16 +1454,19 @@ void Splinterpolator<T>::assign(const Splinterpolator<T>& src)
template<class T>
bool Splinterpolator<T>::calc_coef(const T *data_or_coefs, bool copy, bool data_are_coefs)
{
if (_order < 2 && !copy) { _cptr = data_or_coefs; return(false); }
// No copy, and nearest/interp, or pre-calculated
// coefficients - just take a pointer to the data
if (_order < 2 && !copy) { _cptr = data_or_coefs; return(false); }
if (data_are_coefs && !copy) { _cptr = data_or_coefs; return(false); }
// Allocate memory and put the original data into _coef
//
unsigned int ts=1;
for (unsigned int i=0; i<_dim.size(); i++) ts *= _dim[i];
_coef = new T[ts];
memcpy(_coef,data_or_coefs,ts*sizeof(T));
if (_order < 2) return(true); // If nearest neighbour or linear, that's all we need
if (_order < 2) return(true); // If nearest neighbour or linear, that's all we need
if (data_are_coefs) return(true); // User has given us pre-calculated coefficients
// Loop over all non-singleton dimensions and deconvolve along them
//
Loading