# HG changeset patch # User Ben Abbott # Date 1222695186 14400 # Node ID 15e4a450bf846457b52ab204e9b8e84ccbedb125 # Parent c0b8546c00202759898630af2798dc0ab55e7284 conv.m: Correct row/col orientation of output diff -r c0b8546c0020 -r 15e4a450bf84 scripts/ChangeLog --- a/scripts/ChangeLog Mon Sep 29 07:57:57 2008 +0200 +++ b/scripts/ChangeLog Mon Sep 29 09:33:06 2008 -0400 @@ -1,3 +1,7 @@ +2008-09-29 Ben Abbott + + * polynomial/conv.m: Correct row/col orientation of output. + 2008-09-26 David Bateman * general/subsindex.m: Dummy subsindex function for help string diff -r c0b8546c0020 -r 15e4a450bf84 scripts/polynomial/conv.m --- a/scripts/polynomial/conv.m Mon Sep 29 07:57:57 2008 +0200 +++ b/scripts/polynomial/conv.m Mon Sep 29 09:33:06 2008 -0400 @@ -47,25 +47,26 @@ ly = la + lb - 1; - ## Ensure that both vectors are row vectors. - if (rows (a) > 1) - a = reshape (a, 1, la); - endif - if (rows (b) > 1) - b = reshape (b, 1, lb); - endif - ## Use the shortest vector as the coefficent vector to filter. + ## Preserve the row/column orientation of the longer input. if (la < lb) if (ly > lb) - x = [b, (zeros (1, ly - lb))]; + if (size (b, 1) <= size (b, 2)) + x = [b, (zeros (1, ly - lb))]; + else + x = [b; (zeros (ly - lb, 1))]; + endif else x = b; endif y = filter (a, 1, x); else if(ly > la) - x = [a, (zeros (1, ly - la))]; + if (size (a, 1) <= size (a, 2)) + x = [a, (zeros (1, ly - la))]; + else + x = [a; (zeros (ly - la, 1))]; + endif else x = a; endif @@ -74,7 +75,7 @@ endfunction -%!assert(all (all (conv (ones (3, 1), ones (3, 1)) == [1, 2, 3, 2, 1]))); +%!assert(all (all (conv (ones (3, 1), ones (3, 1)) == [1; 2; 3; 2; 1]))); %!assert(all (all (conv (ones (1, 3), ones (3, 1)) == [1, 2, 3, 2, 1]))); @@ -86,3 +87,35 @@ %!error conv (2, []); +%!test +%! a = 1:10; +%! b = 1:3; +%! c = conv (a, b); +%! assert (size(c), [1, numel(a)+numel(b)-1]) +%!test +%! a = (1:10).'; +%! b = 1:3; +%! c = conv (a, b); +%! assert (size(c), [numel(a)+numel(b)-1, 1]) +%!test +%! a = 1:10; +%! b = (1:3).'; +%! c = conv (a, b); +%! assert (size(c), [1, numel(a)+numel(b)-1]) + +%!test +%! b = 1:10; +%! a = 1:3; +%! c = conv (a, b); +%! assert (size(c), [1, numel(a)+numel(b)-1]) +%!test +%! b = (1:10).'; +%! a = 1:3; +%! c = conv (a, b); +%! assert (size(c), [numel(a)+numel(b)-1, 1]) +%!test +%! b = 1:10; +%! a = (1:3).'; +%! c = conv (a, b); +%! assert (size(c), [1, numel(a)+numel(b)-1]) +