Mercurial > hg > octave-terminal
changeset 9126:5780b3b80425
optimize toeplitz for sparse args
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Thu, 16 Apr 2009 11:20:49 +0200 |
parents | 8ab1e6f63cdc |
children | 5ec4dc52c131 |
files | scripts/ChangeLog scripts/special-matrix/toeplitz.m |
diffstat | 2 files changed, 23 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,7 @@ +2009-04-16 Marco Caliari <marco.caliari@univr.it> + + * toeplitz.m: Treat separately the sparse case. + 2009-04-14 Thomas Treichl <Thomas.Treichl@gmx.net> * plot/__marching_cube__.m: Add help text.
--- a/scripts/special-matrix/toeplitz.m +++ b/scripts/special-matrix/toeplitz.m @@ -91,15 +91,28 @@ c(1) = conj (c(1)); endif - ## Concatenate data into a single column vector. - data = [r(end:-1:2)(:); c(:)]; + if (issparse(c) && issparse(r)) + c = c(:).'; + r = r(:).'; + cidx = find(c); + ridx = find(r); + + ## Ignore the first element in r. + ridx = ridx(ridx > 1); - ## Get slices. - slices = cellslices (data, nc:-1:1, nc+nr-1:-1:nr); + ## Form matrix. + retval = spdiags(repmat(c(cidx),nr,1),1-cidx,nr,nc)+... + spdiags(repmat(r(ridx),nr,1),ridx-1,nr,nc); + else + ## Concatenate data into a single column vector. + data = [r(end:-1:2)(:); c(:)]; - ## Form matrix. - retval = horzcat (slices{:}); + ## Get slices. + slices = cellslices (data, nc:-1:1, nc+nr-1:-1:nr); + ## Form matrix. + retval = horzcat (slices{:}); + endif endfunction %!assert((toeplitz (1) == 1