34 #if defined (HAVE_CONFIG_H)
66 if (
norm ==
static_cast<T
> (0.0))
67 error (
"filter: the first element of A must be nonzero");
70 if (dim < 0 || dim > x_dims.
ndims ())
71 error (
"filter: DIM must be a valid dimension");
78 if (si_len != ab_len - 1)
79 error (
"filter: first dimension of SI must be of length max (length (a), length (b)) - 1");
82 error (
"filter: dimensionality of SI and X must agree");
86 if (si_dims(i) != x_dims(i-1))
87 error (
"filter: dimensionality of SI and X must agree");
91 if (si_dims(i) != x_dims(i))
92 error (
"filter: dimensionality of SI and X must agree");
98 if (
norm !=
static_cast<T
> (1.0))
104 if (a_len <= 1 && si_len <= 0)
110 for (
int i = 0; i < dim; i++)
111 x_stride *= x_dims(i);
118 x_offset = num * x_len;
123 while (x_offset >= x_stride)
125 x_offset -= x_stride;
128 x_offset += x_offset2 * x_stride * x_len;
137 const T *pa = a.
data ();
138 const T *pb = b.
data ();
139 const T *px =
x.data ();
145 i++, idx += x_stride)
147 py[idx] =
psi[0] + pb[0] * px[idx];
155 psi[j] =
psi[j+1] - pa[j+1] * py[idx] + pb[j+1] * px[idx];
158 psi[si_len-1] = pb[si_len] * px[idx] - pa[si_len] * py[idx];
164 psi[0] = pb[si_len] * px[idx] - pa[si_len] * py[idx];
173 const T *pb = b.
data ();
174 const T *px =
x.data ();
180 i++, idx += x_stride)
182 py[idx] =
psi[0] + pb[0] * px[idx];
190 psi[j] =
psi[j+1] + pb[j+1] * px[idx];
193 psi[si_len-1] = pb[si_len] * px[idx];
199 psi[0] = pb[1] * px[idx];
208 template <
typename T>
216 else if (dim > x_dims.
ndims ())
217 error (
"filter: DIM must be a valid dimension");
224 for (
int i = dim; i > 0; i--)
225 si_dims(i) = si_dims(i-1);
230 return filter (b, a,
x, si, dim);
336 int nargin = args.length ();
338 if (nargin < 3 || nargin > 5)
346 dim = args(4).nint_value () - 1;
347 if (dim < 0 || dim >= x_dims.
ndims ())
348 error (
"filter: DIM must be a valid dimension");
355 const char *a_b_errmsg =
"filter: A and B must be vectors";
356 const char *x_si_errmsg =
"filter: X and SI must be arrays";
358 bool isfloat = (args(0).is_single_type ()
359 || args(1).is_single_type ()
360 || args(2).is_single_type ()
361 || (nargin >= 4 && args(3).is_single_type ()));
363 if (args(0).iscomplex ()
364 || args(1).iscomplex ()
365 || args(2).iscomplex ()
366 || (nargin >= 4 && args(3).iscomplex ()))
376 if (nargin == 3 || args(3).isempty ())
384 for (
int i = dim; i > 0; i--)
385 si_dims(i) = si_dims(i-1);
392 si = args(3).xfloat_complex_array_value (x_si_errmsg);
411 if (nargin == 3 || args(3).isempty ())
419 for (
int i = dim; i > 0; i--)
420 si_dims(i) = si_dims(i-1);
427 si = args(3).xcomplex_array_value (x_si_errmsg);
449 if (nargin == 3 || args(3).isempty ())
457 for (
int i = dim; i > 0; i--)
458 si_dims(i) = si_dims(i-1);
465 si = args(3).xfloat_array_value (x_si_errmsg);
480 NDArray x = args(2).xarray_value (x_si_errmsg);
484 if (nargin == 3 || args(3).isempty ())
492 for (
int i = dim; i > 0; i--)
493 si_dims(i) = si_dims(i-1);
500 si = args(3).xarray_value (x_si_errmsg);
void resize(const dim_vector &dv, const T &rfv)
Size of the specified dimension.
octave_idx_type numel(void) const
Number of elements in the array.
bool isvector(void) const
Size of the specified dimension.
const T * data(void) const
Size of the specified dimension.
const dim_vector & dims(void) const
Return a const-reference so that dims ()(i) works efficiently.
const T * fortran_vec(void) const
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,...)
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::octave_value(const Array< char > &chm, char type) return retval
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.