## octave-cvsupdate

 [Octave-cvsupdate] SF.net SVN: octave:[5557] trunk/octave-forge/main/general/inst/unvech.m From: - 2009-02-18 13:28:55 ```Revision: 5557 http://octave.svn.sourceforge.net/octave/?rev=5557&view=rev Author: highegg Date: 2009-02-18 13:28:51 +0000 (Wed, 18 Feb 2009) Log Message: ----------- optimize & adjust style of unvech Modified Paths: -------------- trunk/octave-forge/main/general/inst/unvech.m Modified: trunk/octave-forge/main/general/inst/unvech.m =================================================================== --- trunk/octave-forge/main/general/inst/unvech.m 2009-02-11 21:02:23 UTC (rev 5556) +++ trunk/octave-forge/main/general/inst/unvech.m 2009-02-18 13:28:51 UTC (rev 5557) @@ -1,4 +1,5 @@ ## Copyright (C) 2006 Michael Creel +## Copyright (C) 2009 Jaroslav Hajek ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by @@ -19,42 +20,31 @@ ## triangular elements, received as a vector @var{v}. ## @end deftypefn -# Note: this uses a double loop. A C version would be a lot faster for large matrices. -## Adapted-By: Ben Hall - function x = unvech (v) - if (nargin != 1) - usage ("unvech (v)"); - endif + if (nargin != 1) + usage ("unvech (v)"); + endif + + if (! isvector(v)) + usage ("unvech (v)"); + endif + + # find out dimension of symmetric matrix + p = length (v); + n = -(1 - sqrt (1 + 8*p))/2; + + if (mod (n, 1) != 0) + error("unvech: the input vector does not generate a square matrix"); + endif + + x = zeros (n, n); - if (! isvector(v)) - usage ("unvech (v)"); - endif - - # find out dimension of symmetric matrix - p = length(v); - g = -(1 - sqrt(1 + 8*p))/2; - - if (mod(g,1) != 0) - error("unvech: the input vector does not generate a square matrix"); - endif - - x = zeros(g,g); - - # fill in the symmetric matrix, the obvious way -# k = 1; -# for i = 1:g -# for j = i:g -# x(i,j) = v(k); -# if (i != j) x(j,i) = v(k); endif -# k = k + 1; -# endfor -# endfor - - # fill in the symmetric matrix, a more clever way - ii = repmat( 1:g, [g 1] ); - idx= find( ii <= ii' ); - x(idx) = v; - x = x + x' - diag(diag(x)); + # do the reverse of vech + count = 0; + for j = 1 : n + i = j : n; + x(j,i) = x(i,j) = v(count + i); + count += n - j; + endfor endfunction This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ```
 [Octave-cvsupdate] SF.net SVN: octave:[5674] trunk/octave-forge/main/general/inst/unvech.m From: - 2009-04-04 20:45:09 ```Revision: 5674 http://octave.svn.sourceforge.net/octave/?rev=5674&view=rev Author: thomas-weber Date: 2009-04-04 20:45:01 +0000 (Sat, 04 Apr 2009) Log Message: ----------- Add tests for unvech Modified Paths: -------------- trunk/octave-forge/main/general/inst/unvech.m Modified: trunk/octave-forge/main/general/inst/unvech.m =================================================================== --- trunk/octave-forge/main/general/inst/unvech.m 2009-04-04 05:00:34 UTC (rev 5673) +++ trunk/octave-forge/main/general/inst/unvech.m 2009-04-04 20:45:01 UTC (rev 5674) @@ -48,3 +48,6 @@ count += n - j; endfor endfunction + +%!assert(unvech([1;0;0;1;0;1]), eye(3,3) ); +%!error unvech([1;0;0;1;0;1;1]); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ```
 [Octave-cvsupdate] SF.net SVN: octave:[8219] trunk/octave-forge/main/general/inst/unvech.m From: - 2011-04-18 17:28:33 ```Revision: 8219 http://octave.svn.sourceforge.net/octave/?rev=8219&view=rev Author: thomas-weber Date: 2011-04-18 17:28:27 +0000 (Mon, 18 Apr 2011) Log Message: ----------- Fix test failing due to type checking Modified Paths: -------------- trunk/octave-forge/main/general/inst/unvech.m Modified: trunk/octave-forge/main/general/inst/unvech.m =================================================================== --- trunk/octave-forge/main/general/inst/unvech.m 2011-04-18 15:53:40 UTC (rev 8218) +++ trunk/octave-forge/main/general/inst/unvech.m 2011-04-18 17:28:27 UTC (rev 8219) @@ -49,5 +49,5 @@ endfor endfunction -%!assert(unvech([1;0;0;1;0;1]), eye(3,3) ); +%!assert(unvech([1;0;0;1;0;1]), full(eye(3,3)) ); %!error unvech([1;0;0;1;0;1;1]); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ```
 [Octave-cvsupdate] SF.net SVN: octave:[8811] trunk/octave-forge/main/general/inst/unvech.m From: - 2011-10-21 15:23:18 ```Revision: 8811 http://octave.svn.sourceforge.net/octave/?rev=8811&view=rev Author: jpicarbajal Date: 2011-10-21 15:23:11 +0000 (Fri, 21 Oct 2011) Log Message: ----------- general. Updating unvech. All 3 tests pased with octave running with --norc Modified Paths: -------------- trunk/octave-forge/main/general/inst/unvech.m Modified: trunk/octave-forge/main/general/inst/unvech.m =================================================================== --- trunk/octave-forge/main/general/inst/unvech.m 2011-10-21 15:18:07 UTC (rev 8810) +++ trunk/octave-forge/main/general/inst/unvech.m 2011-10-21 15:23:11 UTC (rev 8811) @@ -15,7 +15,7 @@ ## ## You should have received a copy of the GNU General Public License ## along with this program; If not, see ;. - + ## -*- texinfo -*- ## @deftypefn {Function File} {@var{m} =} unvech (@var{v}, @var{scale}) ## Performs the reverse of @code{vech} on the vector @var{v}. @@ -27,31 +27,44 @@ ## that 1 and -1 can be used for symmetric and antisymmetric matrix respectively. ## @var{scale} must be a scalar and defaults to 1. ## -## @seealso{vech, ind2sub, sub2ind_tril} +## @seealso{vech, ind2sub} ## @end deftypefn - + function M = unvech (v, scale = 1) - + if ( nargin < 1 || nargin > 2 ) print_usage; elseif ( !ismatrix (v) && any (size (v) != 1) ) - error ("V must be a row orcolumn matrix") + error ("V must be a row or column matrix") elseif ( !isnumeric (scale) || !isscalar (scale) ) error ("SCALE must be a scalar") endif - + N = length (v); dim = (sqrt ( 1 + 8*N ) - 1)/2; [r, c] = ind2sub_tril (dim, 1:N); M = accumarray ([r; c].', v); M += scale * tril (M, -1).'; - + endfunction -%!assert(unvech([1;0;0;1;0;1]), full(eye(3,3)) ); +function [r c] = ind2sub_tril(N,idx) -#%!error unvech([1;0;0;1;0;1;1]); + %% Horrible lengthly check + if nargin < 2 ||( !isnumeric (N) && all(size(N)==1) )|| ... + !( ismatrix (idx) && any (size (idx)==1) ) + print_usage; + endif + + endofrow = 0.5*(1:N) .* (2*N:-1:N + 1); + c = lookup(endofrow, idx-1)+1; + r = N - endofrow(c) + idx ; + +end + +%!assert(unvech([1;0;0;1;0;1]), full(eye(3,3)) ); + %!test %symmetric %! dim = 10; %! A = tril( floor ( 5*(2*rand(dim)-1) ) ); @@ -59,7 +72,7 @@ %! M = vech(A); %! M = unvech(M, 1); %! assert (A, M); - + %!test %antisymmetric %! dim = 10; %! A = tril( floor ( 5*(2*rand(dim)-1) ) ); @@ -67,3 +80,4 @@ %! M = vech(A); %! M = unvech(M, -1); %! assert (A, M); + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ```
 [Octave-cvsupdate] SF.net SVN: octave:[8813] trunk/octave-forge/main/general/inst/unvech.m From: - 2011-10-21 17:01:05 ```Revision: 8813 http://octave.svn.sourceforge.net/octave/?rev=8813&view=rev Author: carandraug Date: 2011-10-21 17:00:59 +0000 (Fri, 21 Oct 2011) Log Message: ----------- unvech: added note to remove subfunction ind2sub_tril after official release of octave 3.6 and removed unecessary check of arguments in subfunction Modified Paths: -------------- trunk/octave-forge/main/general/inst/unvech.m Modified: trunk/octave-forge/main/general/inst/unvech.m =================================================================== --- trunk/octave-forge/main/general/inst/unvech.m 2011-10-21 16:04:59 UTC (rev 8812) +++ trunk/octave-forge/main/general/inst/unvech.m 2011-10-21 17:00:59 UTC (rev 8813) @@ -15,7 +15,7 @@ ## ## You should have received a copy of the GNU General Public License ## along with this program; If not, see ;. - + ## -*- texinfo -*- ## @deftypefn {Function File} {@var{m} =} unvech (@var{v}, @var{scale}) ## Performs the reverse of @code{vech} on the vector @var{v}. @@ -29,9 +29,12 @@ ## ## @seealso{vech, ind2sub} ## @end deftypefn - + +## TODO remove subfunction ind2sub_tril after new release of octave that will have +## it builtin standard ind2sub + function M = unvech (v, scale = 1) - + if ( nargin < 1 || nargin > 2 ) print_usage; elseif ( !ismatrix (v) && any (size (v) != 1) ) @@ -39,32 +42,26 @@ elseif ( !isnumeric (scale) || !isscalar (scale) ) error ("SCALE must be a scalar") endif - + N = length (v); dim = (sqrt ( 1 + 8*N ) - 1)/2; - [r, c] = ind2sub_tril (dim, 1:N); + [r, c] = ind2sub_tril (dim, 1:N); # replace with core ind2sub after octave 3.6 M = accumarray ([r; c].', v); M += scale * tril (M, -1).'; - + endfunction function [r c] = ind2sub_tril(N,idx) - %% Horrible lengthly check - if nargin < 2 ||( !isnumeric (N) && all(size(N)==1) )|| ... - !( ismatrix (idx) && any (size (idx)==1) ) - print_usage; - endif - endofrow = 0.5*(1:N) .* (2*N:-1:N + 1); c = lookup(endofrow, idx-1)+1; r = N - endofrow(c) + idx ; -end +endfunction %!assert(unvech([1;0;0;1;0;1]), full(eye(3,3)) ); - + %!test %symmetric %! dim = 10; %! A = tril( floor ( 5*(2*rand(dim)-1) ) ); @@ -72,7 +69,7 @@ %! M = vech(A); %! M = unvech(M, 1); %! assert (A, M); - + %!test %antisymmetric %! dim = 10; %! A = tril( floor ( 5*(2*rand(dim)-1) ) ); @@ -80,4 +77,3 @@ %! M = vech(A); %! M = unvech(M, -1); %! assert (A, M); - This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ```