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