--- toeplitz.m.orig 2009-04-12 10:46:22.000000000 +0200 +++ toeplitz.m 2009-04-16 10:41:10.000000000 +0200 @@ -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); + + ## 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(:)]; - ## Get slices. - slices = cellslices (data, nc:-1:1, nc+nr-1:-1:nr); - - ## 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