Mercurial > hg > octave-lojdl
changeset 9104:e0250e2b60ed
optimize vander
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Wed, 08 Apr 2009 13:16:23 +0200 |
parents | 10bed8fbec99 |
children | 9b12ed1fbbbd |
files | scripts/ChangeLog scripts/special-matrix/vander.m |
diffstat | 2 files changed, 13 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,7 @@ +2009-04-08 Jaroslav Hajek <highegg@gmail.com> + + * special-matrix/vander.m: Optimize. + 2009-04-07 Ben Abbott <bpabbott@mac.com> * plot/Makefile.in: Remove __gnuplot_default_font__.m from SOURCES.
--- a/scripts/special-matrix/vander.m +++ b/scripts/special-matrix/vander.m @@ -1,5 +1,6 @@ ## Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2002, ## 2004, 2005, 2006, 2007, 2008, 2009 John W. Eaton +## Copyright (C) 2009 VZLU Prague ## ## This file is part of Octave. ## @@ -58,7 +59,14 @@ if (isvector (c)) n = length (c); - retval = (c(:) * ones (1, n)) .^ (ones (n, 1) * (n-1:-1:0)); + retval = zeros (n, n, class (c)); + ## avoiding many ^s appears to be faster for n >= 100. + d = 1; + c = c(:); + for i = n:-1:1 + retval(:,i) = d; + d = c .* d; + endfor else error ("vander: argument must be a vector"); endif