# HG changeset patch # User Rik # Date 1444710512 25200 # Node ID a3b9ee5c040aecff5cd9930a9b1923c6d9b0c943 # Parent e54ecb33727e03de2ac4cf6b34ecd9749193a990 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. diff -r e54ecb33727e -r a3b9ee5c040a scripts/general/cumtrapz.m --- a/scripts/general/cumtrapz.m Mon Oct 12 21:13:47 2015 -0700 +++ b/scripts/general/cumtrapz.m Mon Oct 12 21:28:32 2015 -0700 @@ -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"); diff -r e54ecb33727e -r a3b9ee5c040a scripts/general/quadgk.m --- a/scripts/general/quadgk.m Mon Oct 12 21:13:47 2015 -0700 +++ b/scripts/general/quadgk.m Mon Oct 12 21:28:32 2015 -0700 @@ -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 diff -r e54ecb33727e -r a3b9ee5c040a scripts/general/trapz.m --- a/scripts/general/trapz.m Mon Oct 12 21:13:47 2015 -0700 +++ b/scripts/general/trapz.m Mon Oct 12 21:28:32 2015 -0700 @@ -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"); diff -r e54ecb33727e -r a3b9ee5c040a scripts/statistics/base/center.m --- a/scripts/statistics/base/center.m Mon Oct 12 21:13:47 2015 -0700 +++ b/scripts/statistics/base/center.m Mon Oct 12 21:28:32 2015 -0700 @@ -70,7 +70,7 @@ if (n == 0) retval = x; else - retval = bsxfun (@minus, x, mean (x, dim)); + retval = x - mean (x, dim); endif endfunction diff -r e54ecb33727e -r a3b9ee5c040a scripts/statistics/base/zscore.m --- a/scripts/statistics/base/zscore.m Mon Oct 12 21:13:47 2015 -0700 +++ b/scripts/statistics/base/zscore.m Mon Oct 12 21:28:32 2015 -0700 @@ -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