26#if defined (HAVE_CONFIG_H)
47 return dv.
ndims () == 2 && (dv(0) == 1 || dv(1) == 1);
61 if (y >
x[n-1] || y <
x[0])
64#if defined (EXHAUSTIF)
65 for (j = 0; j < n - 1; j++)
67 if (
x[j] <= y && y <=
x[j+1])
96 if (y >
x[0] || y <
x[n-1])
99#if defined (EXHAUSTIF)
100 for (j = 0; j < n - 1; j++)
102 if (
x[j+1] <= y && y <=
x[j])
134 const T *v,
const T **y, T *vi)
146 for (
int i = 0; i < n; i++)
148 index[i] =
lookup (
x[i], size[i], y[i][m]);
149 out = index[i] == -1;
156 coef[2*i+1] = (y[i][m] -
x[i][j])/(
x[i][j+1] -
x[i][j]);
157 coef[2*i] = 1 - coef[2*i+1];
168 for (
int i = 0; i < (1 << n); i++)
174 for (
int j = 0; j < n; j++)
178 l +=
scale[j] * (index[j] + bit);
188template <
typename T,
typename M>
194 M Vi =
M (Y[0].dims ());
199 for (
int i = 0; i < n; i++)
202 size[i] =
V.dims ()(i);
208 const T *v =
V.data ();
209 T *vi = Vi.fortran_vec ();
218 for (
int i = 1; i < n; i++)
226 for (
int i = 0; i < n; i++)
228 if (X[i].dims () !=
V.dims ())
229 error (
"interpn: incompatible size of argument number %d", i+1);
234 tmp(j) = X[i](
scale[i]*j);
240 for (
int i = 0; i < n; i++)
242 if (!
isvector (X[i]) && X[i].numel () != size[i])
243 error (
"interpn: incompatible size of argument number %d", i+1);
266DEFUN (__lin_interpn__, args, ,
272 int nargin = args.length ();
274 if (nargin < 2 || nargin % 2 == 0)
280 int n = (nargin-1)/2;
282 if (args(n).is_single_type ())
289 for (
int i = 0; i < n; i++)
291 X[i] = args(i).float_array_value ();
292 Y[i] = args(n+i+1).float_array_value ();
294 if (Y[0].dims () != Y[i].dims ())
295 error (
"interpn: incompatible size of argument number %d", n+i+2);
298 retval = lin_interpn<float, FloatNDArray> (n, X,
V, Y);
305 const NDArray V = args(n).array_value ();
307 for (
int i = 0; i < n; i++)
309 X[i] = args(i).array_value ();
310 Y[i] = args(n+i+1).array_value ();
312 if (Y[0].dims () != Y[i].dims ())
313 error (
"interpn: incompatible size of argument number %d", n+i+2);
316 retval = lin_interpn<double, NDArray> (n, X,
V, Y);
OCTAVE_NAMESPACE_BEGIN bool isvector(const T &array)
octave_idx_type lookup(const T *x, octave_idx_type n, T y)
void lin_interpn(int n, const octave_idx_type *size, const octave_idx_type *scale, octave_idx_type Ni, T extrapval, const T **x, const T *v, const T **y, T *vi)
Vector representing the dimensions (size) of an Array.
octave_idx_type ndims(void) const
Number of dimensions.
OCTINTERP_API void print_usage(void)
#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_INT const F77_INT const F77_INT const F77_DBLE const F77_DBLE F77_INT & M
F77_RET_T const F77_DBLE * x
#define OCTAVE_LOCAL_BUFFER(T, buf, size)