comparison scripts/general/cumtrapz.m @ 20652: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 7503499a252b
children
comparison
equal deleted inserted replaced
20651:e54ecb33727e 20652:a3b9ee5c040a
98 endif 98 endif
99 ## Reshape vector to point along dimension DIM 99 ## Reshape vector to point along dimension DIM
100 shape = ones (nd, 1); 100 shape = ones (nd, 1);
101 shape(dim) = sz(dim); 101 shape(dim) = sz(dim);
102 x = reshape (x, shape); 102 x = reshape (x, shape);
103 z = 0.5 * cumsum (bsxfun (@times, diff (x), y(idx1{:}) + y(idx2{:})), dim); 103 z = 0.5 * cumsum (diff (x) .* (y(idx1{:}) + y(idx2{:})), dim);
104 else 104 else
105 if (! size_equal (x, y)) 105 if (! size_equal (x, y))
106 error ("cumtrapz: X and Y must have same shape"); 106 error ("cumtrapz: X and Y must have same shape");
107 endif 107 endif
108 z = 0.5 * cumsum (diff (x, 1, dim) .* (y(idx1{:}) + y(idx2{:})), dim); 108 z = 0.5 * cumsum (diff (x, 1, dim) .* (y(idx1{:}) + y(idx2{:})), dim);