31 #if defined (HAVE_CONFIG_H) 63 if (
norm == static_cast<T> (0.0))
64 error (
"filter: the first element of A must be nonzero");
67 if (dim < 0 || dim > x_dims.
ndims ())
68 error (
"filter: DIM must be a valid dimension");
75 if (si_len != ab_len - 1)
76 error (
"filter: first dimension of SI must be of length max (length (a), length (b)) - 1");
79 error (
"filter: dimensionality of SI and X must agree");
83 if (si_dims(
i) != x_dims(
i-1))
84 error (
"filter: dimensionality of SI and X must agree");
88 if (si_dims(
i) != x_dims(
i))
89 error (
"filter: dimensionality of SI and X must agree");
95 if (
norm != static_cast<T> (1.0))
101 if (a_len <= 1 && si_len <= 0)
104 y.resize (x_dims, 0.0);
107 for (
int i = 0;
i < dim;
i++)
108 x_stride *= x_dims(
i);
115 x_offset = num * x_len;
120 while (x_offset >= x_stride)
122 x_offset -= x_stride;
125 x_offset += x_offset2 * x_stride * x_len;
131 T *py =
y.fortran_vec ();
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];
167 T *py =
y.fortran_vec ();
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];
205 template <
typename T>
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);
333 int nargin = args.length ();
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);
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);
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);
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);
Template for N-dimensional array classes with like-type math operators.
OCTINTERP_API void print_usage(void)
bool isvector(void) const
const T * fortran_vec(void) const
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
void error(const char *fmt,...)
const dim_vector & dims(void) const
Return a const-reference so that dims ()(i) works efficiently.
calling an anonymous function involves an overhead quite comparable to the overhead of an m file function Passing a handle to a built in function is because the interpreter is not involved in the internal loop For a
MArray< T > reshape(const dim_vector &new_dims) const
OCTAVE_EXPORT octave_value_list isfloat
int first_non_singleton(int def=0) const
double norm(const ColumnVector &v)
void resize(const dim_vector &dv, const T &rfv)
Resizing (with fill).
MArray< T > filter(MArray< T > &b, MArray< T > &a, MArray< T > &x, MArray< T > &si, int dim=0)
OCTAVE_EXPORT octave_value_list isa nd deftypefn *return ovl(args(0).isinteger())
octave_idx_type numel(int n=0) const
Number of elements that a matrix with this dimensions would have.
the element is set to zero In other the statement xample y
octave_idx_type ndims(void) const
Number of dimensions.
octave_idx_type numel(void) const
Number of elements in the array.
Vector representing the dimensions (size) of an Array.
F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE * x