Mercurial > hg > octave-lojdl
changeset 9093:8be05554bbd0
optimize vech
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Mon, 06 Apr 2009 08:33:49 +0200 |
parents | 38c3a0f8c6d0 |
children | 2e35cfcf6a6a |
files | scripts/ChangeLog scripts/linear-algebra/vech.m |
diffstat | 2 files changed, 7 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,7 @@ +2009-04-06 Jaroslav Hajek <highegg@gmail.com> + + * linear-algebra/vech.m: Optimize. + 2009-04-06 Jaroslav Hajek <highegg@gmail.com> * special-matrix/toeplitz.m: Optimize.
--- a/scripts/linear-algebra/vech.m +++ b/scripts/linear-algebra/vech.m @@ -1,5 +1,6 @@ ## Copyright (C) 1995, 1996, 1997, 1999, 2000, 2002, 2005, 2006, 2007, 2008 ## Kurt Hornik +## Copyright (C) 2009 VZLU Prague ## ## This file is part of Octave. ## @@ -41,16 +42,9 @@ error ("vech: x must be square"); endif - ## This should be quicker than having an inner `for' loop as well. - ## Ideally, vech should be written in C++. n = rows (x); - v = zeros ((n+1)*n/2, 1); - count = 0; - for j = 1 : n - i = j : n; - v (count + i) = x (i, j); - count = count + n - j; - endfor + slices = cellslices (x(:), (1:n) + n*(0:n-1), n*(1:n)); + v = vertcat (slices{:}); endfunction