changeset 20828:a3b9ee5c040a

Replace bsxfun with broadcasting for performance with complex inputs (bug #38628). cumtrapz.m, quadgk.m, trapz.m, center.m, zscore.m: Replace bsxfun with broadcasting for performance where inputs might be complex.
author Rik <rik@octave.org>
date Mon, 12 Oct 2015 21:28:32 -0700
parents e54ecb33727e
children 9cef0a1207e4
files scripts/general/cumtrapz.m scripts/general/quadgk.m scripts/general/trapz.m scripts/statistics/base/center.m scripts/statistics/base/zscore.m
diffstat 5 files changed, 5 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/general/cumtrapz.m
+++ b/scripts/general/cumtrapz.m
@@ -100,7 +100,7 @@
       shape = ones (nd, 1);
       shape(dim) = sz(dim);
       x = reshape (x, shape);
-      z = 0.5 * cumsum (bsxfun (@times, diff (x), y(idx1{:}) + y(idx2{:})), dim);
+      z = 0.5 * cumsum (diff (x) .* (y(idx1{:}) + y(idx2{:})), dim);
     else
       if (! size_equal (x, y))
         error ("cumtrapz: X and Y must have same shape");
--- a/scripts/general/quadgk.m
+++ b/scripts/general/quadgk.m
@@ -420,7 +420,7 @@
 
   halfwidth = diff (subs, [], 2) ./ 2;
   center = sum (subs, 2) ./ 2;;
-  x = bsxfun (@plus, halfwidth * abscissa, center);
+  x = (halfwidth * abscissa) + center;
   y = reshape (f (x(:)), size (x));
 
   ## This is faster than using bsxfun as the * operator can use a
--- a/scripts/general/trapz.m
+++ b/scripts/general/trapz.m
@@ -114,7 +114,7 @@
       shape = ones (nd, 1);
       shape(dim) = sz(dim);
       x = reshape (x, shape);
-      z = 0.5 * sum (bsxfun (@times, diff (x), y(idx1{:}) + y(idx2{:})), dim);
+      z = 0.5 * sum (diff (x) .* (y(idx1{:}) + y(idx2{:})), dim);
     else
       if (! size_equal (x, y))
         error ("trapz: X and Y must have same shape");
--- a/scripts/statistics/base/center.m
+++ b/scripts/statistics/base/center.m
@@ -70,7 +70,7 @@
   if (n == 0)
     retval = x;
   else
-    retval = bsxfun (@minus, x, mean (x, dim));
+    retval = x - mean (x, dim);
   endif
 
 endfunction
--- a/scripts/statistics/base/zscore.m
+++ b/scripts/statistics/base/zscore.m
@@ -86,8 +86,7 @@
     sigma = std (x, opt, dim);
     s = sigma;
     s(s==0) = 1;
-    ## FIXME: Use normal broadcasting once we can disable that warning
-    z = bsxfun (@rdivide, bsxfun (@minus, x, mu), s);
+    z = (x - mu) ./ s;
   endif
 
 endfunction