Mercurial > octave-nkf
annotate src/DLD-FUNCTIONS/conv2.cc @ 10368:d2849dbcc858
undo unintended changes to conv2 in previous commit
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 27 Feb 2010 16:15:38 -0500 |
parents | 173e10268080 |
children | dc8637fd7a76 |
rev | line source |
---|---|
5819 | 1 /* |
2 | |
8920 | 3 Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 |
7017 | 4 Andy Adler |
5819 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
5819 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
5819 | 21 |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include <config.h> | |
26 #endif | |
27 | |
28 #include "defun-dld.h" | |
29 #include "error.h" | |
30 #include "oct-obj.h" | |
31 #include "utils.h" | |
32 | |
10368
d2849dbcc858
undo unintended changes to conv2 in previous commit
John W. Eaton <jwe@octave.org>
parents:
10367
diff
changeset
|
33 #define MAX(a,b) ((a) > (b) ? (a) : (b)) |
d2849dbcc858
undo unintended changes to conv2 in previous commit
John W. Eaton <jwe@octave.org>
parents:
10367
diff
changeset
|
34 |
5819 | 35 enum Shape { SHAPE_FULL, SHAPE_SAME, SHAPE_VALID }; |
36 | |
37 #if !defined (CXX_NEW_FRIEND_TEMPLATE_DECL) | |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
38 extern MArray<double> |
10368
d2849dbcc858
undo unintended changes to conv2 in previous commit
John W. Eaton <jwe@octave.org>
parents:
10367
diff
changeset
|
39 conv2 (MArray<double>&, MArray<double>&, MArray<double>&, Shape); |
5819 | 40 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
41 extern MArray<Complex> |
10368
d2849dbcc858
undo unintended changes to conv2 in previous commit
John W. Eaton <jwe@octave.org>
parents:
10367
diff
changeset
|
42 conv2 (MArray<Complex>&, MArray<Complex>&, MArray<Complex>&, Shape); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
43 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
44 extern MArray<float> |
10368
d2849dbcc858
undo unintended changes to conv2 in previous commit
John W. Eaton <jwe@octave.org>
parents:
10367
diff
changeset
|
45 conv2 (MArray<float>&, MArray<float>&, MArray<float>&, Shape); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
46 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
47 extern MArray<FloatComplex> |
10368
d2849dbcc858
undo unintended changes to conv2 in previous commit
John W. Eaton <jwe@octave.org>
parents:
10367
diff
changeset
|
48 conv2 (MArray<FloatComplex>&, MArray<FloatComplex>&, MArray<FloatComplex>&, Shape); |
5819 | 49 #endif |
50 | |
51 template <class T> | |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
52 MArray<T> |
10368
d2849dbcc858
undo unintended changes to conv2 in previous commit
John W. Eaton <jwe@octave.org>
parents:
10367
diff
changeset
|
53 conv2 (MArray<T>& R, MArray<T>& C, MArray<T>& A, Shape ishape) |
5819 | 54 { |
10368
d2849dbcc858
undo unintended changes to conv2 in previous commit
John W. Eaton <jwe@octave.org>
parents:
10367
diff
changeset
|
55 octave_idx_type Rn = R.length (); |
d2849dbcc858
undo unintended changes to conv2 in previous commit
John W. Eaton <jwe@octave.org>
parents:
10367
diff
changeset
|
56 octave_idx_type Cm = C.length (); |
5819 | 57 octave_idx_type Am = A.rows (); |
58 octave_idx_type An = A.columns (); | |
59 | |
60 // Calculate the size of the output matrix: | |
61 // in order to stay Matlab compatible, it is based | |
62 // on the third parameter if it's separable, and the | |
63 // first if it's not | |
64 | |
65 octave_idx_type outM = 0; | |
66 octave_idx_type outN = 0; | |
67 octave_idx_type edgM = 0; | |
68 octave_idx_type edgN = 0; | |
69 | |
70 switch (ishape) | |
71 { | |
72 case SHAPE_FULL: | |
73 outM = Am + Cm - 1; | |
74 outN = An + Rn - 1; | |
75 edgM = Cm - 1; | |
76 edgN = Rn - 1; | |
77 break; | |
78 | |
79 case SHAPE_SAME: | |
80 outM = Am; | |
81 outN = An; | |
82 // Follow the Matlab convention (ie + instead of -) | |
83 edgM = (Cm - 1) /2; | |
84 edgN = (Rn - 1) /2; | |
85 break; | |
86 | |
87 case SHAPE_VALID: | |
88 outM = Am - Cm + 1; | |
89 outN = An - Rn + 1; | |
90 if (outM < 0) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
91 outM = 0; |
5819 | 92 if (outN < 0) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
93 outN = 0; |
5819 | 94 edgM = edgN = 0; |
95 break; | |
96 | |
97 default: | |
98 error ("conv2: invalid value of parameter ishape"); | |
99 } | |
100 | |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
101 MArray<T> O (outM, outN); |
5819 | 102 |
103 // X accumulates the 1-D conv for each row, before calculating | |
104 // the convolution in the other direction | |
105 // There is no efficiency advantage to doing it in either direction | |
106 // first | |
107 | |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
108 MArray<T> X (An, 1); |
5819 | 109 |
110 for (octave_idx_type oi = 0; oi < outM; oi++) | |
111 { | |
112 for (octave_idx_type oj = 0; oj < An; oj++) | |
113 { | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
114 T sum = 0; |
5819 | 115 |
10368
d2849dbcc858
undo unintended changes to conv2 in previous commit
John W. Eaton <jwe@octave.org>
parents:
10367
diff
changeset
|
116 octave_idx_type ci = Cm - 1 - MAX(0, edgM-oi); |
d2849dbcc858
undo unintended changes to conv2 in previous commit
John W. Eaton <jwe@octave.org>
parents:
10367
diff
changeset
|
117 octave_idx_type ai = MAX(0, oi-edgM); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
118 const T* Ad = A.data() + ai + Am*oj; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
119 const T* Cd = C.data() + ci; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
120 for ( ; ci >= 0 && ai < Am; ci--, Cd--, ai++, Ad++) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
121 sum += (*Ad) * (*Cd); |
5819 | 122 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
123 X(oj) = sum; |
5819 | 124 } |
125 | |
126 for (octave_idx_type oj = 0; oj < outN; oj++) | |
127 { | |
128 T sum = 0; | |
129 | |
10368
d2849dbcc858
undo unintended changes to conv2 in previous commit
John W. Eaton <jwe@octave.org>
parents:
10367
diff
changeset
|
130 octave_idx_type rj = Rn - 1 - MAX(0, edgN-oj); |
d2849dbcc858
undo unintended changes to conv2 in previous commit
John W. Eaton <jwe@octave.org>
parents:
10367
diff
changeset
|
131 octave_idx_type aj = MAX(0, oj-edgN) ; |
5819 | 132 const T* Xd = X.data() + aj; |
133 const T* Rd = R.data() + rj; | |
134 | |
135 for ( ; rj >= 0 && aj < An; rj--, Rd--, aj++, Xd++) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
136 sum += (*Xd) * (*Rd); |
5819 | 137 |
10368
d2849dbcc858
undo unintended changes to conv2 in previous commit
John W. Eaton <jwe@octave.org>
parents:
10367
diff
changeset
|
138 O(oi,oj)= sum; |
5819 | 139 } |
140 } | |
141 | |
142 return O; | |
143 } | |
144 | |
145 #if !defined (CXX_NEW_FRIEND_TEMPLATE_DECL) | |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
146 extern MArray<double> |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
147 conv2 (MArray<double>&, MArray<double>&, Shape); |
5819 | 148 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
149 extern MArray<Complex> |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
150 conv2 (MArray<Complex>&, MArray<Complex>&, Shape); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
151 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
152 extern MArray<float> |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
153 conv2 (MArray<float>&, MArray<float>&, Shape); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
154 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
155 extern MArray<FloatComplex> |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
156 conv2 (MArray<FloatComplex>&, MArray<FloatComplex>&, Shape); |
5819 | 157 #endif |
158 | |
159 template <class T> | |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
160 MArray<T> |
10368
d2849dbcc858
undo unintended changes to conv2 in previous commit
John W. Eaton <jwe@octave.org>
parents:
10367
diff
changeset
|
161 conv2 (MArray<T>&A, MArray<T>&B, Shape ishape) |
5819 | 162 { |
163 // Convolution works fastest if we choose the A matrix to be | |
164 // the largest. | |
165 | |
166 // Here we calculate the size of the output matrix, | |
167 // in order to stay Matlab compatible, it is based | |
168 // on the third parameter if it's separable, and the | |
169 // first if it's not | |
170 | |
171 // NOTE in order to be Matlab compatible, we give argueably | |
172 // wrong sizes for 'valid' if the smallest matrix is first | |
173 | |
174 octave_idx_type Am = A.rows (); | |
175 octave_idx_type An = A.columns (); | |
176 octave_idx_type Bm = B.rows (); | |
177 octave_idx_type Bn = B.columns (); | |
178 | |
179 octave_idx_type outM = 0; | |
180 octave_idx_type outN = 0; | |
181 octave_idx_type edgM = 0; | |
182 octave_idx_type edgN = 0; | |
183 | |
184 switch (ishape) | |
185 { | |
186 case SHAPE_FULL: | |
187 outM = Am + Bm - 1; | |
188 outN = An + Bn - 1; | |
189 edgM = Bm - 1; | |
190 edgN = Bn - 1; | |
191 break; | |
192 | |
193 case SHAPE_SAME: | |
194 outM = Am; | |
195 outN = An; | |
196 edgM = (Bm - 1) /2; | |
197 edgN = (Bn - 1) /2; | |
198 break; | |
199 | |
200 case SHAPE_VALID: | |
201 outM = Am - Bm + 1; | |
202 outN = An - Bn + 1; | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
203 if (outM < 0) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
204 outM = 0; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
205 if (outN < 0) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
206 outN = 0; |
5819 | 207 edgM = edgN = 0; |
208 break; | |
209 } | |
210 | |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
211 MArray<T> O (outM, outN); |
5819 | 212 |
10368
d2849dbcc858
undo unintended changes to conv2 in previous commit
John W. Eaton <jwe@octave.org>
parents:
10367
diff
changeset
|
213 for (octave_idx_type oi = 0; oi < outM; oi++) |
5819 | 214 { |
10368
d2849dbcc858
undo unintended changes to conv2 in previous commit
John W. Eaton <jwe@octave.org>
parents:
10367
diff
changeset
|
215 for (octave_idx_type oj = 0; oj < outN; oj++) |
5819 | 216 { |
217 T sum = 0; | |
218 | |
10368
d2849dbcc858
undo unintended changes to conv2 in previous commit
John W. Eaton <jwe@octave.org>
parents:
10367
diff
changeset
|
219 for (octave_idx_type bj = Bn - 1 - MAX (0, edgN-oj), aj= MAX (0, oj-edgN); |
d2849dbcc858
undo unintended changes to conv2 in previous commit
John W. Eaton <jwe@octave.org>
parents:
10367
diff
changeset
|
220 bj >= 0 && aj < An; bj--, aj++) |
5819 | 221 { |
10368
d2849dbcc858
undo unintended changes to conv2 in previous commit
John W. Eaton <jwe@octave.org>
parents:
10367
diff
changeset
|
222 octave_idx_type bi = Bm - 1 - MAX (0, edgM-oi); |
d2849dbcc858
undo unintended changes to conv2 in previous commit
John W. Eaton <jwe@octave.org>
parents:
10367
diff
changeset
|
223 octave_idx_type ai = MAX (0, oi-edgM); |
d2849dbcc858
undo unintended changes to conv2 in previous commit
John W. Eaton <jwe@octave.org>
parents:
10367
diff
changeset
|
224 const T* Ad = A.data () + ai + Am*aj; |
d2849dbcc858
undo unintended changes to conv2 in previous commit
John W. Eaton <jwe@octave.org>
parents:
10367
diff
changeset
|
225 const T* Bd = B.data () + bi + Bm*bj; |
5819 | 226 |
10368
d2849dbcc858
undo unintended changes to conv2 in previous commit
John W. Eaton <jwe@octave.org>
parents:
10367
diff
changeset
|
227 for ( ; bi >= 0 && ai < Am; bi--, Bd--, ai++, Ad++) |
5819 | 228 { |
10368
d2849dbcc858
undo unintended changes to conv2 in previous commit
John W. Eaton <jwe@octave.org>
parents:
10367
diff
changeset
|
229 sum += (*Ad) * (*Bd); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
230 // Comment: it seems to be 2.5 x faster than this: |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
231 // sum+= A(ai,aj) * B(bi,bj); |
5819 | 232 } |
233 } | |
234 | |
10368
d2849dbcc858
undo unintended changes to conv2 in previous commit
John W. Eaton <jwe@octave.org>
parents:
10367
diff
changeset
|
235 O(oi,oj) = sum; |
5819 | 236 } |
237 } | |
238 | |
239 return O; | |
240 } | |
241 | |
242 /* | |
243 %!test | |
244 %! b = [0,1,2,3;1,8,12,12;4,20,24,21;7,22,25,18]; | |
245 %! assert(conv2([0,1;1,2],[1,2,3;4,5,6;7,8,9]),b); | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
246 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
247 %!test |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
248 %! b = single([0,1,2,3;1,8,12,12;4,20,24,21;7,22,25,18]); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
249 %! assert(conv2(single([0,1;1,2]),single([1,2,3;4,5,6;7,8,9])),b); |
5819 | 250 */ |
251 | |
252 DEFUN_DLD (conv2, args, , | |
253 "-*- texinfo -*-\n\ | |
254 @deftypefn {Loadable Function} {y =} conv2 (@var{a}, @var{b}, @var{shape})\n\ | |
255 @deftypefnx {Loadable Function} {y =} conv2 (@var{v1}, @var{v2}, @var{M}, @var{shape})\n\ | |
256 \n\ | |
257 Returns 2D convolution of @var{a} and @var{b} where the size\n\ | |
258 of @var{c} is given by\n\ | |
259 \n\ | |
260 @table @asis\n\ | |
10368
d2849dbcc858
undo unintended changes to conv2 in previous commit
John W. Eaton <jwe@octave.org>
parents:
10367
diff
changeset
|
261 @item @var{shape}= 'full'\n\ |
5819 | 262 returns full 2-D convolution\n\ |
10368
d2849dbcc858
undo unintended changes to conv2 in previous commit
John W. Eaton <jwe@octave.org>
parents:
10367
diff
changeset
|
263 @item @var{shape}= 'same'\n\ |
5819 | 264 same size as a. 'central' part of convolution\n\ |
10368
d2849dbcc858
undo unintended changes to conv2 in previous commit
John W. Eaton <jwe@octave.org>
parents:
10367
diff
changeset
|
265 @item @var{shape}= 'valid'\n\ |
5819 | 266 only parts which do not include zero-padded edges\n\ |
267 @end table\n\ | |
268 \n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
269 By default @var{shape} is 'full'. When the third argument is a matrix\n\ |
5819 | 270 returns the convolution of the matrix @var{M} by the vector @var{v1}\n\ |
271 in the column direction and by vector @var{v2} in the row direction\n\ | |
272 @end deftypefn") | |
273 { | |
274 octave_value retval; | |
275 octave_value tmp; | |
276 int nargin = args.length (); | |
10368
d2849dbcc858
undo unintended changes to conv2 in previous commit
John W. Eaton <jwe@octave.org>
parents:
10367
diff
changeset
|
277 std::string shape= "full"; //default |
d2849dbcc858
undo unintended changes to conv2 in previous commit
John W. Eaton <jwe@octave.org>
parents:
10367
diff
changeset
|
278 bool separable= false; |
5819 | 279 Shape ishape; |
280 | |
281 if (nargin < 2) | |
282 { | |
5823 | 283 print_usage (); |
5819 | 284 return retval; |
285 } | |
286 else if (nargin == 3) | |
287 { | |
5822 | 288 if (args(2).is_string ()) |
5819 | 289 shape = args(2).string_value (); |
290 else | |
291 separable = true; | |
292 } | |
293 else if (nargin >= 4) | |
294 { | |
295 separable = true; | |
296 shape = args(3).string_value (); | |
297 } | |
298 | |
299 if (shape == "full") | |
300 ishape = SHAPE_FULL; | |
301 else if (shape == "same") | |
302 ishape = SHAPE_SAME; | |
303 else if (shape == "valid") | |
304 ishape = SHAPE_VALID; | |
305 else | |
306 { | |
5822 | 307 error ("conv2: shape type not valid"); |
5823 | 308 print_usage (); |
5819 | 309 return retval; |
310 } | |
311 | |
312 if (separable) | |
313 { | |
314 // If user requests separable, check first two params are vectors | |
315 | |
316 if (! (1 == args(0).rows () || 1 == args(0).columns ()) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
317 || ! (1 == args(1).rows () || 1 == args(1).columns ())) |
5819 | 318 { |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
319 print_usage (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
320 return retval; |
5819 | 321 } |
322 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
323 if (args(0).is_single_type () || |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
324 args(1).is_single_type () || |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
325 args(2).is_single_type ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
326 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
327 if (args(0).is_complex_type () |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
328 || args(1).is_complex_type () |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
329 || args(2).is_complex_type ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
330 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
331 FloatComplexColumnVector v1 (args(0).float_complex_vector_value ()); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
332 FloatComplexColumnVector v2 (args(1).float_complex_vector_value ()); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
333 FloatComplexMatrix a (args(2).float_complex_matrix_value ()); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
334 FloatComplexMatrix c (conv2 (v1, v2, a, ishape)); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
335 if (! error_state) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
336 retval = c; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
337 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
338 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
339 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
340 FloatColumnVector v1 (args(0).float_vector_value ()); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
341 FloatColumnVector v2 (args(1).float_vector_value ()); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
342 FloatMatrix a (args(2).float_matrix_value ()); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
343 FloatMatrix c (conv2 (v1, v2, a, ishape)); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
344 if (! error_state) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
345 retval = c; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
346 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
347 } |
5819 | 348 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
349 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
350 if (args(0).is_complex_type () |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
351 || args(1).is_complex_type () |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
352 || args(2).is_complex_type ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
353 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
354 ComplexColumnVector v1 (args(0).complex_vector_value ()); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
355 ComplexColumnVector v2 (args(1).complex_vector_value ()); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
356 ComplexMatrix a (args(2).complex_matrix_value ()); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
357 ComplexMatrix c (conv2 (v1, v2, a, ishape)); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
358 if (! error_state) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
359 retval = c; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
360 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
361 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
362 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
363 ColumnVector v1 (args(0).vector_value ()); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
364 ColumnVector v2 (args(1).vector_value ()); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
365 Matrix a (args(2).matrix_value ()); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
366 Matrix c (conv2 (v1, v2, a, ishape)); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
367 if (! error_state) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
368 retval = c; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
369 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
370 } |
5819 | 371 } // if (separable) |
372 else | |
373 { | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
374 if (args(0).is_single_type () || |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
375 args(1).is_single_type ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
376 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
377 if (args(0).is_complex_type () |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
378 || args(1).is_complex_type ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
379 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
380 FloatComplexMatrix a (args(0).float_complex_matrix_value ()); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
381 FloatComplexMatrix b (args(1).float_complex_matrix_value ()); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
382 FloatComplexMatrix c (conv2 (a, b, ishape)); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
383 if (! error_state) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
384 retval = c; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
385 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
386 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
387 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
388 FloatMatrix a (args(0).float_matrix_value ()); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
389 FloatMatrix b (args(1).float_matrix_value ()); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
390 FloatMatrix c (conv2 (a, b, ishape)); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
391 if (! error_state) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
392 retval = c; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
393 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
394 } |
5819 | 395 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
396 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
397 if (args(0).is_complex_type () |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
398 || args(1).is_complex_type ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
399 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
400 ComplexMatrix a (args(0).complex_matrix_value ()); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
401 ComplexMatrix b (args(1).complex_matrix_value ()); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
402 ComplexMatrix c (conv2 (a, b, ishape)); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
403 if (! error_state) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
404 retval = c; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
405 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
406 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
407 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
408 Matrix a (args(0).matrix_value ()); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
409 Matrix b (args(1).matrix_value ()); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
410 Matrix c (conv2 (a, b, ishape)); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
411 if (! error_state) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
412 retval = c; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
413 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
414 } |
5819 | 415 |
416 } // if (separable) | |
417 | |
418 return retval; | |
419 } | |
420 | |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
421 template MArray<double> |
10368
d2849dbcc858
undo unintended changes to conv2 in previous commit
John W. Eaton <jwe@octave.org>
parents:
10367
diff
changeset
|
422 conv2 (MArray<double>&, MArray<double>&, MArray<double>&, Shape); |
5819 | 423 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
424 template MArray<double> |
10368
d2849dbcc858
undo unintended changes to conv2 in previous commit
John W. Eaton <jwe@octave.org>
parents:
10367
diff
changeset
|
425 conv2 (MArray<double>&, MArray<double>&, Shape); |
5819 | 426 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
427 template MArray<Complex> |
10368
d2849dbcc858
undo unintended changes to conv2 in previous commit
John W. Eaton <jwe@octave.org>
parents:
10367
diff
changeset
|
428 conv2 (MArray<Complex>&, MArray<Complex>&, MArray<Complex>&, Shape); |
5819 | 429 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
430 template MArray<Complex> |
10368
d2849dbcc858
undo unintended changes to conv2 in previous commit
John W. Eaton <jwe@octave.org>
parents:
10367
diff
changeset
|
431 conv2 (MArray<Complex>&, MArray<Complex>&, Shape); |