26 #if defined (HAVE_CONFIG_H)
38 #include <type_traits>
49 return dv.
ndims () == 2 && (dv(0) == 1 || dv(1) == 1);
63 if (y >
x[
n-1] || y <
x[0])
66 #if defined (EXHAUSTIF)
67 for (j = 0; j <
n - 1; j++)
69 if (
x[j] <= y && y <=
x[j+1])
98 if (y >
x[0] || y <
x[
n-1])
101 #if defined (EXHAUSTIF)
102 for (j = 0; j <
n - 1; j++)
104 if (
x[j+1] <= y && y <=
x[j])
132 template <
typename T,
typename DT>
136 const DT *v,
const T **y, DT *vi)
148 for (
int i = 0; i <
n; i++)
150 index[i] =
lookup (
x[i], size[i], y[i][
m]);
151 out = index[i] == -1;
158 coef[2*i+1] = (y[i][
m] -
x[i][j])/(
x[i][j+1] -
x[i][j]);
159 coef[2*i] = 1 - coef[2*i+1];
170 for (
int i = 0; i < (1 <<
n); i++)
176 for (
int j = 0; j <
n; j++)
180 l +=
scale[j] * (index[j] + bit);
190 template <
typename MT,
typename DMT,
typename DT>
194 static_assert(std::is_same<DT, typename DMT::element_type>::value,
195 "Type DMT must be an ArrayType with elements of type DT.");
196 using T =
typename MT::element_type;
200 DMT Vi = DMT (Y[0].dims ());
205 for (
int i = 0; i <
n; i++)
208 size[i] =
V.dims ()(i);
214 const DT *v =
V.data ();
215 DT *vi = Vi.fortran_vec ();
222 for (
int i = 1; i <
n; i++)
230 for (
int i = 0; i <
n; i++)
232 if (X[i].dims () !=
V.dims ())
233 error (
"interpn: incompatible size of argument number %d", i+1);
238 tmp(j) = X[i](
scale[i]*j);
244 for (
int i = 0; i <
n; i++)
246 if (!
isvector (X[i]) && X[i].numel () != size[i])
247 error (
"interpn: incompatible size of argument number %d", i+1);
270 DEFUN (__lin_interpn__, args, ,
276 int nargin = args.length ();
278 if (nargin < 2 || nargin % 2 == 0)
284 int n = (nargin-1)/2;
286 if (args(
n).is_single_type ())
291 for (
int i = 0; i <
n; i++)
293 X[i] = args(i).float_array_value ();
294 Y[i] = args(
n+i+1).float_array_value ();
296 if (Y[0].dims () != Y[i].dims ())
297 error (
"interpn: incompatible size of argument number %d",
n+i+2);
300 if (args(
n).iscomplex ())
318 for (
int i = 0; i <
n; i++)
320 X[i] = args(i).array_value ();
321 Y[i] = args(
n+i+1).array_value ();
323 if (Y[0].dims () != Y[i].dims ())
324 error (
"interpn: incompatible size of argument number %d",
n+i+2);
327 if (args(
n).iscomplex ())
335 const NDArray V = args(
n).array_value ();
359 OCTAVE_END_NAMESPACE(
octave)
octave_idx_type lookup(const T *x, octave_idx_type n, T y)
bool isvector(const T &array)
void lin_interpn(int n, const octave_idx_type *size, const octave_idx_type *scale, octave_idx_type Ni, DT extrapval, const T **x, const DT *v, const T **y, DT *vi)
Vector representing the dimensions (size) of an Array.
octave_idx_type ndims() const
Number of dimensions.
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
void() error(const char *fmt,...)
void scale(Matrix &m, double x, double y, double z)
F77_RET_T const F77_INT const F77_INT const F77_INT const F77_DBLE const F77_DBLE F77_INT F77_DBLE * V
F77_RET_T const F77_DBLE * x
std::complex< double > Complex
std::complex< float > FloatComplex
#define OCTAVE_LOCAL_BUFFER(T, buf, size)