comparison scripts/general/trapz.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
112 endif 112 endif
113 ## Reshape vector to point along dimension DIM 113 ## Reshape vector to point along dimension DIM
114 shape = ones (nd, 1); 114 shape = ones (nd, 1);
115 shape(dim) = sz(dim); 115 shape(dim) = sz(dim);
116 x = reshape (x, shape); 116 x = reshape (x, shape);
117 z = 0.5 * sum (bsxfun (@times, diff (x), y(idx1{:}) + y(idx2{:})), dim); 117 z = 0.5 * sum (diff (x) .* (y(idx1{:}) + y(idx2{:})), dim);
118 else 118 else
119 if (! size_equal (x, y)) 119 if (! size_equal (x, y))
120 error ("trapz: X and Y must have same shape"); 120 error ("trapz: X and Y must have same shape");
121 endif 121 endif
122 z = 0.5 * sum (diff (x, 1, dim) .* (y(idx1{:}) + y(idx2{:})), dim); 122 z = 0.5 * sum (diff (x, 1, dim) .* (y(idx1{:}) + y(idx2{:})), dim);