34#if defined (HAVE_CONFIG_H)
68 if (
norm ==
static_cast<T
> (0.0))
69 error (
"filter: the first element of A must be nonzero");
72 if (dim < 0 || dim > x_dims.
ndims ())
73 error (
"filter: DIM must be a valid dimension");
80 if (si_len != ab_len - 1)
81 error (
"filter: first dimension of SI must be of length max (length (a), length (b)) - 1");
84 error (
"filter: dimensionality of SI and X must agree");
88 if (si_dims(i) != x_dims(i-1))
89 error (
"filter: dimensionality of SI and X must agree");
93 if (si_dims(i) != x_dims(i))
94 error (
"filter: dimensionality of SI and X must agree");
100 if (
norm !=
static_cast<T
> (1.0))
106 if (a_len <= 1 && si_len <= 0)
112 for (
int i = 0; i < dim; i++)
113 x_stride *= x_dims(i);
120 x_offset = num * x_len;
125 x_offset += n_strides * x_stride * (x_len - 1);
134 const T *pa = a.
data ();
135 const T *pb = b.
data ();
136 const T *px =
x.data ();
142 i++, idx += x_stride)
144 py[idx] =
psi[0] + pb[0] * px[idx];
152 psi[j] =
psi[j+1] - pa[j+1] * py[idx] + pb[j+1] * px[idx];
155 psi[si_len-1] = pb[si_len] * px[idx] - pa[si_len] * py[idx];
161 psi[0] = pb[si_len] * px[idx] - pa[si_len] * py[idx];
170 const T *pb = b.
data ();
171 const T *px =
x.data ();
177 i++, idx += x_stride)
179 py[idx] =
psi[0] + pb[0] * px[idx];
187 psi[j] =
psi[j+1] + pb[j+1] * px[idx];
190 psi[si_len-1] = pb[si_len] * px[idx];
196 psi[0] = pb[1] * px[idx];
213 else if (dim > x_dims.
ndims ())
214 error (
"filter: DIM must be a valid dimension");
221 for (
int i = dim; i > 0; i--)
222 si_dims(i) = si_dims(i-1);
227 return filter (b, a,
x, si, dim);
333 int nargin = args.length ();
335 if (nargin < 3 || nargin > 5)
343 dim = args(4).nint_value () - 1;
344 if (dim < 0 || dim >= x_dims.
ndims ())
345 error (
"filter: DIM must be a valid dimension");
352 const char *a_b_errmsg =
"filter: A and B must be vectors";
353 const char *x_si_errmsg =
"filter: X and SI must be arrays";
355 bool isfloat = (args(0).is_single_type ()
356 || args(1).is_single_type ()
357 || args(2).is_single_type ()
358 || (nargin >= 4 && args(3).is_single_type ()));
360 if (args(0).iscomplex ()
361 || args(1).iscomplex ()
362 || args(2).iscomplex ()
363 || (nargin >= 4 && args(3).iscomplex ()))
373 if (nargin == 3 || args(3).isempty ())
381 for (
int i = dim; i > 0; i--)
382 si_dims(i) = si_dims(i-1);
389 si = args(3).xfloat_complex_array_value (x_si_errmsg);
397 retval =
ovl (y, si);
408 if (nargin == 3 || args(3).isempty ())
416 for (
int i = dim; i > 0; i--)
417 si_dims(i) = si_dims(i-1);
424 si = args(3).xcomplex_array_value (x_si_errmsg);
432 retval =
ovl (y, si);
446 if (nargin == 3 || args(3).isempty ())
454 for (
int i = dim; i > 0; i--)
455 si_dims(i) = si_dims(i-1);
462 si = args(3).xfloat_array_value (x_si_errmsg);
470 retval =
ovl (y, si);
477 NDArray x = args(2).xarray_value (x_si_errmsg);
481 if (nargin == 3 || args(3).isempty ())
489 for (
int i = dim; i > 0; i--)
490 si_dims(i) = si_dims(i-1);
497 si = args(3).xarray_value (x_si_errmsg);
505 retval =
ovl (y, si);
octave_idx_type numel(void) const
Number of elements in the array.
const dim_vector & dims(void) const
Return a const-reference so that dims ()(i) works efficiently.
bool isvector(void) const
Size of the specified dimension.
OCTARRAY_API void resize(const dim_vector &dv, const T &rfv)
Size of the specified dimension.
const T * data(void) const
Size of the specified dimension.
OCTARRAY_API T * fortran_vec(void)
Size of the specified dimension.
Template for N-dimensional array classes with like-type math operators.
MArray< T > reshape(const dim_vector &new_dims) const
Vector representing the dimensions (size) of an Array.
octave_idx_type numel(int n=0) const
Number of elements that a matrix with this dimensions would have.
int first_non_singleton(int def=0) const
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,...)
OCTAVE_NAMESPACE_BEGIN MArray< T > filter(MArray< T > &b, MArray< T > &a, MArray< T > &x, MArray< T > &si, int dim=0)
double norm(const ColumnVector &v)
F77_RET_T const F77_DBLE * x
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.