annotate src/DLD-FUNCTIONS/conv2.cc @ 14501:60e5cf354d80

Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions. * __contourc__.cc, __delaunayn__.cc, __dispatch__.cc, __dsearchn__.cc, __fltk_uigetfile__.cc, __glpk__.cc, __lin_interpn__.cc, __magick_read__.cc, __pchip_deriv__.cc, __qp__.cc, __voronoi__.cc, besselj.cc, betainc.cc, bsxfun.cc, cellfun.cc, chol.cc, conv2.cc, convhulln.cc, dassl.cc, det.cc, dlmread.cc, dmperm.cc, dot.cc, eig.cc, eigs.cc, fft.cc, fft2.cc, filter.cc, find.cc, gammainc.cc, gcd.cc, givens.cc, hess.cc, hex2num.cc, inv.cc, kron.cc, lookup.cc, lsode.cc, lu.cc, luinc.cc, matrix_type.cc, max.cc, mgorth.cc, nproc.cc, qr.cc, quad.cc, quadcc.cc, qz.cc, rand.cc, rcond.cc, regexp.cc, schur.cc, spparms.cc, sqrtm.cc, str2double.cc, strfind.cc, sub2ind.cc, svd.cc, syl.cc, time.cc, tril.cc, tsearch.cc: Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
author Rik <octave@nomad.inbox5.com>
date Tue, 27 Mar 2012 22:46:45 -0700
parents 846273dae16b
children 34f067bcac12
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5819
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
1 /*
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
2
14138
72c96de7a403 maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents: 13219
diff changeset
3 Copyright (C) 1999-2012 Andy Adler
10498
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10384
diff changeset
4 Copyright (C) 2010 VZLU Prague
5819
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
5
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
6 This file is part of Octave.
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
7
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
8 Octave is free software; you can redistribute it and/or modify it
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
9 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5823
diff changeset
10 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5823
diff changeset
11 option) any later version.
5819
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
12
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
13 Octave is distributed in the hope that it will be useful, but WITHOUT
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
16 for more details.
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
17
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5823
diff changeset
19 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5823
diff changeset
20 <http://www.gnu.org/licenses/>.
5819
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
21
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
22 */
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
23
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
24 #ifdef HAVE_CONFIG_H
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
25 #include <config.h>
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
26 #endif
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
27
10384
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
28 #include "oct-convn.h"
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
29
5819
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
30 #include "defun-dld.h"
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
31 #include "error.h"
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
32 #include "oct-obj.h"
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
33 #include "utils.h"
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
34
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
35 enum Shape { SHAPE_FULL, SHAPE_SAME, SHAPE_VALID };
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
36
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
37 DEFUN_DLD (conv2, args, ,
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
38 "-*- texinfo -*-\n\
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
39 @deftypefn {Loadable Function} {} conv2 (@var{A}, @var{B})\n\
11085
2beacd515e09 Update docstrings for convolution family of functions (conv, conv2, fftconv)
Rik <octave@nomad.inbox5.com>
parents: 11083
diff changeset
40 @deftypefnx {Loadable Function} {} conv2 (@var{v1}, @var{v2}, @var{m})\n\
2beacd515e09 Update docstrings for convolution family of functions (conv, conv2, fftconv)
Rik <octave@nomad.inbox5.com>
parents: 11083
diff changeset
41 @deftypefnx {Loadable Function} {} conv2 (@dots{}, @var{shape})\n\
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
42 Return the 2-D convolution of @var{A} and @var{B}. The size of the result\n\
11085
2beacd515e09 Update docstrings for convolution family of functions (conv, conv2, fftconv)
Rik <octave@nomad.inbox5.com>
parents: 11083
diff changeset
43 is determined by the optional @var{shape} argument which takes the following\n\
2beacd515e09 Update docstrings for convolution family of functions (conv, conv2, fftconv)
Rik <octave@nomad.inbox5.com>
parents: 11083
diff changeset
44 values\n\
5819
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
45 \n\
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
46 @table @asis\n\
11083
bb8bf77f2242 conv2.cc: style fixes; update docstrings
John W. Eaton <jwe@octave.org>
parents: 10840
diff changeset
47 @item @var{shape} = \"full\"\n\
11085
2beacd515e09 Update docstrings for convolution family of functions (conv, conv2, fftconv)
Rik <octave@nomad.inbox5.com>
parents: 11083
diff changeset
48 Return the full convolution. (default)\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10498
diff changeset
49 \n\
11083
bb8bf77f2242 conv2.cc: style fixes; update docstrings
John W. Eaton <jwe@octave.org>
parents: 10840
diff changeset
50 @item @var{shape} = \"same\"\n\
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
51 Return the central part of the convolution with the same size as @var{A}.\n\
14209
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
52 The central part of the convolution begins at the indices\n\
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
53 @code{floor ([size(@var{B})/2] + 1)}.\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10498
diff changeset
54 \n\
11083
bb8bf77f2242 conv2.cc: style fixes; update docstrings
John W. Eaton <jwe@octave.org>
parents: 10840
diff changeset
55 @item @var{shape} = \"valid\"\n\
bb8bf77f2242 conv2.cc: style fixes; update docstrings
John W. Eaton <jwe@octave.org>
parents: 10840
diff changeset
56 Return only the parts which do not include zero-padded edges.\n\
14209
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
57 The size of the result is @code{max (size (A) - size (B) + 1, 0)}.\n\
5819
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
58 @end table\n\
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
59 \n\
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
60 When the third argument is a matrix, return the convolution of the matrix\n\
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
61 @var{m} by the vector @var{v1} in the column direction and by the vector\n\
14209
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
62 @var{v2} in the row direction.\n\
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
63 @seealso{conv, convn}\n\
5819
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
64 @end deftypefn")
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
65 {
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
66 octave_value retval;
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
67 octave_value tmp;
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
68 int nargin = args.length ();
14209
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
69 std::string shape = "full"; // default
10371
dc8637fd7a76 improve conv2 performance
John W. Eaton <jwe@octave.org>
parents: 10368
diff changeset
70 bool separable = false;
10384
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
71 convn_type ct;
5819
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
72
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
73 if (nargin < 2)
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
74 {
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5822
diff changeset
75 print_usage ();
5819
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
76 return retval;
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
77 }
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
78 else if (nargin == 3)
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
79 {
5822
4fdc2515ebad [project @ 2006-05-18 19:31:36 by jwe]
jwe
parents: 5819
diff changeset
80 if (args(2).is_string ())
5819
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
81 shape = args(2).string_value ();
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
82 else
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
83 separable = true;
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
84 }
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
85 else if (nargin >= 4)
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
86 {
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
87 separable = true;
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
88 shape = args(3).string_value ();
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
89 }
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
90
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
91 if (shape == "full")
10384
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
92 ct = convn_full;
5819
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
93 else if (shape == "same")
10384
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
94 ct = convn_same;
5819
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
95 else if (shape == "valid")
10384
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
96 ct = convn_valid;
5819
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
97 else
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
98 {
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
99 error ("conv2: SHAPE type not valid");
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5822
diff changeset
100 print_usage ();
5819
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
101 return retval;
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
102 }
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
103
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
104 if (separable)
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
105 {
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
106 // If user requests separable, check first two params are vectors
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
107
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
108 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
109 || ! (1 == args(1).rows () || 1 == args(1).columns ()))
5819
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
110 {
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
111 print_usage ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
112 return retval;
5819
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
113 }
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
114
11083
bb8bf77f2242 conv2.cc: style fixes; update docstrings
John W. Eaton <jwe@octave.org>
parents: 10840
diff changeset
115 if (args(0).is_single_type () || args(1).is_single_type ()
bb8bf77f2242 conv2.cc: style fixes; update docstrings
John W. Eaton <jwe@octave.org>
parents: 10840
diff changeset
116 || args(2).is_single_type ())
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
117 {
11083
bb8bf77f2242 conv2.cc: style fixes; update docstrings
John W. Eaton <jwe@octave.org>
parents: 10840
diff changeset
118 if (args(0).is_complex_type () || args(1).is_complex_type ()
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
119 || args(2).is_complex_type ())
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
120 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
121 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
122 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
123 {
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
124 FloatColumnVector v1 (args(0).float_vector_value ());
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
125 FloatRowVector v2 (args(1).float_vector_value ());
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
126 retval = convn (a, v1, v2, ct);
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
127 }
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
128 else
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
129 {
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
130 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
131 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
132 retval = convn (a, v1, v2, ct);
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
133 }
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
134 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
135 else
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
136 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
137 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
138 FloatRowVector v2 (args(1).float_vector_value ());
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
139 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
140 retval = convn (a, v1, v2, ct);
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
141 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
142 }
5819
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
143 else
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
144 {
11083
bb8bf77f2242 conv2.cc: style fixes; update docstrings
John W. Eaton <jwe@octave.org>
parents: 10840
diff changeset
145 if (args(0).is_complex_type () || args(1).is_complex_type ()
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
146 || args(2).is_complex_type ())
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
147 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
148 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
149 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
150 {
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
151 ColumnVector v1 (args(0).vector_value ());
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
152 RowVector v2 (args(1).vector_value ());
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
153 retval = convn (a, v1, v2, ct);
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
154 }
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
155 else
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
156 {
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
157 ComplexColumnVector v1 (args(0).complex_vector_value ());
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
158 ComplexRowVector v2 (args(1).complex_vector_value ());
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
159 retval = convn (a, v1, v2, ct);
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
160 }
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
161 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
162 else
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
163 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
164 ColumnVector v1 (args(0).vector_value ());
10384
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
165 RowVector v2 (args(1).vector_value ());
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
166 Matrix a (args(2).matrix_value ());
10384
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
167 retval = convn (a, v1, v2, ct);
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
168 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
169 }
5819
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
170 } // if (separable)
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
171 else
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
172 {
11083
bb8bf77f2242 conv2.cc: style fixes; update docstrings
John W. Eaton <jwe@octave.org>
parents: 10840
diff changeset
173 if (args(0).is_single_type () || args(1).is_single_type ())
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
174 {
11083
bb8bf77f2242 conv2.cc: style fixes; update docstrings
John W. Eaton <jwe@octave.org>
parents: 10840
diff changeset
175 if (args(0).is_complex_type () || args(1).is_complex_type ())
10154
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 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
178 if (args(1).is_real_type ())
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
179 {
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
180 FloatMatrix b (args(1).float_matrix_value ());
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
181 retval = convn (a, b, ct);
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
182 }
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
183 else
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
184 {
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
185 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
186 retval = convn (a, b, ct);
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
187 }
10154
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 else
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
190 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
191 FloatMatrix a (args(0).float_matrix_value ());
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
192 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
193 retval = convn (a, b, ct);
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
194 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
195 }
5819
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
196 else
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
197 {
11083
bb8bf77f2242 conv2.cc: style fixes; update docstrings
John W. Eaton <jwe@octave.org>
parents: 10840
diff changeset
198 if (args(0).is_complex_type () || args(1).is_complex_type ())
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
199 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
200 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
201 if (args(1).is_real_type ())
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
202 {
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
203 Matrix b (args(1).matrix_value ());
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
204 retval = convn (a, b, ct);
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
205 }
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
206 else
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
207 {
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
208 ComplexMatrix b (args(1).complex_matrix_value ());
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
209 retval = convn (a, b, ct);
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
210 }
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
211 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
212 else
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
213 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
214 Matrix a (args(0).matrix_value ());
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
215 Matrix b (args(1).matrix_value ());
10384
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
216 retval = convn (a, b, ct);
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
217 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9064
diff changeset
218 }
5819
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
219
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
220 } // if (separable)
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
221
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
222 return retval;
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
223 }
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
224
14209
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
225 /*
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
226 %!test
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
227 %! c = [0,1,2,3;1,8,12,12;4,20,24,21;7,22,25,18];
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
228 %! assert (conv2 ([0,1;1,2], [1,2,3;4,5,6;7,8,9]), c);
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
229
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
230 %!test
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
231 %! c = single ([0,1,2,3;1,8,12,12;4,20,24,21;7,22,25,18]);
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
232 %! assert (conv2 (single ([0,1;1,2]), single ([1,2,3;4,5,6;7,8,9])), c);
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
233
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
234 %!test
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
235 %! c = [1,4,4;5,18,16;14,48,40;19,62,48;15,48,36];
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
236 %! assert (conv2 (1:3, 1:2, [1,2;3,4;5,6]), c);
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
237
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
238 %!assert (conv2 (1:3, 1:2, [1,2;3,4;5,6], "full"),
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
239 %! conv2 (1:3, 1:2, [1,2;3,4;5,6]));
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
240
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
241 %% Test shapes
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
242 %!shared A, B, C
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
243 %! A = rand (3, 4);
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
244 %! B = rand (4);
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
245 %! C = conv2 (A, B);
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
246 %!assert (conv2 (A,B, "full"), C)
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
247 %!assert (conv2 (A,B, "same"), C(3:5,3:6))
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
248 %!assert (conv2 (A,B, "valid"), zeros (0, 1))
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
249 %!assert (size (conv2 (B,A, "valid")), [2 1])
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
250
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
251 %!test
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
252 %! B = rand (5);
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
253 %! C = conv2 (A, B);
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
254 %!assert (conv2 (A,B, "full"), C)
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
255 %!assert (conv2 (A,B, "same"), C(3:5,3:6))
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
256 %!assert (conv2 (A,B, "valid"), zeros (0, 0))
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
257 %!assert (size (conv2 (B,A, "valid")), [3 2])
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
258
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
259 %% Clear shared variables so they are not reported for tests below
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
260 %!shared
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
261
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
262 %% Test cases from Bug #34893
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14209
diff changeset
263 %!assert (conv2 ([1:5;1:5], [1:2], "same"), [4 7 10 13 10; 4 7 10 13 10])
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14209
diff changeset
264 %!assert (conv2 ([1:5;1:5]', [1:2]', "same"), [4 7 10 13 10; 4 7 10 13 10]')
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14209
diff changeset
265 %!#assert (conv2 ([1:5;1:5], [1:2], "valid"), [4 7 10 13; 4 7 10 13])
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14209
diff changeset
266 %!assert (conv2 ([1:5;1:5]', [1:2]', "valid"), [4 7 10 13; 4 7 10 13]')
14209
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
267
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
268 %% Test input validation
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
269 %!error conv2 ()
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
270 %!error conv2 (1)
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
271 %!error <SHAPE type not valid> conv2 (1,2, "NOT_A_SHAPE")
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
272 %% Test alternate calling form which should be 2 vectors and a matrix
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
273 %!error conv2 (ones (2), 1, 1)
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
274 %!error conv2 (1, ones (2), 1)
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
275 */
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
276
10384
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
277 DEFUN_DLD (convn, args, ,
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
278 "-*- texinfo -*-\n\
14209
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
279 @deftypefn {Loadable Function} {@var{C} =} convn (@var{A}, @var{B})\n\
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
280 @deftypefnx {Loadable Function} {@var{C} =} convn (@var{A}, @var{B}, @var{shape})\n\
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
281 Return the n-D convolution of @var{A} and @var{B}. The size of the result\n\
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
282 is determined by the optional @var{shape} argument which takes the following\n\
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
283 values\n\
10384
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
284 \n\
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
285 @table @asis\n\
11083
bb8bf77f2242 conv2.cc: style fixes; update docstrings
John W. Eaton <jwe@octave.org>
parents: 10840
diff changeset
286 @item @var{shape} = \"full\"\n\
14209
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
287 Return the full convolution. (default)\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10498
diff changeset
288 \n\
11083
bb8bf77f2242 conv2.cc: style fixes; update docstrings
John W. Eaton <jwe@octave.org>
parents: 10840
diff changeset
289 @item @var{shape} = \"same\"\n\
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
290 Return central part of the convolution with the same size as @var{A}.\n\
14209
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
291 The central part of the convolution begins at the indices\n\
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
292 @code{floor ([size(@var{B})/2] + 1)}.\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10498
diff changeset
293 \n\
11083
bb8bf77f2242 conv2.cc: style fixes; update docstrings
John W. Eaton <jwe@octave.org>
parents: 10840
diff changeset
294 @item @var{shape} = \"valid\"\n\
bb8bf77f2242 conv2.cc: style fixes; update docstrings
John W. Eaton <jwe@octave.org>
parents: 10840
diff changeset
295 Return only the parts which do not include zero-padded edges.\n\
14209
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
296 The size of the result is @code{max (size (A) - size (B) + 1, 0)}.\n\
10384
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
297 @end table\n\
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
298 \n\
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
299 @seealso{conv2, conv}\n\
10384
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
300 @end deftypefn")
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
301 {
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
302 octave_value retval;
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
303 octave_value tmp;
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
304 int nargin = args.length ();
14209
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
305 std::string shape = "full"; // default
10384
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
306 convn_type ct;
5819
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
307
10384
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
308 if (nargin < 2 || nargin > 3)
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
309 {
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
310 print_usage ();
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
311 return retval;
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 if (nargin == 3)
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 if (args(2).is_string ())
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
316 shape = args(2).string_value ();
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
317 }
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 if (shape == "full")
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
320 ct = convn_full;
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
321 else if (shape == "same")
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
322 ct = convn_same;
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
323 else if (shape == "valid")
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
324 ct = convn_valid;
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
325 else
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
326 {
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
327 error ("convn: SHAPE type not valid");
10384
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
328 print_usage ();
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
329 return retval;
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
330 }
5819
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
331
11083
bb8bf77f2242 conv2.cc: style fixes; update docstrings
John W. Eaton <jwe@octave.org>
parents: 10840
diff changeset
332 if (args(0).is_single_type () || args(1).is_single_type ())
10384
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
333 {
11083
bb8bf77f2242 conv2.cc: style fixes; update docstrings
John W. Eaton <jwe@octave.org>
parents: 10840
diff changeset
334 if (args(0).is_complex_type () || args(1).is_complex_type ())
10384
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 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
337 if (args(1).is_real_type ())
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 FloatNDArray b (args(1).float_array_value ());
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
340 retval = convn (a, b, ct);
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
341 }
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
342 else
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
343 {
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
344 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
345 retval = convn (a, b, ct);
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
346 }
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
347 }
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
348 else
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
349 {
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
350 FloatNDArray a (args(0).float_array_value ());
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
351 FloatNDArray b (args(1).float_array_value ());
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
352 retval = convn (a, b, ct);
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
353 }
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
354 }
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
355 else
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
356 {
11083
bb8bf77f2242 conv2.cc: style fixes; update docstrings
John W. Eaton <jwe@octave.org>
parents: 10840
diff changeset
357 if (args(0).is_complex_type () || args(1).is_complex_type ())
10384
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
358 {
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
359 ComplexNDArray a (args(0).complex_array_value ());
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
360 if (args(1).is_real_type ())
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
361 {
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
362 NDArray b (args(1).array_value ());
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
363 retval = convn (a, b, ct);
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
364 }
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
365 else
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
366 {
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
367 ComplexNDArray b (args(1).complex_array_value ());
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
368 retval = convn (a, b, ct);
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
369 }
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
370 }
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
371 else
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
372 {
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
373 NDArray a (args(0).array_value ());
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
374 NDArray b (args(1).array_value ());
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
375 retval = convn (a, b, ct);
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
376 }
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
377 }
5819
e54c11df0524 [project @ 2006-05-17 20:34:52 by jwe]
jwe
parents:
diff changeset
378
10384
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
379 return retval;
978f5c94b11f initial implementation of conv2/convn in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10371
diff changeset
380 }
14209
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
381
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
382 /*
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
383 FIXME: Need tests for convn in addition to conv2.
846273dae16b Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
384 */