# HG changeset patch # User Kai T. Ohlhus # Date 1544621615 -3600 # Node ID 33913d29bed4810815aac99bdc79646ae6103cbd # Parent fc7b842daca18cbafcb7ff7ea1019c16db22926e conv.m: Simplify function and improve performance (8X) (bug #55205). * conv.m: All compuations of conv are already treated by Octaves C++ Function Fconv2, when using vectorized input. Only the shape of the orginal operands has to be restored properly. This simplification results in a performance gain by factor 7-8 for inputs with more than 10^4 elemets. diff -r fc7b842daca1 -r 33913d29bed4 scripts/polynomial/conv.m --- a/scripts/polynomial/conv.m Wed Dec 12 00:50:34 2018 -0500 +++ b/scripts/polynomial/conv.m Wed Dec 12 14:33:35 2018 +0100 @@ -61,36 +61,17 @@ error ('conv: SHAPE argument must be "full", "same", or "valid"'); endif - la = la_orig = length (a); - lb = lb_orig = length (b); - - ly = la + lb - 1; - - if (ly == 0) - y = zeros (1, 0); - return; - endif + y = conv2 (a(:), b(:), shape); - ## Use shortest vector as the coefficent vector to filter. - if (la > lb) - [a, b] = deal (b, a); # Swap vectors - lb = la; - endif - x = b; - - ## Pad longer vector to convolution length. - if (ly > lb) - x(end+1:end+ly-lb) = 0; - endif - - y = filter (a, 1, x); - - if (strcmpi (shape, "same")) - idx = ceil ((ly - la) / 2); - y = y(idx+1:idx+la); - elseif (strcmpi (shape, "valid")) - len = la_orig - lb_orig; - y = y(lb_orig:lb_orig+len); + if (strcmpi (shape, "full")) + ## Adapt the shape to the longest input argument, if necessary. + if ((length (a) > length (b) && isrow (a)) ... + || (length (a) <= length (b) && isrow (b))) + y = y.'; + endif + elseif (isrow (a)) + ## Adapt the shape to the first input argument, if necessary. + y = y.'; endif endfunction