Mercurial > octave
annotate libinterp/corefcn/filter.cc @ 20682:18f38ed43962
vector_value exctractors with error messages
* ov.h, ov.cc (octave_value::vector_value,
octave_value::complex_vector_value, octave_value::float_vector_value,
octave_value::float_complex_vector_value, octave_value::int_vector_value):
New overloaded methods with error messages.
* daspk.cc, dasrt.cc, dassl.cc, file-io.cc, filter.cc, graphics.cc,
lsode.cc, matrix_type.cc, quad.cc rand.cc, __eigs__.cc,
__magick_read__.cc: Use them and eliminate more uses of error_state.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 06 Nov 2015 16:52:49 -0500 |
parents | a9574e3c6e9e |
children | 5f04bfc7c17a |
rev | line source |
---|---|
2928 | 1 /* |
2 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
18812
diff
changeset
|
3 Copyright (C) 1996-2015 John W. Eaton |
2928 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
2928 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
2928 | 20 |
21 */ | |
22 | |
23 // Based on Tony Richardson's filter.m. | |
24 // | |
5428 | 25 // Originally translated to C++ by KH (Kurt.Hornik@wu-wien.ac.at) |
2928 | 26 // with help from Fritz Leisch and Andreas Weingessel on Oct 20, 1994. |
27 // | |
28 // Rewritten to use templates to handle both real and complex cases by | |
29 // jwe, Wed Nov 1 19:15:29 1995. | |
30 | |
31 #ifdef HAVE_CONFIG_H | |
32 #include <config.h> | |
33 #endif | |
34 | |
4153 | 35 #include "quit.h" |
36 | |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
37 #include "defun.h" |
2928 | 38 #include "error.h" |
39 #include "oct-obj.h" | |
40 | |
3109 | 41 #if !defined (CXX_NEW_FRIEND_TEMPLATE_DECL) |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
42 extern MArray<double> |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
43 filter (MArray<double>&, MArray<double>&, MArray<double>&, int dim); |
2928 | 44 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
45 extern MArray<Complex> |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
46 filter (MArray<Complex>&, MArray<Complex>&, MArray<Complex>&, int dim); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
47 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
48 extern MArray<float> |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
49 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
|
50 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
51 extern MArray<FloatComplex> |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
52 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
|
53 int dim); |
3107 | 54 #endif |
2928 | 55 |
56 template <class T> | |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
57 MArray<T> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
58 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
|
59 int dim = 0) |
2928 | 60 { |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
61 MArray<T> y; |
2928 | 62 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20230
diff
changeset
|
63 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
|
64 octave_idx_type b_len = b.numel (); |
2928 | 65 |
5275 | 66 octave_idx_type ab_len = a_len > b_len ? a_len : b_len; |
2928 | 67 |
12637
d02798e9eeae
filter.cc: Stop test errors in residue.m (bug #33164)
Rik <octave@nomad.inbox5.com>
parents:
12566
diff
changeset
|
68 // FIXME: The two lines below should be unecessary because |
d02798e9eeae
filter.cc: Stop test errors in residue.m (bug #33164)
Rik <octave@nomad.inbox5.com>
parents:
12566
diff
changeset
|
69 // 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
|
70 // 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
|
71 // 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
|
72 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
|
73 if (a_len > 1) |
d02798e9eeae
filter.cc: Stop test errors in residue.m (bug #33164)
Rik <octave@nomad.inbox5.com>
parents:
12566
diff
changeset
|
74 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
|
75 |
2928 | 76 T norm = a (0); |
77 | |
19739
3fa35defe495
Adjust spacing of static_cast<> calls to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
78 if (norm == static_cast<T> (0.0)) |
2928 | 79 { |
18812
9ac2357f19bc
doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
80 error ("filter: the first element of A must be nonzero"); |
2928 | 81 return y; |
82 } | |
83 | |
4844 | 84 dim_vector x_dims = x.dims (); |
5056 | 85 if (dim < 0 || dim > x_dims.length ()) |
4844 | 86 { |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
87 error ("filter: DIM must be a valid dimension"); |
4844 | 88 return y; |
89 } | |
90 | |
5275 | 91 octave_idx_type x_len = x_dims(dim); |
4844 | 92 |
93 dim_vector si_dims = si.dims (); | |
5275 | 94 octave_idx_type si_len = si_dims(0); |
4844 | 95 |
96 if (si_len != ab_len - 1) | |
97 { | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
98 error ("filter: first dimension of SI must be of length max (length (a), length (b)) - 1"); |
4844 | 99 return y; |
100 } | |
101 | |
5059 | 102 if (si_dims.length () != x_dims.length ()) |
4844 | 103 { |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
104 error ("filter: dimensionality of SI and X must agree"); |
4844 | 105 return y; |
106 } | |
107 | |
12774
ec6c52496485
Fix input validation of SI vector for filter() when DIM used (Bug #33625)
Rik <octave@nomad.inbox5.com>
parents:
12707
diff
changeset
|
108 for (octave_idx_type i = 1; i < dim; i++) |
4844 | 109 { |
12774
ec6c52496485
Fix input validation of SI vector for filter() when DIM used (Bug #33625)
Rik <octave@nomad.inbox5.com>
parents:
12707
diff
changeset
|
110 if (si_dims(i) != x_dims(i-1)) |
ec6c52496485
Fix input validation of SI vector for filter() when DIM used (Bug #33625)
Rik <octave@nomad.inbox5.com>
parents:
12707
diff
changeset
|
111 { |
ec6c52496485
Fix input validation of SI vector for filter() when DIM used (Bug #33625)
Rik <octave@nomad.inbox5.com>
parents:
12707
diff
changeset
|
112 error ("filter: dimensionality of SI and X must agree"); |
ec6c52496485
Fix input validation of SI vector for filter() when DIM used (Bug #33625)
Rik <octave@nomad.inbox5.com>
parents:
12707
diff
changeset
|
113 return y; |
ec6c52496485
Fix input validation of SI vector for filter() when DIM used (Bug #33625)
Rik <octave@nomad.inbox5.com>
parents:
12707
diff
changeset
|
114 } |
ec6c52496485
Fix input validation of SI vector for filter() when DIM used (Bug #33625)
Rik <octave@nomad.inbox5.com>
parents:
12707
diff
changeset
|
115 } |
ec6c52496485
Fix input validation of SI vector for filter() when DIM used (Bug #33625)
Rik <octave@nomad.inbox5.com>
parents:
12707
diff
changeset
|
116 for (octave_idx_type i = dim+1; i < x_dims.length (); i++) |
ec6c52496485
Fix input validation of SI vector for filter() when DIM used (Bug #33625)
Rik <octave@nomad.inbox5.com>
parents:
12707
diff
changeset
|
117 { |
ec6c52496485
Fix input validation of SI vector for filter() when DIM used (Bug #33625)
Rik <octave@nomad.inbox5.com>
parents:
12707
diff
changeset
|
118 if (si_dims(i) != x_dims(i)) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
119 { |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
120 error ("filter: dimensionality of SI and X must agree"); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
121 return y; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
122 } |
4844 | 123 } |
2928 | 124 |
10241
a277ba5da4dc
filter.cc: return early if X is empty
John W. Eaton <jwe@octave.org>
parents:
10155
diff
changeset
|
125 if (x_len == 0) |
a277ba5da4dc
filter.cc: return early if X is empty
John W. Eaton <jwe@octave.org>
parents:
10155
diff
changeset
|
126 return x; |
a277ba5da4dc
filter.cc: return early if X is empty
John W. Eaton <jwe@octave.org>
parents:
10155
diff
changeset
|
127 |
19739
3fa35defe495
Adjust spacing of static_cast<> calls to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
128 if (norm != static_cast<T> (1.0)) |
4844 | 129 { |
20230
e914b5399c67
Use in-place operators in C++ code where possible.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
130 a /= norm; |
e914b5399c67
Use in-place operators in C++ code where possible.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
131 b /= norm; |
4844 | 132 } |
2928 | 133 |
5056 | 134 if (a_len <= 1 && si_len <= 0) |
4844 | 135 return b(0) * x; |
136 | |
137 y.resize (x_dims, 0.0); | |
138 | |
139 int x_stride = 1; | |
140 for (int i = 0; i < dim; i++) | |
141 x_stride *= x_dims(i); | |
2928 | 142 |
5275 | 143 octave_idx_type x_num = x_dims.numel () / x_len; |
144 for (octave_idx_type num = 0; num < x_num; num++) | |
4844 | 145 { |
5275 | 146 octave_idx_type x_offset; |
4844 | 147 if (x_stride == 1) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
148 x_offset = num * x_len; |
4844 | 149 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
150 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
151 octave_idx_type x_offset2 = 0; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
152 x_offset = num; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
153 while (x_offset >= x_stride) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
154 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
155 x_offset -= x_stride; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
156 x_offset2++; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
157 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
158 x_offset += x_offset2 * x_stride * x_len; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
159 } |
5275 | 160 octave_idx_type si_offset = num * si_len; |
2928 | 161 |
4844 | 162 if (a_len > 1) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
163 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
164 T *py = y.fortran_vec (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
165 T *psi = si.fortran_vec (); |
5114 | 166 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
167 const T *pa = a.data (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
168 const T *pb = b.data (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
169 const T *px = x.data (); |
5114 | 170 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
171 psi += si_offset; |
5114 | 172 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
173 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
|
174 i < x_len; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
175 i++, idx += x_stride) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
176 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
177 py[idx] = psi[0] + pb[0] * px[idx]; |
5114 | 178 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
179 if (si_len > 0) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
180 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
181 for (octave_idx_type j = 0; j < si_len - 1; j++) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
182 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
183 OCTAVE_QUIT; |
5114 | 184 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
185 psi[j] = psi[j+1] - pa[j+1] * py[idx] + pb[j+1] * px[idx]; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
186 } |
5114 | 187 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
188 psi[si_len-1] = pb[si_len] * px[idx] - pa[si_len] * py[idx]; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
189 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
190 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
191 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
192 OCTAVE_QUIT; |
5114 | 193 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
194 psi[0] = pb[si_len] * px[idx] - pa[si_len] * py[idx]; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
195 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
196 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
197 } |
5114 | 198 else if (si_len > 0) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
199 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
200 T *py = y.fortran_vec (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
201 T *psi = si.fortran_vec (); |
5114 | 202 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
203 const T *pb = b.data (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
204 const T *px = x.data (); |
5114 | 205 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
206 psi += si_offset; |
5114 | 207 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
208 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
|
209 i < x_len; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
210 i++, idx += x_stride) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
211 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
212 py[idx] = psi[0] + pb[0] * px[idx]; |
4844 | 213 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
214 if (si_len > 1) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
215 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
216 for (octave_idx_type j = 0; j < si_len - 1; j++) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
217 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
218 OCTAVE_QUIT; |
4153 | 219 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
220 psi[j] = psi[j+1] + pb[j+1] * px[idx]; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
221 } |
4844 | 222 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
223 psi[si_len-1] = pb[si_len] * px[idx]; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
224 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
225 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
226 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
227 OCTAVE_QUIT; |
4844 | 228 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
229 psi[0] = pb[1] * px[idx]; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
230 } |
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 | 233 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
234 |
2928 | 235 return y; |
236 } | |
237 | |
3109 | 238 #if !defined (CXX_NEW_FRIEND_TEMPLATE_DECL) |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
239 extern MArray<double> |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
240 filter (MArray<double>&, MArray<double>&, MArray<double>&, |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
241 MArray<double>&, int dim); |
2928 | 242 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
243 extern MArray<Complex> |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
244 filter (MArray<Complex>&, MArray<Complex>&, MArray<Complex>&, |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
245 MArray<Complex>&, int dim); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
246 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
247 extern MArray<float> |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
248 filter (MArray<float>&, MArray<float>&, MArray<float>&, |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
249 MArray<float>&, int dim); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
250 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
251 extern MArray<FloatComplex> |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
252 filter (MArray<FloatComplex>&, MArray<FloatComplex>&, MArray<FloatComplex>&, |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
253 MArray<FloatComplex>&, int dim); |
3107 | 254 #endif |
2928 | 255 |
256 template <class T> | |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
257 MArray<T> |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
258 filter (MArray<T>& b, MArray<T>& a, MArray<T>& x, int dim = -1) |
2928 | 259 { |
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
|
260 dim_vector x_dims = x.dims (); |
4844 | 261 |
262 if (dim < 0) | |
263 { | |
264 // Find first non-singleton dimension | |
5059 | 265 while (dim < x_dims.length () && x_dims(dim) <= 1) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
266 dim++; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
267 |
4844 | 268 // All dimensions singleton, pick first dimension |
269 if (dim == x_dims.length ()) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
270 dim = 0; |
4844 | 271 } |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
272 else if (dim < 0 || dim > x_dims.length ()) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
273 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
274 error ("filter: DIM must be a valid dimension"); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
275 return MArray<T> (); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
276 } |
4844 | 277 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20230
diff
changeset
|
278 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
|
279 octave_idx_type b_len = b.numel (); |
2928 | 280 |
5275 | 281 octave_idx_type si_len = (a_len > b_len ? a_len : b_len) - 1; |
4844 | 282 dim_vector si_dims = x.dims (); |
283 for (int i = dim; i > 0; i--) | |
5059 | 284 si_dims(i) = si_dims(i-1); |
285 si_dims(0) = si_len; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
286 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
287 MArray<T> si (si_dims, T (0.0)); |
2928 | 288 |
4844 | 289 return filter (b, a, x, si, dim); |
2928 | 290 } |
291 | |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
292 DEFUN (filter, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
293 "-*- texinfo -*-\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19739
diff
changeset
|
294 @deftypefn {Built-in Function} {@var{y} =} filter (@var{b}, @var{a}, @var{x})\n\ |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
295 @deftypefnx {Built-in Function} {[@var{y}, @var{sf}] =} filter (@var{b}, @var{a}, @var{x}, @var{si})\n\ |
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
296 @deftypefnx {Built-in Function} {[@var{y}, @var{sf}] =} filter (@var{b}, @var{a}, @var{x}, [], @var{dim})\n\ |
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
297 @deftypefnx {Built-in Function} {[@var{y}, @var{sf}] =} filter (@var{b}, @var{a}, @var{x}, @var{si}, @var{dim})\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19739
diff
changeset
|
298 Apply a 1-D digital filter to the data @var{x}.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19739
diff
changeset
|
299 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19739
diff
changeset
|
300 @code{filter} returns the solution to the following linear, time-invariant\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19739
diff
changeset
|
301 difference equation:\n\ |
3367 | 302 @tex\n\ |
303 $$\n\ | |
304 \\sum_{k=0}^N a_{k+1} y_{n-k} = \\sum_{k=0}^M b_{k+1} x_{n-k}, \\qquad\n\ | |
305 1 \\le n \\le P\n\ | |
306 $$\n\ | |
307 @end tex\n\ | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7789
diff
changeset
|
308 @ifnottex\n\ |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
309 @c Set example in small font to prevent overfull line\n\ |
2928 | 310 \n\ |
3367 | 311 @smallexample\n\ |
10840 | 312 @group\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
313 N M\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
314 SUM a(k+1) y(n-k) = SUM b(k+1) x(n-k) for 1<=n<=length(x)\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
315 k=0 k=0\n\ |
10840 | 316 @end group\n\ |
3367 | 317 @end smallexample\n\ |
10840 | 318 \n\ |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7789
diff
changeset
|
319 @end ifnottex\n\ |
2928 | 320 \n\ |
3367 | 321 @noindent\n\ |
322 where\n\ | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7789
diff
changeset
|
323 @ifnottex\n\ |
14842
aa4c25ca498e
doc: Improve docstring for filter.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
324 N=length(a)-1 and M=length(b)-1.\n\ |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7789
diff
changeset
|
325 @end ifnottex\n\ |
3367 | 326 @tex\n\ |
14842
aa4c25ca498e
doc: Improve docstring for filter.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
327 $a \\in \\Re^{N-1}$, $b \\in \\Re^{M-1}$, and $x \\in \\Re^P$.\n\ |
3367 | 328 @end tex\n\ |
14842
aa4c25ca498e
doc: Improve docstring for filter.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
329 The result is calculated over the first non-singleton dimension of @var{x}\n\ |
aa4c25ca498e
doc: Improve docstring for filter.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
330 or over @var{dim} if supplied.\n\ |
aa4c25ca498e
doc: Improve docstring for filter.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
331 \n\ |
aa4c25ca498e
doc: Improve docstring for filter.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
332 An equivalent form of the equation is:\n\ |
3367 | 333 @tex\n\ |
334 $$\n\ | |
335 y_n = -\\sum_{k=1}^N c_{k+1} y_{n-k} + \\sum_{k=0}^M d_{k+1} x_{n-k}, \\qquad\n\ | |
336 1 \\le n \\le P\n\ | |
337 $$\n\ | |
338 @end tex\n\ | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7789
diff
changeset
|
339 @ifnottex\n\ |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
340 @c Set example in small font to prevent overfull line\n\ |
2928 | 341 \n\ |
3367 | 342 @smallexample\n\ |
10840 | 343 @group\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
344 N M\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
345 y(n) = - SUM c(k+1) y(n-k) + SUM d(k+1) x(n-k) for 1<=n<=length(x)\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
346 k=1 k=0\n\ |
10840 | 347 @end group\n\ |
3367 | 348 @end smallexample\n\ |
10840 | 349 \n\ |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7789
diff
changeset
|
350 @end ifnottex\n\ |
3367 | 351 \n\ |
352 @noindent\n\ | |
353 where\n\ | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7789
diff
changeset
|
354 @ifnottex\n\ |
3367 | 355 c = a/a(1) and d = b/a(1).\n\ |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7789
diff
changeset
|
356 @end ifnottex\n\ |
3367 | 357 @tex\n\ |
358 $c = a/a_1$ and $d = b/a_1$.\n\ | |
359 @end tex\n\ | |
360 \n\ | |
361 If the fourth argument @var{si} is provided, it is taken as the\n\ | |
362 initial state of the system and the final state is returned as\n\ | |
363 @var{sf}. The state vector is a column vector whose length is\n\ | |
364 equal to the length of the longest coefficient vector minus one.\n\ | |
365 If @var{si} is not supplied, the initial state vector is set to all\n\ | |
2928 | 366 zeros.\n\ |
367 \n\ | |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19739
diff
changeset
|
368 In terms of the Z Transform, @var{y} is the result of passing the\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19739
diff
changeset
|
369 discrete-time signal @var{x} through a system characterized by the following\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19739
diff
changeset
|
370 rational system function:\n\ |
3367 | 371 @tex\n\ |
372 $$\n\ | |
373 H(z) = {\\displaystyle\\sum_{k=0}^M d_{k+1} z^{-k}\n\ | |
374 \\over 1 + \\displaystyle\\sum_{k+1}^N c_{k+1} z^{-k}}\n\ | |
375 $$\n\ | |
376 @end tex\n\ | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7789
diff
changeset
|
377 @ifnottex\n\ |
3367 | 378 \n\ |
379 @example\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
380 @group\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
381 M\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
382 SUM d(k+1) z^(-k)\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
383 k=0\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
384 H(z) = ---------------------\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
385 N\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
386 1 + SUM c(k+1) z^(-k)\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
387 k=1\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
388 @end group\n\ |
3367 | 389 @end example\n\ |
10840 | 390 \n\ |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7789
diff
changeset
|
391 @end ifnottex\n\ |
11572
7d6d8c1e471f
Grammarcheck Texinfo for files in src directory.
Rik <octave@nomad.inbox5.com>
parents:
11553
diff
changeset
|
392 @seealso{filter2, fftfilt, freqz}\n\ |
3367 | 393 @end deftypefn") |
2928 | 394 { |
395 octave_value_list retval; | |
396 | |
397 int nargin = args.length (); | |
398 | |
4844 | 399 if (nargin < 3 || nargin > 5) |
2928 | 400 { |
5823 | 401 print_usage (); |
2928 | 402 return retval; |
403 } | |
404 | |
4844 | 405 const char *errmsg = "filter: arguments a and b must be vectors"; |
406 | |
407 int dim; | |
408 dim_vector x_dims = args(2).dims (); | |
2928 | 409 |
4844 | 410 if (nargin == 5) |
411 { | |
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
|
412 dim = args(4).nint_value () - 1; |
4844 | 413 if (dim < 0 || dim >= x_dims.length ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
414 { |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
415 error ("filter: DIM must be a valid dimension"); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
416 return retval; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
417 } |
4844 | 418 } |
419 else | |
420 { | |
421 // Find first non-singleton dimension | |
422 dim = 0; | |
5059 | 423 while (dim < x_dims.length () && x_dims(dim) <= 1) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
424 dim++; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
425 |
4844 | 426 // All dimensions singleton, pick first dimension |
427 if (dim == x_dims.length ()) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
428 dim = 0; |
4844 | 429 } |
2928 | 430 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
431 bool isfloat = (args(0).is_single_type () |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
432 || args(1).is_single_type () |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
433 || args(2).is_single_type () |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
434 || (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
|
435 |
2928 | 436 if (args(0).is_complex_type () |
437 || args(1).is_complex_type () | |
438 || args(2).is_complex_type () | |
4844 | 439 || (nargin >= 4 && args(3).is_complex_type ())) |
2928 | 440 { |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
441 if (isfloat) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
442 { |
20682
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
443 FloatComplexColumnVector b (args(0).float_complex_vector_value (errmsg)); |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
444 FloatComplexColumnVector a (args(1).float_complex_vector_value (errmsg)); |
3088 | 445 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
446 FloatComplexNDArray x (args(2).float_complex_array_value ()); |
3088 | 447 |
20682
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
448 FloatComplexNDArray si; |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
449 |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
450 if (nargin == 3 || args(3).is_empty ()) |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
451 { |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
452 octave_idx_type a_len = a.numel (); |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
453 octave_idx_type b_len = b.numel (); |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
454 |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
455 octave_idx_type si_len = (a_len > b_len ? a_len : b_len) - 1; |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
456 |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
457 dim_vector si_dims = x.dims (); |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
458 for (int i = dim; i > 0; i--) |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
459 si_dims(i) = si_dims(i-1); |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
460 si_dims(0) = si_len; |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
461 |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
462 si.resize (si_dims, 0.0); |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
463 } |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
464 else |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
465 { |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
466 si = args(3).float_complex_array_value (); |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
467 |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
468 if (si.is_vector () && x.is_vector ()) |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
469 si = si.reshape (dim_vector (si.numel (), 1)); |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
470 } |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
471 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
472 if (! error_state) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
473 { |
20682
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
474 FloatComplexNDArray y (filter (b, a, x, si, dim)); |
3088 | 475 |
20682
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
476 if (nargout == 2) |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
477 retval(1) = si; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
478 |
20682
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
479 retval(0) = y; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
480 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
481 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
482 error (errmsg); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
483 } |
2928 | 484 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
485 { |
20682
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
486 ComplexColumnVector b (args(0).complex_vector_value (errmsg)); |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
487 ComplexColumnVector a (args(1).complex_vector_value (errmsg)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
488 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
489 ComplexNDArray x (args(2).complex_array_value ()); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
490 |
20682
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
491 ComplexNDArray si; |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
492 |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
493 if (nargin == 3 || args(3).is_empty ()) |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
494 { |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
495 octave_idx_type a_len = a.numel (); |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
496 octave_idx_type b_len = b.numel (); |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
497 |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
498 octave_idx_type si_len = (a_len > b_len ? a_len : b_len) - 1; |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
499 |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
500 dim_vector si_dims = x.dims (); |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
501 for (int i = dim; i > 0; i--) |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
502 si_dims(i) = si_dims(i-1); |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
503 si_dims(0) = si_len; |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
504 |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
505 si.resize (si_dims, 0.0); |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
506 } |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
507 else |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
508 { |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
509 si = args(3).complex_array_value (); |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
510 |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
511 if (si.is_vector () && x.is_vector ()) |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
512 si = si.reshape (dim_vector (si.numel (), 1)); |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
513 } |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
514 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
515 if (! error_state) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
516 { |
20682
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
517 ComplexNDArray y (filter (b, a, x, si, dim)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
518 |
20682
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
519 if (nargout == 2) |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
520 retval(1) = si; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
521 |
20682
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
522 retval(0) = y; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
523 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
524 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
525 error (errmsg); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
526 } |
2928 | 527 } |
528 else | |
529 { | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
530 if (isfloat) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
531 { |
20682
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
532 FloatColumnVector b (args(0).float_vector_value (errmsg)); |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
533 FloatColumnVector a (args(1).float_vector_value (errmsg)); |
3088 | 534 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
535 FloatNDArray x (args(2).float_array_value ()); |
3088 | 536 |
20682
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
537 FloatNDArray si; |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
538 |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
539 if (nargin == 3 || args(3).is_empty ()) |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
540 { |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
541 octave_idx_type a_len = a.numel (); |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
542 octave_idx_type b_len = b.numel (); |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
543 |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
544 octave_idx_type si_len = (a_len > b_len ? a_len : b_len) - 1; |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
545 |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
546 dim_vector si_dims = x.dims (); |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
547 for (int i = dim; i > 0; i--) |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
548 si_dims(i) = si_dims(i-1); |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
549 si_dims(0) = si_len; |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
550 |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
551 si.resize (si_dims, 0.0); |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
552 } |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
553 else |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
554 { |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
555 si = args(3).float_array_value (); |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
556 |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
557 if (si.is_vector () && x.is_vector ()) |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
558 si = si.reshape (dim_vector (si.numel (), 1)); |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
559 } |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
560 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
561 if (! error_state) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
562 { |
20682
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
563 FloatNDArray y (filter (b, a, x, si, dim)); |
3088 | 564 |
20682
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
565 if (nargout == 2) |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
566 retval(1) = si; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
567 |
20682
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
568 retval(0) = y; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
569 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
570 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
571 error (errmsg); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
572 } |
2928 | 573 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
574 { |
20682
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
575 ColumnVector b (args(0).vector_value (errmsg)); |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
576 ColumnVector a (args(1).vector_value (errmsg)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
577 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
578 NDArray x (args(2).array_value ()); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
579 |
20682
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
580 NDArray si; |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
581 |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
582 if (nargin == 3 || args(3).is_empty ()) |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
583 { |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
584 octave_idx_type a_len = a.numel (); |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
585 octave_idx_type b_len = b.numel (); |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
586 |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
587 octave_idx_type si_len = (a_len > b_len ? a_len : b_len) - 1; |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
588 |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
589 dim_vector si_dims = x.dims (); |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
590 for (int i = dim; i > 0; i--) |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
591 si_dims(i) = si_dims(i-1); |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
592 si_dims(0) = si_len; |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
593 |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
594 si.resize (si_dims, 0.0); |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
595 } |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
596 else |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
597 { |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
598 si = args(3).array_value (); |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
599 |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
600 if (si.is_vector () && x.is_vector ()) |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
601 si = si.reshape (dim_vector (si.numel (), 1)); |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
602 } |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
603 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
604 if (! error_state) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
605 { |
20682
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
606 NDArray y (filter (b, a, x, si, dim)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
607 |
20682
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
608 if (nargout == 2) |
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
609 retval(1) = si; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
610 |
20682
18f38ed43962
vector_value exctractors with error messages
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
611 retval(0) = y; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
612 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
613 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
614 error (errmsg); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
615 } |
2928 | 616 } |
617 | |
618 return retval; | |
619 } | |
620 | |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
621 template MArray<double> |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
622 filter (MArray<double>&, MArray<double>&, MArray<double>&, |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
623 MArray<double>&, int dim); |
2928 | 624 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
625 template MArray<double> |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
626 filter (MArray<double>&, MArray<double>&, MArray<double>&, int dim); |
2928 | 627 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
628 template MArray<Complex> |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
629 filter (MArray<Complex>&, MArray<Complex>&, MArray<Complex>&, |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
630 MArray<Complex>&, int dim); |
2928 | 631 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
632 template MArray<Complex> |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
633 filter (MArray<Complex>&, MArray<Complex>&, MArray<Complex>&, int dim); |
2928 | 634 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
635 template MArray<float> |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
636 filter (MArray<float>&, MArray<float>&, MArray<float>&, |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
637 MArray<float>&, int dim); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
638 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
639 template MArray<float> |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
640 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
|
641 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
642 template MArray<FloatComplex> |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
643 filter (MArray<FloatComplex>&, MArray<FloatComplex>&, MArray<FloatComplex>&, |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
644 MArray<FloatComplex>&, int dim); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
645 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10247
diff
changeset
|
646 template MArray<FloatComplex> |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
647 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
|
648 int dim); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
649 |
2928 | 650 /* |
9432
8cc2d087f3c1
src/DLD-FUNCTIONS/filter.cc: new tests
Robert T. Short <octave@phaselockedsystems.com>
parents:
9153
diff
changeset
|
651 %!shared a, b, x, r |
8cc2d087f3c1
src/DLD-FUNCTIONS/filter.cc: new tests
Robert T. Short <octave@phaselockedsystems.com>
parents:
9153
diff
changeset
|
652 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
653 %! a = [1 1]; |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
654 %! b = [1 1]; |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
655 %! 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
|
656 %! 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
|
657 %! 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
|
658 %! 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
|
659 %! 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
|
660 %! 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
|
661 %! 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
|
662 %! 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
|
663 %! 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
|
664 %! 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
|
665 %! 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
|
666 %! 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
|
667 %! 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
|
668 %! 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
|
669 %! 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
|
670 %! 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
|
671 %! 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
|
672 |
9432
8cc2d087f3c1
src/DLD-FUNCTIONS/filter.cc: new tests
Robert T. Short <octave@phaselockedsystems.com>
parents:
9153
diff
changeset
|
673 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
674 %! 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
|
675 %! a = a*r; |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
676 %! b = b*r; |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
677 %! 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
|
678 %! 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
|
679 %! 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
|
680 %! 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
|
681 %! 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
|
682 |
9432
8cc2d087f3c1
src/DLD-FUNCTIONS/filter.cc: new tests
Robert T. Short <octave@phaselockedsystems.com>
parents:
9153
diff
changeset
|
683 %!shared a, b, x, y, so |
8cc2d087f3c1
src/DLD-FUNCTIONS/filter.cc: new tests
Robert T. Short <octave@phaselockedsystems.com>
parents:
9153
diff
changeset
|
684 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
685 %! a = [1,1]; |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
686 %! b = [1,1]; |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
687 %! 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
|
688 %! [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
|
689 %! 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
|
690 %! assert (so, 0); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
691 |
9432
8cc2d087f3c1
src/DLD-FUNCTIONS/filter.cc: new tests
Robert T. Short <octave@phaselockedsystems.com>
parents:
9153
diff
changeset
|
692 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
693 %! 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
|
694 %! 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
|
695 %! 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
|
696 %! assert (y, y0); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
697 |
9432
8cc2d087f3c1
src/DLD-FUNCTIONS/filter.cc: new tests
Robert T. Short <octave@phaselockedsystems.com>
parents:
9153
diff
changeset
|
698 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
699 %! a = [1,1]; |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
700 %! b=[1,1]; |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
701 %! 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
|
702 %! 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
|
703 %! 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
|
704 %! assert (y, y0); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
705 |
14854
5ae9f0f77635
maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
706 %!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
|
707 %!assert (filter (1, ones (10,1) / 10, zeros (0,10)), zeros (0,10)) |
5ae9f0f77635
maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
708 %!assert (filter (1, ones (10,1) / 10, single (1:5)), 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
|
709 |
12707
a5f4dad4ec27
Merge with stable; recover on default backed-out 9843b3b055e0 from stable
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12706
diff
changeset
|
710 %% 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
|
711 %!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
|
712 %!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
|
713 %!assert (filter ([1, 3], [1], [1 2; 3 4; 5 6], [4, 5]), [5 7; 6 10; 14 18]) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
714 %!error (filter ([1, 3], [1], [1 2; 3 4; 5 6], [4, 5]')) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
715 %!assert (filter ([1, 3, 2], [1], [1 2; 3 4; 5 6], [1 0 0; 1 0 0], 2), [2 6; 3 13; 5 21]) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
716 |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
717 ## 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
|
718 %!test |
ec6c52496485
Fix input validation of SI vector for filter() when DIM used (Bug #33625)
Rik <octave@nomad.inbox5.com>
parents:
12707
diff
changeset
|
719 %! 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
|
720 %! 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
|
721 %! 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
|
722 %! 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
|
723 %! 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
|
724 %! assert (y, y0); |
10155
d0ce5e973937
DLD-FUNCTIONS/*.cc: delete Emacs local-variables settings
John W. Eaton <jwe@octave.org>
parents:
10154
diff
changeset
|
725 */ |