1function S = sssvd (matrix, ss_index)                                       %#ok
2%SSSVD singular values of a matrix in the SuiteSparse Matrix Collection.
3%
4% As of Nov 2012, only matrices for which min(size(A)) <= 30401
5% have their singular values computed.
6%
7% Examples:
8%   S = sssvd ('HB/arc130')
9%   S = sssvd (6)
10%   index = ssget
11%   S = sssvd (6, index)
12%
13% S is a struct containing:
14%   s       the singular values (a column vector of size min(size(A)))
15%   how     a string
16%
17% See also ssget.
18
19% Copyright 2017-2019, Timothy A. Davis, http://www.suitesparse.com
20
21if (nargin < 2)
22    % load the SuiteSparse index
23    ss_index = ssget ;
24end
25
26% look up the matrix in the SuiteSparse index
27[group, matrix, id] = ssget_lookup (matrix, ss_index) ;
28if (id == 0)
29    error ('invalid matrix') ;
30end
31
32% determine where the files go
33params = ssget_defaults ;
34svddir  = [ params.topdir 'svd' filesep group ] ;
35svdfile = [ svddir filesep matrix '_SVD.mat' ] ;
36svdurl  = [ params.topurl '/svd/' group '/' matrix '_SVD.mat' ] ;
37
38% make sure the mat/Group directory exists
39if (~exist (svddir, 'dir'))
40    mkdir (svddir) ;
41end
42
43% download the *_SVD.mat file, if not already downloaded
44if (~exist (svdfile, 'file'))
45    fprintf ('downloading %s\n', svdurl) ;
46    fprintf ('to %s\n', svdfile) ;
47    tmp = tempname ;                        % download to a temp file first
48    try
49        websave (tmp, svdurl) ;
50    catch me
51        error ('SVD not yet computed for this matrix (or URL not found)') ;
52    end
53    movefile (tmp, svdfile, 'f') ;          % move the new matrix into place
54end
55
56% load the SVD, which sets the return value of S
57load (svdfile) ;
58
59