Mercurial > octave-nkf
annotate src/DLD-FUNCTIONS/conv2.cc @ 10840:89f4d7e294cc
Grammarcheck .cc files
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sat, 31 Jul 2010 11:18:11 -0700 |
parents | 8615b55b5caf |
children | bb8bf77f2242 |
rev | line source |
---|---|
5819 | 1 /* |
2 | |
8920 | 3 Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 |
7017 | 4 Andy Adler |
10498
8615b55b5caf
fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents:
10384
diff
changeset
|
5 Copyright (C) 2010 VZLU Prague |
5819 | 6 |
7 This file is part of Octave. | |
8 | |
9 Octave is free software; you can redistribute it and/or modify it | |
10 under the terms of the GNU General Public License as published by the | |
7016 | 11 Free Software Foundation; either version 3 of the License, or (at your |
12 option) any later version. | |
5819 | 13 |
14 Octave is distributed in the hope that it will be useful, but WITHOUT | |
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
17 for more details. | |
18 | |
19 You should have received a copy of the GNU General Public License | |
7016 | 20 along with Octave; see the file COPYING. If not, see |
21 <http://www.gnu.org/licenses/>. | |
5819 | 22 |
23 */ | |
24 | |
25 #ifdef HAVE_CONFIG_H | |
26 #include <config.h> | |
27 #endif | |
28 | |
10384
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
29 #include "oct-convn.h" |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
30 |
5819 | 31 #include "defun-dld.h" |
32 #include "error.h" | |
33 #include "oct-obj.h" | |
34 #include "utils.h" | |
35 | |
36 enum Shape { SHAPE_FULL, SHAPE_SAME, SHAPE_VALID }; | |
37 | |
38 /* | |
39 %!test | |
40 %! b = [0,1,2,3;1,8,12,12;4,20,24,21;7,22,25,18]; | |
41 %! 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
|
42 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
43 %!test |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
44 %! 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
|
45 %! assert(conv2(single([0,1;1,2]),single([1,2,3;4,5,6;7,8,9])),b); |
10371 | 46 |
10384
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
47 %!assert (conv2 (1:3, 1:2, [1,2;3,4;5,6]), |
10371 | 48 %! [1,4,4;5,18,16;14,48,40;19,62,48;15,48,36;]); |
5819 | 49 */ |
50 | |
10371 | 51 |
5819 | 52 DEFUN_DLD (conv2, args, , |
53 "-*- texinfo -*-\n\ | |
10840 | 54 @deftypefn {Loadable Function} {y =} conv2 (@var{a}, @var{b}, @var{shape})\n\ |
5819 | 55 @deftypefnx {Loadable Function} {y =} conv2 (@var{v1}, @var{v2}, @var{M}, @var{shape})\n\ |
56 \n\ | |
57 Returns 2D convolution of @var{a} and @var{b} where the size\n\ | |
58 of @var{c} is given by\n\ | |
59 \n\ | |
60 @table @asis\n\ | |
10371 | 61 @item @var{shape} = 'full'\n\ |
5819 | 62 returns full 2-D convolution\n\ |
10840 | 63 \n\ |
10371 | 64 @item @var{shape} = 'same'\n\ |
5819 | 65 same size as a. 'central' part of convolution\n\ |
10840 | 66 \n\ |
10371 | 67 @item @var{shape} = 'valid'\n\ |
5819 | 68 only parts which do not include zero-padded edges\n\ |
69 @end table\n\ | |
70 \n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
71 By default @var{shape} is 'full'. When the third argument is a matrix\n\ |
5819 | 72 returns the convolution of the matrix @var{M} by the vector @var{v1}\n\ |
73 in the column direction and by vector @var{v2} in the row direction\n\ | |
74 @end deftypefn") | |
75 { | |
76 octave_value retval; | |
77 octave_value tmp; | |
78 int nargin = args.length (); | |
10371 | 79 std::string shape = "full"; //default |
80 bool separable = false; | |
10384
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
81 convn_type ct; |
5819 | 82 |
83 if (nargin < 2) | |
84 { | |
5823 | 85 print_usage (); |
5819 | 86 return retval; |
87 } | |
88 else if (nargin == 3) | |
89 { | |
5822 | 90 if (args(2).is_string ()) |
5819 | 91 shape = args(2).string_value (); |
92 else | |
93 separable = true; | |
94 } | |
95 else if (nargin >= 4) | |
96 { | |
97 separable = true; | |
98 shape = args(3).string_value (); | |
99 } | |
100 | |
101 if (shape == "full") | |
10384
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
102 ct = convn_full; |
5819 | 103 else if (shape == "same") |
10384
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
104 ct = convn_same; |
5819 | 105 else if (shape == "valid") |
10384
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
106 ct = convn_valid; |
5819 | 107 else |
108 { | |
5822 | 109 error ("conv2: shape type not valid"); |
5823 | 110 print_usage (); |
5819 | 111 return retval; |
112 } | |
113 | |
114 if (separable) | |
115 { | |
116 // If user requests separable, check first two params are vectors | |
117 | |
118 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
|
119 || ! (1 == args(1).rows () || 1 == args(1).columns ())) |
5819 | 120 { |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
121 print_usage (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
122 return retval; |
5819 | 123 } |
124 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
125 if (args(0).is_single_type () || |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
126 args(1).is_single_type () || |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
127 args(2).is_single_type ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
128 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
129 if (args(0).is_complex_type () |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
130 || args(1).is_complex_type () |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
131 || args(2).is_complex_type ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
132 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
133 FloatComplexMatrix a (args(2).float_complex_matrix_value ()); |
10384
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
134 if (args(1).is_real_type () && args(2).is_real_type ()) |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
135 { |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
136 FloatColumnVector v1 (args(0).float_vector_value ()); |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
137 FloatRowVector v2 (args(1).float_vector_value ()); |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
138 retval = convn (a, v1, v2, ct); |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
139 } |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
140 else |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
141 { |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
142 FloatComplexColumnVector v1 (args(0).float_complex_vector_value ()); |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
143 FloatComplexRowVector v2 (args(1).float_complex_vector_value ()); |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
144 retval = convn (a, v1, v2, ct); |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
145 } |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
146 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
147 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
148 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
149 FloatColumnVector v1 (args(0).float_vector_value ()); |
10384
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
150 FloatRowVector v2 (args(1).float_vector_value ()); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
151 FloatMatrix a (args(2).float_matrix_value ()); |
10384
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
152 retval = convn (a, v1, v2, ct); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
153 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
154 } |
5819 | 155 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
156 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
157 if (args(0).is_complex_type () |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
158 || args(1).is_complex_type () |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
159 || args(2).is_complex_type ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
160 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
161 ComplexMatrix a (args(2).complex_matrix_value ()); |
10384
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
162 if (args(1).is_real_type () && args(2).is_real_type ()) |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
163 { |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
164 ColumnVector v1 (args(0).vector_value ()); |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
165 RowVector v2 (args(1).vector_value ()); |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
166 retval = convn (a, v1, v2, ct); |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
167 } |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
168 else |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
169 { |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
170 ComplexColumnVector v1 (args(0).complex_vector_value ()); |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
171 ComplexRowVector v2 (args(1).complex_vector_value ()); |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
172 retval = convn (a, v1, v2, ct); |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
173 } |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
174 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
175 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
176 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
177 ColumnVector v1 (args(0).vector_value ()); |
10384
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
178 RowVector v2 (args(1).vector_value ()); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
179 Matrix a (args(2).matrix_value ()); |
10384
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
180 retval = convn (a, v1, v2, ct); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
181 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
182 } |
5819 | 183 } // if (separable) |
184 else | |
185 { | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
186 if (args(0).is_single_type () || |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
187 args(1).is_single_type ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
188 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
189 if (args(0).is_complex_type () |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
190 || args(1).is_complex_type ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
191 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
192 FloatComplexMatrix a (args(0).float_complex_matrix_value ()); |
10384
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
193 if (args(1).is_real_type ()) |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
194 { |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
195 FloatMatrix b (args(1).float_matrix_value ()); |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
196 retval = convn (a, b, ct); |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
197 } |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
198 else |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
199 { |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
200 FloatComplexMatrix b (args(1).float_complex_matrix_value ()); |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
201 retval = convn (a, b, ct); |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
202 } |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
203 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
204 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
205 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
206 FloatMatrix a (args(0).float_matrix_value ()); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
207 FloatMatrix b (args(1).float_matrix_value ()); |
10384
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
208 retval = convn (a, b, ct); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
209 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
210 } |
5819 | 211 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
212 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
213 if (args(0).is_complex_type () |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
214 || args(1).is_complex_type ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
215 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
216 ComplexMatrix a (args(0).complex_matrix_value ()); |
10384
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
217 if (args(1).is_real_type ()) |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
218 { |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
219 Matrix b (args(1).matrix_value ()); |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
220 retval = convn (a, b, ct); |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
221 } |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
222 else |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
223 { |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
224 ComplexMatrix b (args(1).complex_matrix_value ()); |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
225 retval = convn (a, b, ct); |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
226 } |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
227 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
228 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
229 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
230 Matrix a (args(0).matrix_value ()); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
231 Matrix b (args(1).matrix_value ()); |
10384
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
232 retval = convn (a, b, ct); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
233 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
234 } |
5819 | 235 |
236 } // if (separable) | |
237 | |
238 return retval; | |
239 } | |
240 | |
10384
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
241 DEFUN_DLD (convn, args, , |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
242 "-*- texinfo -*-\n\ |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
243 @deftypefn {Loadable Function} {y =} conv2 (@var{a}, @var{b}, @var{shape})\n\ |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
244 \n\ |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
245 Returns n-D convolution of @var{a} and @var{b} where the size\n\ |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
246 of @var{c} is given by\n\ |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
247 \n\ |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
248 @table @asis\n\ |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
249 @item @var{shape} = 'full'\n\ |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
250 returns full n-D convolution\n\ |
10840 | 251 \n\ |
10384
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
252 @item @var{shape} = 'same'\n\ |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
253 same size as a. 'central' part of convolution\n\ |
10840 | 254 \n\ |
10384
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
255 @item @var{shape} = 'valid'\n\ |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
256 only parts which do not include zero-padded edges\n\ |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
257 @end table\n\ |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
258 \n\ |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
259 By default @var{shape} is 'full'.\n\ |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
260 @end deftypefn") |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
261 { |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
262 octave_value retval; |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
263 octave_value tmp; |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
264 int nargin = args.length (); |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
265 std::string shape = "full"; //default |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
266 bool separable = false; |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
267 convn_type ct; |
5819 | 268 |
10384
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
269 if (nargin < 2 || nargin > 3) |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
270 { |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
271 print_usage (); |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
272 return retval; |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
273 } |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
274 else if (nargin == 3) |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
275 { |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
276 if (args(2).is_string ()) |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
277 shape = args(2).string_value (); |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
278 else |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
279 separable = true; |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
280 } |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
281 |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
282 if (shape == "full") |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
283 ct = convn_full; |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
284 else if (shape == "same") |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
285 ct = convn_same; |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
286 else if (shape == "valid") |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
287 ct = convn_valid; |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
288 else |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
289 { |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
290 error ("convn: shape type not valid"); |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
291 print_usage (); |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
292 return retval; |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
293 } |
5819 | 294 |
10384
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
295 if (args(0).is_single_type () || |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
296 args(1).is_single_type ()) |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
297 { |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
298 if (args(0).is_complex_type () |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
299 || args(1).is_complex_type ()) |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
300 { |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
301 FloatComplexNDArray a (args(0).float_complex_array_value ()); |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
302 if (args(1).is_real_type ()) |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
303 { |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
304 FloatNDArray b (args(1).float_array_value ()); |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
305 retval = convn (a, b, ct); |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
306 } |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
307 else |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
308 { |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
309 FloatComplexNDArray b (args(1).float_complex_array_value ()); |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
310 retval = convn (a, b, ct); |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
311 } |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
312 } |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
313 else |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
314 { |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
315 FloatNDArray a (args(0).float_array_value ()); |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
316 FloatNDArray b (args(1).float_array_value ()); |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
317 retval = convn (a, b, ct); |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
318 } |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
319 } |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
320 else |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
321 { |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
322 if (args(0).is_complex_type () |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
323 || args(1).is_complex_type ()) |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
324 { |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
325 ComplexNDArray a (args(0).complex_array_value ()); |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
326 if (args(1).is_real_type ()) |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
327 { |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
328 NDArray b (args(1).array_value ()); |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
329 retval = convn (a, b, ct); |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
330 } |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
331 else |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
332 { |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
333 ComplexNDArray b (args(1).complex_array_value ()); |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
334 retval = convn (a, b, ct); |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
335 } |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
336 } |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
337 else |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
338 { |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
339 NDArray a (args(0).array_value ()); |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
340 NDArray b (args(1).array_value ()); |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
341 retval = convn (a, b, ct); |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
342 } |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
343 } |
5819 | 344 |
10384
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
345 return retval; |
978f5c94b11f
initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10371
diff
changeset
|
346 } |