Mercurial > hg > octave-shane
changeset 9940:1707df259536
optimize interp1q
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Mon, 07 Dec 2009 21:46:12 +0100 |
parents | f0f7c2477cdb |
children | 1369f13ae6b2 |
files | scripts/ChangeLog scripts/general/interp1q.m |
diffstat | 2 files changed, 11 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,7 @@ +2009-12-07 Jaroslav Hajek <highegg@gmail.com> + + * general/interp1q.m: Use more optimal code. + 2009-12-08 John W. Eaton <jwe@octave.org> * Makefile.am (DOCSTRINGS): Depend on $(GEN_FCN_FILES) instead
--- a/scripts/general/interp1q.m +++ b/scripts/general/interp1q.m @@ -39,19 +39,17 @@ x = x(:); nx = size (x, 1); szy = size (y); - ny = szy (1); - nc = prod (szy (2 : end)); - y = reshape (y, ny, nc); + y = y(:,:); + [ny, nc] = size (y); szx = size (xi); xi = xi (:); - range = find (xi >= x (1) & xi <= x (nx)); - yi = NA (size(xi, 1), size (y, 2)); - xi = xi (range); - dy = y (2 : ny, :) - y (1 : ny - 1, :); - dx = x (2 : nx) - x (1 : nx - 1); + dy = diff (y); + dx = diff (x); idx = lookup (x, xi, "lr"); s = (xi - x (idx)) ./ dx (idx); - yi (range, :) = s (:, ones (1, nc)) .* dy (idx, :) + y (idx, :); + yi = bsxfun (@times, s, dy(idx,:)) + y(idx,:); + range = xi < x(1) | !(xi <= x(nx)); + yi(range,:) = NA; if (length (szx) == 2 && any (szx == 1)) yi = reshape (yi, [max(szx), szy(2:end)]); else