annotate libinterp/corefcn/filter.cc @ 31605:e88a07dec498 stable

maint: Use macros to begin/end C++ namespaces. * oct-conf-post-public.in.h: Define two macros (OCTAVE_BEGIN_NAMESPACE, OCTAVE_END_NAMESPACE) that can be used to start/end a namespace. * mk-opts.pl, build-env.h, build-env.in.cc, __betainc__.cc, __contourc__.cc, __dsearchn__.cc, __eigs__.cc, __expint__.cc, __ftp__.cc, __gammainc__.cc, __ichol__.cc, __ilu__.cc, __isprimelarge__.cc, __lin_interpn__.cc, __magick_read__.cc, __pchip_deriv__.cc, __qp__.cc, amd.cc, auto-shlib.cc, auto-shlib.h, balance.cc, base-text-renderer.cc, base-text-renderer.h, besselj.cc, bitfcns.cc, bsxfun.cc, c-file-ptr-stream.cc, c-file-ptr-stream.h, call-stack.cc, call-stack.h, ccolamd.cc, cellfun.cc, chol.cc, colamd.cc, colloc.cc, conv2.cc, daspk.cc, dasrt.cc, dassl.cc, data.cc, data.h, debug.cc, defaults.cc, defaults.h, defun-int.h, defun.cc, det.cc, dirfns.cc, display.cc, display.h, dlmread.cc, dmperm.cc, dot.cc, dynamic-ld.cc, dynamic-ld.h, eig.cc, ellipj.cc, environment.cc, environment.h, error.cc, error.h, errwarn.h, event-manager.cc, event-manager.h, event-queue.cc, event-queue.h, fcn-info.cc, fcn-info.h, fft.cc, fft2.cc, fftn.cc, file-io.cc, filter.cc, find.cc, ft-text-renderer.cc, ft-text-renderer.h, gcd.cc, getgrent.cc, getpwent.cc, getrusage.cc, givens.cc, gl-render.cc, gl-render.h, gl2ps-print.cc, gl2ps-print.h, graphics-toolkit.cc, graphics-toolkit.h, graphics.cc, graphics.in.h, gsvd.cc, gtk-manager.cc, gtk-manager.h, hash.cc, help.cc, help.h, hess.cc, hex2num.cc, hook-fcn.cc, hook-fcn.h, input.cc, input.h, interpreter-private.cc, interpreter-private.h, interpreter.cc, interpreter.h, inv.cc, jsondecode.cc, jsonencode.cc, kron.cc, latex-text-renderer.cc, latex-text-renderer.h, load-path.cc, load-path.h, load-save.cc, load-save.h, lookup.cc, ls-ascii-helper.cc, ls-ascii-helper.h, ls-oct-text.cc, ls-utils.cc, ls-utils.h, lsode.cc, lu.cc, mappers.cc, matrix_type.cc, max.cc, mex-private.h, mex.cc, mgorth.cc, nproc.cc, oct-fstrm.cc, oct-fstrm.h, oct-hdf5-types.cc, oct-hdf5-types.h, oct-hist.cc, oct-hist.h, oct-iostrm.cc, oct-iostrm.h, oct-opengl.h, oct-prcstrm.cc, oct-prcstrm.h, oct-procbuf.cc, oct-procbuf.h, oct-process.cc, oct-process.h, oct-stdstrm.h, oct-stream.cc, oct-stream.h, oct-strstrm.cc, oct-strstrm.h, oct-tex-lexer.in.ll, oct-tex-parser.yy, ordqz.cc, ordschur.cc, pager.cc, pager.h, pinv.cc, pow2.cc, pr-flt-fmt.cc, pr-output.cc, procstream.cc, procstream.h, psi.cc, qr.cc, quad.cc, quadcc.cc, qz.cc, rand.cc, rcond.cc, regexp.cc, schur.cc, settings.cc, settings.h, sighandlers.cc, sighandlers.h, sparse-xdiv.cc, sparse-xdiv.h, sparse-xpow.cc, sparse-xpow.h, sparse.cc, spparms.cc, sqrtm.cc, stack-frame.cc, stack-frame.h, stream-euler.cc, strfind.cc, strfns.cc, sub2ind.cc, svd.cc, sylvester.cc, symbfact.cc, syminfo.cc, syminfo.h, symrcm.cc, symrec.cc, symrec.h, symscope.cc, symscope.h, symtab.cc, symtab.h, syscalls.cc, sysdep.cc, sysdep.h, text-engine.cc, text-engine.h, text-renderer.cc, text-renderer.h, time.cc, toplev.cc, tril.cc, tsearch.cc, typecast.cc, url-handle-manager.cc, url-handle-manager.h, urlwrite.cc, utils.cc, utils.h, variables.cc, variables.h, xdiv.cc, xdiv.h, xnorm.cc, xnorm.h, xpow.cc, xpow.h, __delaunayn__.cc, __fltk_uigetfile__.cc, __glpk__.cc, __init_fltk__.cc, __init_gnuplot__.cc, __ode15__.cc, __voronoi__.cc, audiodevinfo.cc, audioread.cc, convhulln.cc, fftw.cc, gzip.cc, mk-build-env-features.sh, mk-builtins.pl, cdef-class.cc, cdef-class.h, cdef-fwd.h, cdef-manager.cc, cdef-manager.h, cdef-method.cc, cdef-method.h, cdef-object.cc, cdef-object.h, cdef-package.cc, cdef-package.h, cdef-property.cc, cdef-property.h, cdef-utils.cc, cdef-utils.h, ov-base.cc, ov-base.h, ov-bool-mat.cc, ov-builtin.h, ov-cell.cc, ov-class.cc, ov-class.h, ov-classdef.cc, ov-classdef.h, ov-complex.cc, ov-fcn-handle.cc, ov-fcn-handle.h, ov-fcn.h, ov-java.cc, ov-java.h, ov-mex-fcn.h, ov-null-mat.cc, ov-oncleanup.cc, ov-struct.cc, ov-typeinfo.cc, ov-typeinfo.h, ov-usr-fcn.cc, ov-usr-fcn.h, ov.cc, ov.h, octave.cc, octave.h, mk-ops.sh, op-b-b.cc, op-b-bm.cc, op-b-sbm.cc, op-bm-b.cc, op-bm-bm.cc, op-bm-sbm.cc, op-cdm-cdm.cc, op-cell.cc, op-chm.cc, op-class.cc, op-cm-cm.cc, op-cm-cs.cc, op-cm-m.cc, op-cm-s.cc, op-cm-scm.cc, op-cm-sm.cc, op-cs-cm.cc, op-cs-cs.cc, op-cs-m.cc, op-cs-s.cc, op-cs-scm.cc, op-cs-sm.cc, op-dm-dm.cc, op-dm-scm.cc, op-dm-sm.cc, op-dm-template.cc, op-dms-template.cc, op-fcdm-fcdm.cc, op-fcm-fcm.cc, op-fcm-fcs.cc, op-fcm-fm.cc, op-fcm-fs.cc, op-fcn.cc, op-fcs-fcm.cc, op-fcs-fcs.cc, op-fcs-fm.cc, op-fcs-fs.cc, op-fdm-fdm.cc, op-fm-fcm.cc, op-fm-fcs.cc, op-fm-fm.cc, op-fm-fs.cc, op-fs-fcm.cc, op-fs-fcs.cc, op-fs-fm.cc, op-fs-fs.cc, op-i16-i16.cc, op-i32-i32.cc, op-i64-i64.cc, op-i8-i8.cc, op-int-concat.cc, op-m-cm.cc, op-m-cs.cc, op-m-m.cc, op-m-s.cc, op-m-scm.cc, op-m-sm.cc, op-mi.cc, op-pm-pm.cc, op-pm-scm.cc, op-pm-sm.cc, op-pm-template.cc, op-range.cc, op-s-cm.cc, op-s-cs.cc, op-s-m.cc, op-s-s.cc, op-s-scm.cc, op-s-sm.cc, op-sbm-b.cc, op-sbm-bm.cc, op-sbm-sbm.cc, op-scm-cm.cc, op-scm-cs.cc, op-scm-m.cc, op-scm-s.cc, op-scm-scm.cc, op-scm-sm.cc, op-sm-cm.cc, op-sm-cs.cc, op-sm-m.cc, op-sm-s.cc, op-sm-scm.cc, op-sm-sm.cc, op-str-m.cc, op-str-s.cc, op-str-str.cc, op-struct.cc, op-ui16-ui16.cc, op-ui32-ui32.cc, op-ui64-ui64.cc, op-ui8-ui8.cc, ops.h, anon-fcn-validator.cc, anon-fcn-validator.h, bp-table.cc, bp-table.h, comment-list.cc, comment-list.h, filepos.h, lex.h, lex.ll, oct-lvalue.cc, oct-lvalue.h, oct-parse.yy, parse.h, profiler.cc, profiler.h, pt-anon-scopes.cc, pt-anon-scopes.h, pt-arg-list.cc, pt-arg-list.h, pt-args-block.cc, pt-args-block.h, pt-array-list.cc, pt-array-list.h, pt-assign.cc, pt-assign.h, pt-binop.cc, pt-binop.h, pt-bp.cc, pt-bp.h, pt-cbinop.cc, pt-cbinop.h, pt-cell.cc, pt-cell.h, pt-check.cc, pt-check.h, pt-classdef.cc, pt-classdef.h, pt-cmd.h, pt-colon.cc, pt-colon.h, pt-const.cc, pt-const.h, pt-decl.cc, pt-decl.h, pt-eval.cc, pt-eval.h, pt-except.cc, pt-except.h, pt-exp.cc, pt-exp.h, pt-fcn-handle.cc, pt-fcn-handle.h, pt-id.cc, pt-id.h, pt-idx.cc, pt-idx.h, pt-jump.h, pt-loop.cc, pt-loop.h, pt-mat.cc, pt-mat.h, pt-misc.cc, pt-misc.h, pt-pr-code.cc, pt-pr-code.h, pt-select.cc, pt-select.h, pt-spmd.cc, pt-spmd.h, pt-stmt.cc, pt-stmt.h, pt-tm-const.cc, pt-tm-const.h, pt-unop.cc, pt-unop.h, pt-vm-eval.cc, pt-walk.cc, pt-walk.h, pt.cc, pt.h, token.cc, token.h, Range.cc, Range.h, idx-vector.cc, idx-vector.h, range-fwd.h, CollocWt.cc, CollocWt.h, aepbalance.cc, aepbalance.h, chol.cc, chol.h, gepbalance.cc, gepbalance.h, gsvd.cc, gsvd.h, hess.cc, hess.h, lo-mappers.cc, lo-mappers.h, lo-specfun.cc, lo-specfun.h, lu.cc, lu.h, oct-convn.cc, oct-convn.h, oct-fftw.cc, oct-fftw.h, oct-norm.cc, oct-norm.h, oct-rand.cc, oct-rand.h, oct-spparms.cc, oct-spparms.h, qr.cc, qr.h, qrp.cc, qrp.h, randgamma.cc, randgamma.h, randmtzig.cc, randmtzig.h, randpoisson.cc, randpoisson.h, schur.cc, schur.h, sparse-chol.cc, sparse-chol.h, sparse-lu.cc, sparse-lu.h, sparse-qr.cc, sparse-qr.h, svd.cc, svd.h, child-list.cc, child-list.h, dir-ops.cc, dir-ops.h, file-ops.cc, file-ops.h, file-stat.cc, file-stat.h, lo-sysdep.cc, lo-sysdep.h, lo-sysinfo.cc, lo-sysinfo.h, mach-info.cc, mach-info.h, oct-env.cc, oct-env.h, oct-group.cc, oct-group.h, oct-password.cc, oct-password.h, oct-syscalls.cc, oct-syscalls.h, oct-time.cc, oct-time.h, oct-uname.cc, oct-uname.h, action-container.cc, action-container.h, base-list.h, cmd-edit.cc, cmd-edit.h, cmd-hist.cc, cmd-hist.h, f77-fcn.h, file-info.cc, file-info.h, lo-array-errwarn.cc, lo-array-errwarn.h, lo-hash.cc, lo-hash.h, lo-ieee.h, lo-regexp.cc, lo-regexp.h, lo-utils.cc, lo-utils.h, oct-base64.cc, oct-base64.h, oct-glob.cc, oct-glob.h, oct-inttypes.h, oct-mutex.cc, oct-mutex.h, oct-refcount.h, oct-shlib.cc, oct-shlib.h, oct-sparse.cc, oct-sparse.h, oct-string.h, octave-preserve-stream-state.h, pathsearch.cc, pathsearch.h, quit.cc, quit.h, unwind-prot.cc, unwind-prot.h, url-transfer.cc, url-transfer.h : Use new macros to begin/end C++ namespaces.
author Rik <rik@octave.org>
date Thu, 01 Dec 2022 14:23:45 -0800
parents d2cd9ead4c84
children aac27ad79be6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ////////////////////////////////////////////////////////////////////////
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 //
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 29980
diff changeset
3 // Copyright (C) 1996-2022 The Octave Project Developers
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
4 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 // See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 // distribution or <https://octave.org/copyright/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
7 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
8 // This file is part of Octave.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
9 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
10 // Octave is free software: you can redistribute it and/or modify it
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
11 // under the terms of the GNU General Public License as published by
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
12 // the Free Software Foundation, either version 3 of the License, or
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
13 // (at your option) any later version.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
14 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
15 // Octave is distributed in the hope that it will be useful, but
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
18 // GNU General Public License for more details.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
19 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
20 // You should have received a copy of the GNU General Public License
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
21 // along with Octave; see the file COPYING. If not, see
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
22 // <https://www.gnu.org/licenses/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ////////////////////////////////////////////////////////////////////////
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
25
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
26 // Based on Tony Richardson's filter.m.
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
27 //
5428
2a16423e4aa0 [project @ 2005-08-23 18:38:27 by jwe]
jwe
parents: 5307
diff changeset
28 // Originally translated to C++ by KH (Kurt.Hornik@wu-wien.ac.at)
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
29 // with help from Fritz Leisch and Andreas Weingessel on Oct 20, 1994.
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
30 //
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
31 // Rewritten to use templates to handle both real and complex cases by
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
32 // jwe, Wed Nov 1 19:15:29 1995.
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
33
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21697
diff changeset
34 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21200
diff changeset
35 # include "config.h"
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
36 #endif
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
37
4153
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents: 3419
diff changeset
38 #include "quit.h"
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents: 3419
diff changeset
39
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14854
diff changeset
40 #include "defun.h"
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
41 #include "error.h"
20940
48b2ad5ee801 maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents: 20915
diff changeset
42 #include "ovl.h"
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
43
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 30576
diff changeset
44 OCTAVE_BEGIN_NAMESPACE(octave)
29958
32c3a5805893 move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
45
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20997
diff changeset
46 template <typename T>
10350
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10247
diff changeset
47 MArray<T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
48 filter (MArray<T>& b, MArray<T>& a, MArray<T>& x, MArray<T>& si,
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
49 int dim = 0)
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
50 {
10350
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10247
diff changeset
51 MArray<T> y;
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
52
21568
3d60ed163b70 maint: Eliminate bad spacing around '='.
Rik <rik@octave.org>
parents: 21301
diff changeset
53 octave_idx_type a_len = a.numel ();
3d60ed163b70 maint: Eliminate bad spacing around '='.
Rik <rik@octave.org>
parents: 21301
diff changeset
54 octave_idx_type b_len = b.numel ();
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
55
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23220
diff changeset
56 octave_idx_type ab_len = (a_len > b_len ? a_len : b_len);
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
57
27956
2310164737b3 fix many spelling errors (bug #57613)
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
58 // FIXME: The two lines below should be unnecessary because
12637
d02798e9eeae filter.cc: Stop test errors in residue.m (bug #33164)
Rik <octave@nomad.inbox5.com>
parents: 12566
diff changeset
59 // this template is called with a and b as column vectors
d02798e9eeae filter.cc: Stop test errors in residue.m (bug #33164)
Rik <octave@nomad.inbox5.com>
parents: 12566
diff changeset
60 // already. However the a.resize line is currently (2011/04/26)
d02798e9eeae filter.cc: Stop test errors in residue.m (bug #33164)
Rik <octave@nomad.inbox5.com>
parents: 12566
diff changeset
61 // necessary to stop bug #33164.
d02798e9eeae filter.cc: Stop test errors in residue.m (bug #33164)
Rik <octave@nomad.inbox5.com>
parents: 12566
diff changeset
62 b.resize (dim_vector (ab_len, 1), 0.0);
d02798e9eeae filter.cc: Stop test errors in residue.m (bug #33164)
Rik <octave@nomad.inbox5.com>
parents: 12566
diff changeset
63 if (a_len > 1)
d02798e9eeae filter.cc: Stop test errors in residue.m (bug #33164)
Rik <octave@nomad.inbox5.com>
parents: 12566
diff changeset
64 a.resize (dim_vector (ab_len, 1), 0.0);
d02798e9eeae filter.cc: Stop test errors in residue.m (bug #33164)
Rik <octave@nomad.inbox5.com>
parents: 12566
diff changeset
65
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
66 T norm = a (0);
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
67
19739
3fa35defe495 Adjust spacing of static_cast<> calls to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
68 if (norm == static_cast<T> (0.0))
20831
35241c4b696c eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents: 20817
diff changeset
69 error ("filter: the first element of A must be nonzero");
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
70
4844
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4153
diff changeset
71 dim_vector x_dims = x.dims ();
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21568
diff changeset
72 if (dim < 0 || dim > x_dims.ndims ())
20831
35241c4b696c eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents: 20817
diff changeset
73 error ("filter: DIM must be a valid dimension");
4844
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4153
diff changeset
74
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5114
diff changeset
75 octave_idx_type x_len = x_dims(dim);
4844
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4153
diff changeset
76
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4153
diff changeset
77 dim_vector si_dims = si.dims ();
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5114
diff changeset
78 octave_idx_type si_len = si_dims(0);
4844
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4153
diff changeset
79
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4153
diff changeset
80 if (si_len != ab_len - 1)
20831
35241c4b696c eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents: 20817
diff changeset
81 error ("filter: first dimension of SI must be of length max (length (a), length (b)) - 1");
4844
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4153
diff changeset
82
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21568
diff changeset
83 if (si_dims.ndims () != x_dims.ndims ())
20831
35241c4b696c eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents: 20817
diff changeset
84 error ("filter: dimensionality of SI and X must agree");
4844
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4153
diff changeset
85
12774
ec6c52496485 Fix input validation of SI vector for filter() when DIM used (Bug #33625)
Rik <octave@nomad.inbox5.com>
parents: 12707
diff changeset
86 for (octave_idx_type i = 1; i < dim; i++)
4844
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4153
diff changeset
87 {
12774
ec6c52496485 Fix input validation of SI vector for filter() when DIM used (Bug #33625)
Rik <octave@nomad.inbox5.com>
parents: 12707
diff changeset
88 if (si_dims(i) != x_dims(i-1))
20831
35241c4b696c eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents: 20817
diff changeset
89 error ("filter: dimensionality of SI and X must agree");
12774
ec6c52496485 Fix input validation of SI vector for filter() when DIM used (Bug #33625)
Rik <octave@nomad.inbox5.com>
parents: 12707
diff changeset
90 }
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21568
diff changeset
91 for (octave_idx_type i = dim+1; i < x_dims.ndims (); i++)
12774
ec6c52496485 Fix input validation of SI vector for filter() when DIM used (Bug #33625)
Rik <octave@nomad.inbox5.com>
parents: 12707
diff changeset
92 {
ec6c52496485 Fix input validation of SI vector for filter() when DIM used (Bug #33625)
Rik <octave@nomad.inbox5.com>
parents: 12707
diff changeset
93 if (si_dims(i) != x_dims(i))
20831
35241c4b696c eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents: 20817
diff changeset
94 error ("filter: dimensionality of SI and X must agree");
4844
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4153
diff changeset
95 }
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
96
10241
a277ba5da4dc filter.cc: return early if X is empty
John W. Eaton <jwe@octave.org>
parents: 10155
diff changeset
97 if (x_len == 0)
a277ba5da4dc filter.cc: return early if X is empty
John W. Eaton <jwe@octave.org>
parents: 10155
diff changeset
98 return x;
a277ba5da4dc filter.cc: return early if X is empty
John W. Eaton <jwe@octave.org>
parents: 10155
diff changeset
99
19739
3fa35defe495 Adjust spacing of static_cast<> calls to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
100 if (norm != static_cast<T> (1.0))
4844
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4153
diff changeset
101 {
20230
e914b5399c67 Use in-place operators in C++ code where possible.
Rik <rik@octave.org>
parents: 20172
diff changeset
102 a /= norm;
e914b5399c67 Use in-place operators in C++ code where possible.
Rik <rik@octave.org>
parents: 20172
diff changeset
103 b /= norm;
4844
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4153
diff changeset
104 }
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
105
5056
9379d8716407 [project @ 2004-10-22 14:58:05 by jwe]
jwe
parents: 5055
diff changeset
106 if (a_len <= 1 && si_len <= 0)
4844
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4153
diff changeset
107 return b(0) * x;
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4153
diff changeset
108
30576
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
109 // Here onwards, either a_len > 1 or si_len >= 1 or both.
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
110
4844
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4153
diff changeset
111 y.resize (x_dims, 0.0);
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4153
diff changeset
112
21697
e7f641616581 Make filter work with 64-bit octave_idx_type (bug #47918).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21660
diff changeset
113 octave_idx_type x_stride = 1;
4844
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4153
diff changeset
114 for (int i = 0; i < dim; i++)
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4153
diff changeset
115 x_stride *= x_dims(i);
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
116
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5114
diff changeset
117 octave_idx_type x_num = x_dims.numel () / x_len;
30576
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
118 // For deconv and fftfilt, x_num seems to always be 1.
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
119 // For directly calling filter, it can be more than 1.
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
120
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5114
diff changeset
121 for (octave_idx_type num = 0; num < x_num; num++)
4844
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4153
diff changeset
122 {
30576
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
123 octave_idx_type x_offset = (x_stride == 1) ? num * x_len
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
124 : num + (num / x_stride) * x_stride * (x_len - 1);
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
125
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5114
diff changeset
126 octave_idx_type si_offset = num * si_len;
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
127
30576
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
128 // Try to achieve a balance between speed and interruptibility.
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
129 //
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
130 // One extreme is to not check for interruptions at all, which gives
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
131 // good speed but the user cannot use Ctrl-C for the whole duration.
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
132 // The other end is to check frequently from inside an inner loop,
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
133 // which slows down performance by 5X or 6X.
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
134 //
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
135 // Putting any sort of check in an inner loop seems to prevent the
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
136 // compiler from optimizing the loop, so we cannot say "check for
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
137 // interruptions every M iterations" using an if-statement.
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
138 //
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
139 // This is a compromise approach to split the total numer of loop
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
140 // executions into num_outer and num_inner, to provide periodic checks
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
141 // for interruptions without writing a conditional inside a tight loop.
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
142 //
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
143 // To make it more interruptible and run more slowly, reduce num_inner.
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
144 // To speed it up but make it less interruptible, increase it.
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
145 // May need to increase it slowly over time as computers get faster.
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
146 // The aim is to not lose Ctrl-C ability for longer than about 2 seconds.
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
147 //
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
148 // In December 2021, num_inner = 100000 is acceptable.
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
149
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
150 octave_idx_type num_execs = si_len-1; // 0 to num_execs-1
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
151 octave_idx_type num_inner = 100000;
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
152 octave_idx_type num_outer = num_execs / num_inner;
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
153
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
154 // The following if-else block depends on a_len and si_len,
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
155 // both of which are loop invariants in this 0 <= num < x_num loop.
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
156 // But x_num is so small in practice that using the if-else inside
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
157 // the loop has more benefits than duplicating the outer for-loop,
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
158 // even though the checks are on loop invariants.
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
159
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
160 // We cannot have a_len <= 1 AND si_len <= 0 because that case already
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
161 // returned above. This means exactly one of the following blocks
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
162 // inside the if-conditional will be obeyed: it is not possible for the
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
163 // if-block and the else-block to *both* skip. Therefore any code that
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
164 // is common to both branches can be pulled out here without affecting
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
165 // correctness or speed.
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
166
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
167 T *py = y.fortran_vec ();
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
168 T *psi = si.fortran_vec ();
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
169 const T *pb = b.data ();
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
170 const T *px = x.data ();
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
171 psi += si_offset;
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
172
4844
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4153
diff changeset
173 if (a_len > 1)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
174 {
30576
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
175 const T *pa = a.data ();
5114
cda8c0a823c5 [project @ 2005-01-21 17:02:21 by jwe]
jwe
parents: 5059
diff changeset
176
30576
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
177 // Usually the last element to be written will be si_len-1
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
178 // but if si_len is 0, then we need the 0th element to be written.
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
179 // Pulling this check out of the for-loop makes it run faster.
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
180 octave_idx_type iidx = (si_len > 0) ? si_len-1 : 0;
5114
cda8c0a823c5 [project @ 2005-01-21 17:02:21 by jwe]
jwe
parents: 5059
diff changeset
181
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
182 for (octave_idx_type i = 0, idx = x_offset;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
183 i < x_len;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
184 i++, idx += x_stride)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
185 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
186 py[idx] = psi[0] + pb[0] * px[idx];
5114
cda8c0a823c5 [project @ 2005-01-21 17:02:21 by jwe]
jwe
parents: 5059
diff changeset
187
30576
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
188 // Outer and inner loops for interruption management
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
189 for (octave_idx_type u = 0; u <= num_outer; u++)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
190 {
30576
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
191 octave_idx_type lo = u * num_inner;
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
192 octave_idx_type hi = (lo + num_inner < num_execs-1)
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
193 ? lo + num_inner : num_execs-1;
5114
cda8c0a823c5 [project @ 2005-01-21 17:02:21 by jwe]
jwe
parents: 5059
diff changeset
194
30576
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
195 // Inner loop, no interruption
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
196 for (octave_idx_type j = lo; j <= hi; j++)
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
197 psi[j] = psi[j+1] - pa[j+1] * py[idx] + pb[j+1] * px[idx];
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
198
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
199 octave_quit(); // Check for interruptions
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
200 }
5114
cda8c0a823c5 [project @ 2005-01-21 17:02:21 by jwe]
jwe
parents: 5059
diff changeset
201
30576
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
202 psi[iidx] = pb[si_len] * px[idx] - pa[si_len] * py[idx];
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
203 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
204 }
30576
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
205 else // a_len <= 1 ==> si_len MUST be > 0
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
206 {
30576
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
207 // This else-block is almost the same as the above if-block,
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
208 // except for the absence of variable pa.
5114
cda8c0a823c5 [project @ 2005-01-21 17:02:21 by jwe]
jwe
parents: 5059
diff changeset
209
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
210 for (octave_idx_type i = 0, idx = x_offset;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
211 i < x_len;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
212 i++, idx += x_stride)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
213 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
214 py[idx] = psi[0] + pb[0] * px[idx];
4844
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4153
diff changeset
215
30576
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
216 // Outer and inner loops for interruption management
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
217 for (octave_idx_type u = 0; u <= num_outer; u++)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
218 {
30576
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
219 octave_idx_type lo = u * num_inner;
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
220 octave_idx_type hi = (lo + num_inner < num_execs-1)
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
221 ? lo + num_inner : num_execs-1;
4844
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4153
diff changeset
222
30576
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
223 // Inner loop, no interruption
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
224 for (octave_idx_type j = lo; j <= hi; j++)
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
225 psi[j] = psi[j+1] + pb[j+1] * px[idx];
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
226
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
227 octave_quit(); // Check for interruptions
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
228 }
4844
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4153
diff changeset
229
30576
d2cd9ead4c84 filter.cc: Speed up execution by up to 6X (bug #61674).
Arun Giridhar <arungiridhar@gmail.com>
parents: 30565
diff changeset
230 psi[si_len-1] = pb[si_len] * px[idx];
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
231 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
232 }
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
233 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
234
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
235 return y;
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
236 }
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
237
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20997
diff changeset
238 template <typename T>
10350
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10247
diff changeset
239 MArray<T>
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10247
diff changeset
240 filter (MArray<T>& b, MArray<T>& a, MArray<T>& x, int dim = -1)
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
241 {
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14842
diff changeset
242 dim_vector x_dims = x.dims ();
4844
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4153
diff changeset
243
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4153
diff changeset
244 if (dim < 0)
20997
d03babf77549 filter.cc: Use first_non_singleton() rather than handrolled code.
Rik <rik@octave.org>
parents: 20940
diff changeset
245 dim = x_dims.first_non_singleton ();
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21568
diff changeset
246 else if (dim > x_dims.ndims ())
20831
35241c4b696c eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents: 20817
diff changeset
247 error ("filter: DIM must be a valid dimension");
4844
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4153
diff changeset
248
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20230
diff changeset
249 octave_idx_type a_len = a.numel ();
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20230
diff changeset
250 octave_idx_type b_len = b.numel ();
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
251
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5114
diff changeset
252 octave_idx_type si_len = (a_len > b_len ? a_len : b_len) - 1;
4844
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4153
diff changeset
253 dim_vector si_dims = x.dims ();
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4153
diff changeset
254 for (int i = dim; i > 0; i--)
5059
38dd53c8935e [project @ 2004-11-02 02:42:25 by jwe]
jwe
parents: 5056
diff changeset
255 si_dims(i) = si_dims(i-1);
38dd53c8935e [project @ 2004-11-02 02:42:25 by jwe]
jwe
parents: 5056
diff changeset
256 si_dims(0) = si_len;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
257
10350
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10247
diff changeset
258 MArray<T> si (si_dims, T (0.0));
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
259
4844
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4153
diff changeset
260 return filter (b, a, x, si, dim);
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
261 }
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
262
20915
a3359fe50966 remove unused nargout variables
John W. Eaton <jwe@octave.org>
parents: 20909
diff changeset
263 DEFUN (filter, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
264 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
265 @deftypefn {} {@var{y} =} filter (@var{b}, @var{a}, @var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
266 @deftypefnx {} {[@var{y}, @var{sf}] =} filter (@var{b}, @var{a}, @var{x}, @var{si})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
267 @deftypefnx {} {[@var{y}, @var{sf}] =} filter (@var{b}, @var{a}, @var{x}, [], @var{dim})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
268 @deftypefnx {} {[@var{y}, @var{sf}] =} filter (@var{b}, @var{a}, @var{x}, @var{si}, @var{dim})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
269 Apply a 1-D digital filter to the data @var{x}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
270
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
271 @code{filter} returns the solution to the following linear, time-invariant
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
272 difference equation:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
273 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
274 $$
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
275 \sum_{k=0}^N a_{k+1} y_{n-k} = \sum_{k=0}^M b_{k+1} x_{n-k}, \qquad
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
276 1 \le n \le P
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
277 $$
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
278 @end tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
279 @ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
280 @c Set example in small font to prevent overfull line
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
281
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
282 @smallexample
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
283 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
284 N M
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
285 SUM a(k+1) y(n-k) = SUM b(k+1) x(n-k) for 1<=n<=length(x)
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
286 k=0 k=0
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
287 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
288 @end smallexample
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
289
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
290 @end ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
291
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
292 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
293 where
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
294 @ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
295 N=length(a)-1 and M=length(b)-1.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
296 @end ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
297 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
298 $a \in \Re^{N-1}$, $b \in \Re^{M-1}$, and $x \in \Re^P$.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
299 @end tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
300 The result is calculated over the first non-singleton dimension of @var{x}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
301 or over @var{dim} if supplied.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
302
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
303 An equivalent form of the equation is:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
304 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
305 $$
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
306 y_n = -\sum_{k=1}^N c_{k+1} y_{n-k} + \sum_{k=0}^M d_{k+1} x_{n-k}, \qquad
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
307 1 \le n \le P
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
308 $$
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
309 @end tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
310 @ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
311 @c Set example in small font to prevent overfull line
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
312
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
313 @smallexample
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
314 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
315 N M
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
316 y(n) = - SUM c(k+1) y(n-k) + SUM d(k+1) x(n-k) for 1<=n<=length(x)
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
317 k=1 k=0
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
318 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
319 @end smallexample
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
320
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
321 @end ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
322
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
323 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
324 where
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
325 @ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
326 c = a/a(1) and d = b/a(1).
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
327 @end ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
328 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
329 $c = a/a_1$ and $d = b/a_1$.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
330 @end tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
331
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
332 If the fourth argument @var{si} is provided, it is taken as the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
333 initial state of the system and the final state is returned as
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
334 @var{sf}. The state vector is a column vector whose length is
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
335 equal to the length of the longest coefficient vector minus one.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
336 If @var{si} is not supplied, the initial state vector is set to all
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
337 zeros.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
338
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
339 In terms of the Z Transform, @var{y} is the result of passing the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
340 discrete-time signal @var{x} through a system characterized by the following
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
341 rational system function:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
342 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
343 $$
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
344 H(z) = {\displaystyle\sum_{k=0}^M d_{k+1} z^{-k}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
345 \over 1 + \displaystyle\sum_{k+1}^N c_{k+1} z^{-k}}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
346 $$
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
347 @end tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
348 @ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
349
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
350 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
351 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
352 M
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
353 SUM d(k+1) z^(-k)
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
354 k=0
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
355 H(z) = ---------------------
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
356 N
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
357 1 + SUM c(k+1) z^(-k)
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
358 k=1
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
359 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
360 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
361
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
362 @end ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
363 @seealso{filter2, fftfilt, freqz}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
364 @end deftypefn */)
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
365 {
20817
3d551b2ae928 Use variable name nargin consistently in C++ code.
Rik <rik@octave.org>
parents: 20802
diff changeset
366 int nargin = args.length ();
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
367
4844
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4153
diff changeset
368 if (nargin < 3 || nargin > 5)
20802
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
369 print_usage ();
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
370
4844
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4153
diff changeset
371 int dim;
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4153
diff changeset
372 dim_vector x_dims = args(2).dims ();
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
373
4844
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4153
diff changeset
374 if (nargin == 5)
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4153
diff changeset
375 {
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14842
diff changeset
376 dim = args(4).nint_value () - 1;
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21568
diff changeset
377 if (dim < 0 || dim >= x_dims.ndims ())
20831
35241c4b696c eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents: 20817
diff changeset
378 error ("filter: DIM must be a valid dimension");
4844
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4153
diff changeset
379 }
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4153
diff changeset
380 else
20997
d03babf77549 filter.cc: Use first_non_singleton() rather than handrolled code.
Rik <rik@octave.org>
parents: 20940
diff changeset
381 dim = x_dims.first_non_singleton ();
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
382
20909
03e4ddd49396 omit unnecessary nargout checks
John W. Eaton <jwe@octave.org>
parents: 20892
diff changeset
383 octave_value_list retval;
20892
c07bee629973 2015 Code Sprint: use ovl ().
Rik <rik@octave.org>
parents: 20853
diff changeset
384
20997
d03babf77549 filter.cc: Use first_non_singleton() rather than handrolled code.
Rik <rik@octave.org>
parents: 20940
diff changeset
385 const char *a_b_errmsg = "filter: A and B must be vectors";
d03babf77549 filter.cc: Use first_non_singleton() rather than handrolled code.
Rik <rik@octave.org>
parents: 20940
diff changeset
386 const char *x_si_errmsg = "filter: X and SI must be arrays";
d03babf77549 filter.cc: Use first_non_singleton() rather than handrolled code.
Rik <rik@octave.org>
parents: 20940
diff changeset
387
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
388 bool isfloat = (args(0).is_single_type ()
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
389 || args(1).is_single_type ()
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
390 || args(2).is_single_type ()
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
391 || (nargin >= 4 && args(3).is_single_type ()));
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
392
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23577
diff changeset
393 if (args(0).iscomplex ()
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23577
diff changeset
394 || args(1).iscomplex ()
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23577
diff changeset
395 || args(2).iscomplex ()
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23577
diff changeset
396 || (nargin >= 4 && args(3).iscomplex ()))
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
397 {
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
398 if (isfloat)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
399 {
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
400 FloatComplexColumnVector b = args(0).xfloat_complex_vector_value (a_b_errmsg);
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
401 FloatComplexColumnVector a = args(1).xfloat_complex_vector_value (a_b_errmsg);
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
402 FloatComplexNDArray x = args(2).xfloat_complex_array_value (x_si_errmsg);
20687
5f04bfc7c17a backout changeset 18f38ed43962
John W. Eaton <jwe@octave.org>
parents: 20682
diff changeset
403
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
404 FloatComplexNDArray si;
3088
f33738510eb2 [project @ 1997-10-02 06:38:36 by jwe]
jwe
parents: 3014
diff changeset
405
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23450
diff changeset
406 if (nargin == 3 || args(3).isempty ())
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
407 {
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
408 octave_idx_type a_len = a.numel ();
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
409 octave_idx_type b_len = b.numel ();
20687
5f04bfc7c17a backout changeset 18f38ed43962
John W. Eaton <jwe@octave.org>
parents: 20682
diff changeset
410
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
411 octave_idx_type si_len = (a_len > b_len ? a_len : b_len) - 1;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
412
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
413 dim_vector si_dims = x.dims ();
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
414 for (int i = dim; i > 0; i--)
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
415 si_dims(i) = si_dims(i-1);
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
416 si_dims(0) = si_len;
20687
5f04bfc7c17a backout changeset 18f38ed43962
John W. Eaton <jwe@octave.org>
parents: 20682
diff changeset
417
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
418 si.resize (si_dims, 0.0);
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
419 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
420 else
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
421 {
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
422 si = args(3).xfloat_complex_array_value (x_si_errmsg);
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
423
23592
80e3bfb7bd5a maint: Deprecate is_vector and replace with isvector.
Rik <rik@octave.org>
parents: 23581
diff changeset
424 if (si.isvector () && x.isvector ())
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
425 si = si.reshape (dim_vector (si.numel (), 1));
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
426 }
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
427
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
428 FloatComplexNDArray y (filter (b, a, x, si, dim));
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
429
20909
03e4ddd49396 omit unnecessary nargout checks
John W. Eaton <jwe@octave.org>
parents: 20892
diff changeset
430 retval = ovl (y, si);
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
431 }
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
432 else
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
433 {
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
434 ComplexColumnVector b = args(0).xcomplex_vector_value (a_b_errmsg);
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
435 ComplexColumnVector a = args(1).xcomplex_vector_value (a_b_errmsg);
20687
5f04bfc7c17a backout changeset 18f38ed43962
John W. Eaton <jwe@octave.org>
parents: 20682
diff changeset
436
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
437 ComplexNDArray x = args(2).xcomplex_array_value (x_si_errmsg);
20687
5f04bfc7c17a backout changeset 18f38ed43962
John W. Eaton <jwe@octave.org>
parents: 20682
diff changeset
438
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
439 ComplexNDArray si;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
440
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23450
diff changeset
441 if (nargin == 3 || args(3).isempty ())
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
442 {
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
443 octave_idx_type a_len = a.numel ();
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
444 octave_idx_type b_len = b.numel ();
20687
5f04bfc7c17a backout changeset 18f38ed43962
John W. Eaton <jwe@octave.org>
parents: 20682
diff changeset
445
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
446 octave_idx_type si_len = (a_len > b_len ? a_len : b_len) - 1;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
447
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
448 dim_vector si_dims = x.dims ();
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
449 for (int i = dim; i > 0; i--)
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
450 si_dims(i) = si_dims(i-1);
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
451 si_dims(0) = si_len;
20687
5f04bfc7c17a backout changeset 18f38ed43962
John W. Eaton <jwe@octave.org>
parents: 20682
diff changeset
452
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
453 si.resize (si_dims, 0.0);
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
454 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
455 else
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
456 {
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
457 si = args(3).xcomplex_array_value (x_si_errmsg);
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
458
23592
80e3bfb7bd5a maint: Deprecate is_vector and replace with isvector.
Rik <rik@octave.org>
parents: 23581
diff changeset
459 if (si.isvector () && x.isvector ())
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
460 si = si.reshape (dim_vector (si.numel (), 1));
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
461 }
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
462
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
463 ComplexNDArray y (filter (b, a, x, si, dim));
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
464
20909
03e4ddd49396 omit unnecessary nargout checks
John W. Eaton <jwe@octave.org>
parents: 20892
diff changeset
465 retval = ovl (y, si);
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
466 }
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
467 }
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
468 else
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
469 {
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
470 if (isfloat)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
471 {
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
472 FloatColumnVector b = args(0).xfloat_vector_value (a_b_errmsg);
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
473 FloatColumnVector a = args(1).xfloat_vector_value (a_b_errmsg);
20687
5f04bfc7c17a backout changeset 18f38ed43962
John W. Eaton <jwe@octave.org>
parents: 20682
diff changeset
474
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
475 FloatNDArray x = args(2).xfloat_array_value (x_si_errmsg);
20687
5f04bfc7c17a backout changeset 18f38ed43962
John W. Eaton <jwe@octave.org>
parents: 20682
diff changeset
476
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
477 FloatNDArray si;
3088
f33738510eb2 [project @ 1997-10-02 06:38:36 by jwe]
jwe
parents: 3014
diff changeset
478
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23450
diff changeset
479 if (nargin == 3 || args(3).isempty ())
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
480 {
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
481 octave_idx_type a_len = a.numel ();
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
482 octave_idx_type b_len = b.numel ();
20687
5f04bfc7c17a backout changeset 18f38ed43962
John W. Eaton <jwe@octave.org>
parents: 20682
diff changeset
483
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
484 octave_idx_type si_len = (a_len > b_len ? a_len : b_len) - 1;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
485
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
486 dim_vector si_dims = x.dims ();
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
487 for (int i = dim; i > 0; i--)
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
488 si_dims(i) = si_dims(i-1);
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
489 si_dims(0) = si_len;
20687
5f04bfc7c17a backout changeset 18f38ed43962
John W. Eaton <jwe@octave.org>
parents: 20682
diff changeset
490
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
491 si.resize (si_dims, 0.0);
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
492 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
493 else
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
494 {
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
495 si = args(3).xfloat_array_value (x_si_errmsg);
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
496
23592
80e3bfb7bd5a maint: Deprecate is_vector and replace with isvector.
Rik <rik@octave.org>
parents: 23581
diff changeset
497 if (si.isvector () && x.isvector ())
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
498 si = si.reshape (dim_vector (si.numel (), 1));
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
499 }
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
500
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
501 FloatNDArray y (filter (b, a, x, si, dim));
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
502
20909
03e4ddd49396 omit unnecessary nargout checks
John W. Eaton <jwe@octave.org>
parents: 20892
diff changeset
503 retval = ovl (y, si);
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
504 }
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
505 else
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
506 {
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
507 ColumnVector b = args(0).xvector_value (a_b_errmsg);
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
508 ColumnVector a = args(1).xvector_value (a_b_errmsg);
20687
5f04bfc7c17a backout changeset 18f38ed43962
John W. Eaton <jwe@octave.org>
parents: 20682
diff changeset
509
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
510 NDArray x = args(2).xarray_value (x_si_errmsg);
20687
5f04bfc7c17a backout changeset 18f38ed43962
John W. Eaton <jwe@octave.org>
parents: 20682
diff changeset
511
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
512 NDArray si;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
513
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23450
diff changeset
514 if (nargin == 3 || args(3).isempty ())
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
515 {
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
516 octave_idx_type a_len = a.numel ();
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
517 octave_idx_type b_len = b.numel ();
20687
5f04bfc7c17a backout changeset 18f38ed43962
John W. Eaton <jwe@octave.org>
parents: 20682
diff changeset
518
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
519 octave_idx_type si_len = (a_len > b_len ? a_len : b_len) - 1;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
520
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
521 dim_vector si_dims = x.dims ();
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
522 for (int i = dim; i > 0; i--)
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
523 si_dims(i) = si_dims(i-1);
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
524 si_dims(0) = si_len;
20687
5f04bfc7c17a backout changeset 18f38ed43962
John W. Eaton <jwe@octave.org>
parents: 20682
diff changeset
525
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
526 si.resize (si_dims, 0.0);
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
527 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
528 else
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
529 {
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
530 si = args(3).xarray_value (x_si_errmsg);
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
531
23592
80e3bfb7bd5a maint: Deprecate is_vector and replace with isvector.
Rik <rik@octave.org>
parents: 23581
diff changeset
532 if (si.isvector () && x.isvector ())
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
533 si = si.reshape (dim_vector (si.numel (), 1));
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
534 }
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
535
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
536 NDArray y (filter (b, a, x, si, dim));
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20687
diff changeset
537
20909
03e4ddd49396 omit unnecessary nargout checks
John W. Eaton <jwe@octave.org>
parents: 20892
diff changeset
538 retval = ovl (y, si);
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
539 }
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
540 }
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
541
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
542 return retval;
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
543 }
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
544
10350
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10247
diff changeset
545 template MArray<double>
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10247
diff changeset
546 filter (MArray<double>&, MArray<double>&, MArray<double>&,
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10247
diff changeset
547 MArray<double>&, int dim);
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
548
10350
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10247
diff changeset
549 template MArray<double>
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10247
diff changeset
550 filter (MArray<double>&, MArray<double>&, MArray<double>&, int dim);
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
551
10350
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10247
diff changeset
552 template MArray<Complex>
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10247
diff changeset
553 filter (MArray<Complex>&, MArray<Complex>&, MArray<Complex>&,
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10247
diff changeset
554 MArray<Complex>&, int dim);
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
555
10350
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10247
diff changeset
556 template MArray<Complex>
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10247
diff changeset
557 filter (MArray<Complex>&, MArray<Complex>&, MArray<Complex>&, int dim);
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
558
10350
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10247
diff changeset
559 template MArray<float>
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10247
diff changeset
560 filter (MArray<float>&, MArray<float>&, MArray<float>&,
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10247
diff changeset
561 MArray<float>&, int dim);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
562
10350
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10247
diff changeset
563 template MArray<float>
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10247
diff changeset
564 filter (MArray<float>&, MArray<float>&, MArray<float>&, int dim);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
565
10350
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10247
diff changeset
566 template MArray<FloatComplex>
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10247
diff changeset
567 filter (MArray<FloatComplex>&, MArray<FloatComplex>&, MArray<FloatComplex>&,
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10247
diff changeset
568 MArray<FloatComplex>&, int dim);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
569
10350
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10247
diff changeset
570 template MArray<FloatComplex>
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
571 filter (MArray<FloatComplex>&, MArray<FloatComplex>&, MArray<FloatComplex>&,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
572 int dim);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
573
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
574 /*
9432
8cc2d087f3c1 src/DLD-FUNCTIONS/filter.cc: new tests
Robert T. Short <octave@phaselockedsystems.com>
parents: 9153
diff changeset
575 %!shared a, b, x, r
8cc2d087f3c1 src/DLD-FUNCTIONS/filter.cc: new tests
Robert T. Short <octave@phaselockedsystems.com>
parents: 9153
diff changeset
576 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
577 %! a = [1 1];
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
578 %! b = [1 1];
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
579 %! x = zeros (1,10); x(1) = 1;
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
580 %! assert (filter (b, [1], x ), [1 1 0 0 0 0 0 0 0 0]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
581 %! assert (filter (b, [1], x.'), [1 1 0 0 0 0 0 0 0 0].');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
582 %! assert (filter (b.', [1], x ), [1 1 0 0 0 0 0 0 0 0] );
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
583 %! assert (filter (b.', [1], x.'), [1 1 0 0 0 0 0 0 0 0].');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
584 %! assert (filter ([1], a, x ), [+1 -1 +1 -1 +1 -1 +1 -1 +1 -1] );
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
585 %! assert (filter ([1], a, x.'), [+1 -1 +1 -1 +1 -1 +1 -1 +1 -1].');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
586 %! assert (filter ([1], a.', x ), [+1 -1 +1 -1 +1 -1 +1 -1 +1 -1] );
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
587 %! assert (filter ([1], a.', x.'), [+1 -1 +1 -1 +1 -1 +1 -1 +1 -1].');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
588 %! assert (filter (b, a, x ), [1 0 0 0 0 0 0 0 0 0] );
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
589 %! assert (filter (b.', a, x ), [1 0 0 0 0 0 0 0 0 0] );
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
590 %! assert (filter (b, a.', x ), [1 0 0 0 0 0 0 0 0 0] );
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
591 %! assert (filter (b.', a, x ), [1 0 0 0 0 0 0 0 0 0] );
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
592 %! assert (filter (b, a, x.'), [1 0 0 0 0 0 0 0 0 0].');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
593 %! assert (filter (b.', a, x.'), [1 0 0 0 0 0 0 0 0 0].');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
594 %! assert (filter (b, a.', x.'), [1 0 0 0 0 0 0 0 0 0].');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
595 %! assert (filter (b.', a, x.'), [1 0 0 0 0 0 0 0 0 0].');
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
596
9432
8cc2d087f3c1 src/DLD-FUNCTIONS/filter.cc: new tests
Robert T. Short <octave@phaselockedsystems.com>
parents: 9153
diff changeset
597 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
598 %! r = sqrt (1/2) * (1+i);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
599 %! a = a*r;
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
600 %! b = b*r;
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
601 %! assert (filter (b, [1], x ), r*[1 1 0 0 0 0 0 0 0 0] );
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
602 %! assert (filter (b, [1], r*x ), r*r*[1 1 0 0 0 0 0 0 0 0] );
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
603 %! assert (filter (b, [1], x.' ), r*[1 1 0 0 0 0 0 0 0 0].' );
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
604 %! assert (filter (b, a, x ), [1 0 0 0 0 0 0 0 0 0] );
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
605 %! assert (filter (b, a, r*x ), r*[1 0 0 0 0 0 0 0 0 0] );
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
606
9432
8cc2d087f3c1 src/DLD-FUNCTIONS/filter.cc: new tests
Robert T. Short <octave@phaselockedsystems.com>
parents: 9153
diff changeset
607 %!shared a, b, x, y, so
8cc2d087f3c1 src/DLD-FUNCTIONS/filter.cc: new tests
Robert T. Short <octave@phaselockedsystems.com>
parents: 9153
diff changeset
608 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
609 %! a = [1,1];
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
610 %! b = [1,1];
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
611 %! x = zeros (1,10); x(1) = 1;
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
612 %! [y, so] = filter (b, [1], x, [-1]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
613 %! assert (y, [0 1 0 0 0 0 0 0 0 0]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
614 %! assert (so, 0);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
615
9432
8cc2d087f3c1 src/DLD-FUNCTIONS/filter.cc: new tests
Robert T. Short <octave@phaselockedsystems.com>
parents: 9153
diff changeset
616 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
617 %! x = zeros (10,3); x(1,1) = -1; x(1,2) = 1;
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
618 %! y0 = zeros (10,3); y0(1:2,1) = -1; y0(1:2,2) = 1;
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
619 %! y = filter (b, [1], x);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
620 %! assert (y, y0);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
621
9432
8cc2d087f3c1 src/DLD-FUNCTIONS/filter.cc: new tests
Robert T. Short <octave@phaselockedsystems.com>
parents: 9153
diff changeset
622 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
623 %! a = [1,1];
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
624 %! b=[1,1];
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
625 %! x = zeros (4,4,2); x(1,1:4,1) = +1; x(1,1:4,2) = -1;
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
626 %! y0 = zeros (4,4,2); y0(1:2,1:4,1) = +1; y0(1:2,1:4,2) = -1;
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
627 %! y = filter (b, [1], x);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
628 %! assert (y, y0);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
629
14854
5ae9f0f77635 maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
630 %!assert (filter (1, ones (10,1) / 10, []), [])
5ae9f0f77635 maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
631 %!assert (filter (1, ones (10,1) / 10, zeros (0,10)), zeros (0,10))
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 29980
diff changeset
632 %!assert (filter (1, ones (10,1) / 10, single (1:5)),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 29980
diff changeset
633 %! repmat (single (10), 1, 5))
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
634
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22407
diff changeset
635 ## Test using initial conditions
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
636 %!assert (filter ([1, 1, 1], [1, 1], [1 2], [1, 1]), [2 2])
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
637 %!assert (filter ([1, 1, 1], [1, 1], [1 2], [1, 1]'), [2 2])
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
638 %!assert (filter ([1, 3], [1], [1 2; 3 4; 5 6], [4, 5]), [5 7; 6 10; 14 18])
28930
2883b3d08b7e maint: Remove unnecessary parentheses bracketing %!error BIST tests.
Rik <rik@octave.org>
parents: 27957
diff changeset
639 %!error filter ([1, 3], [1], [1 2; 3 4; 5 6], [4, 5]')
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 29980
diff changeset
640 %!assert (filter ([1, 3, 2], [1], [1 2; 3 4; 5 6], [1 0 0; 1 0 0], 2),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 29980
diff changeset
641 %! [2 6; 3 13; 5 21])
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
642
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
643 ## Test of DIM parameter
12774
ec6c52496485 Fix input validation of SI vector for filter() when DIM used (Bug #33625)
Rik <octave@nomad.inbox5.com>
parents: 12707
diff changeset
644 %!test
ec6c52496485 Fix input validation of SI vector for filter() when DIM used (Bug #33625)
Rik <octave@nomad.inbox5.com>
parents: 12707
diff changeset
645 %! x = ones (2, 1, 3, 4);
ec6c52496485 Fix input validation of SI vector for filter() when DIM used (Bug #33625)
Rik <octave@nomad.inbox5.com>
parents: 12707
diff changeset
646 %! x(1,1,:,:) = [1 2 3 4; 5 6 7 8; 9 10 11 12];
ec6c52496485 Fix input validation of SI vector for filter() when DIM used (Bug #33625)
Rik <octave@nomad.inbox5.com>
parents: 12707
diff changeset
647 %! y0 = [1 1 6 2 15 3 2 1 8 2 18 3 3 1 10 2 21 3 4 1 12 2 24 3];
ec6c52496485 Fix input validation of SI vector for filter() when DIM used (Bug #33625)
Rik <octave@nomad.inbox5.com>
parents: 12707
diff changeset
648 %! y0 = reshape (y0, size (x));
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
649 %! y = filter ([1 1 1], 1, x, [], 3);
12774
ec6c52496485 Fix input validation of SI vector for filter() when DIM used (Bug #33625)
Rik <octave@nomad.inbox5.com>
parents: 12707
diff changeset
650 %! assert (y, y0);
10155
d0ce5e973937 DLD-FUNCTIONS/*.cc: delete Emacs local-variables settings
John W. Eaton <jwe@octave.org>
parents: 10154
diff changeset
651 */
29958
32c3a5805893 move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
652
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 30576
diff changeset
653 OCTAVE_END_NAMESPACE(octave)