[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
conv.m and MATLAB incompatibility.
From: |
Robert T. Short |
Subject: |
conv.m and MATLAB incompatibility. |
Date: |
Sun, 28 Jun 2009 09:34:07 -0700 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.22) Gecko/20090606 SeaMonkey/1.1.17 |
Attached is a patch to conv.m that fixes a MATLAB incompatibility. I
also added a couple of tests.
Summarizing: if the input vectors are the same length, but one is a row
vector and the other is a column vector, the octave version returns the
correct answer but with a different orientation than MATLAB. In other
words octave will return a row vector when MATLAB returns a column
vector and octave will return a column vector when MATLAB returns a row
vector.
WARNING. APPLYING THIS PATCH COULD CAUSE SCRIPT BREAKAGE!
Scripts that depend on the row/column nature of the result will no
longer work. This might be a good reason not to apply this patch.
Folks (like me) that want MATLAB compatibility can keep this version in
their path.
Bob
# HG changeset patch
# User Robert T. Short <address@hidden>
# Date 1246206264 25200
# Node ID 9b82ea57212f14a2a93091817da49fd6f53e4318
# Parent 66eaa435bc16bf1f8c4ac797d030e9cb18fa5891
* scripts/polynomial/conv.m: Fix MATLAB incompatibility, add tests.
diff -r 66eaa435bc16 -r 9b82ea57212f scripts/ChangeLog
--- a/scripts/ChangeLog Tue Jun 02 16:57:22 2009 -0700
+++ b/scripts/ChangeLog Sun Jun 28 09:24:24 2009 -0700
@@ -1,3 +1,7 @@
+2009-06-28 Robert T. Short <address@hidden>
+
+ * polynomial/conv.m: Fix MATLAB incompatibility, add tests.
+
2009-06-25 Ben Abbott <address@hidden>
* plot/gnuplot_drawnow.m: Apply feature 'wxt_has_size'.
diff -r 66eaa435bc16 -r 9b82ea57212f scripts/polynomial/conv.m
--- a/scripts/polynomial/conv.m Tue Jun 02 16:57:22 2009 -0700
+++ b/scripts/polynomial/conv.m Sun Jun 28 09:24:24 2009 -0700
@@ -49,7 +49,7 @@
## Use the shortest vector as the coefficent vector to filter.
## Preserve the row/column orientation of the longer input.
- if (la < lb)
+ if (la <= lb)
if (ly > lb)
if (size (b, 1) <= size (b, 2))
x = [b, (zeros (1, ly - lb))];
@@ -75,47 +75,40 @@
endfunction
-%!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])));
-
-%!assert(all (all (conv (3, [1, 2, 3]) == [3, 6, 9])));
-
-%!error conv ([1, 2; 3, 4], 3);
-
-%!assert(conv (2, 3),6);
-
-%!error conv (2, []);
+%!test
+%!shared a, b, c, x
+%! x = ones(3,1);
+%! y = ones(1,3);
+%! b = 2;
+%! c = 3;
+%! assert(all (conv (x,x) == [1; 2; 3; 2; 1]));
+%! assert(all (conv (y,y) == [1, 2, 3, 2, 1]));
+%! assert(all (conv (x,y) == [1, 2, 3, 2, 1])); % MATLAB
+%! assert(all (conv (y,x) == [1; 2; 3; 2; 1]));
+%% assert(all (conv (x,y) == [1; 2; 3; 2; 1])); % octave
+%% assert(all (conv (y,x) == [1, 2, 3, 2, 1]));
+%! assert(all (conv (c,x) == [3; 3; 3]));
+%! assert(all (conv (c,y) == [3, 3, 3]));
+%! assert(all (conv (x,c) == [3; 3; 3]));
+%! assert(all (conv (y,c) == [3, 3, 3]));
+%! error conv ([1, 2; 3, 4], 3);
+%! assert(conv (b, c), 6);
+%! 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])
+%! a = 1:10;
+%! b = 1:3;
+%! assert (size(conv(a,b)), [1, numel(a)+numel(b)-1])
+%! assert (size(conv(b,a)), [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])
+%! a = (1:10).';
+%! b = 1:3;
+%! assert (size(conv(a,b)), [numel(a)+numel(b)-1, 1])
+%! assert (size(conv(b,a)), [numel(a)+numel(b)-1, 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])
-
+%! a = 1:10;
+%! b = (1:3).';
+%! assert (size(conv(a,b)), [1, numel(a)+numel(b)-1])
+%! assert (size(conv(b,a)), [1, numel(a)+numel(b)-1])
- conv.m and MATLAB incompatibility.,
Robert T. Short <=