1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
function [Q,R,C,p,info] = spqr_wrapper (A, B, tol, Q_option, get_details)
%SPQR_WRAPPER wrapper around spqr to get additional statistics
% Not user-callable. Usage:
%
% [Q,R,C,p,info] = spqr_wrapper (A, B, tol, Q_option, get_details) ;
% spqr_rank, Copyright (c) 2012, Leslie Foster and Timothy A Davis.
% All Rights Reserved.
% SPDX-License-Identifier: BSD-3-clause
if (get_details)
% get detailed statistics for time and memory usage
t = tic ;
end
% set the options
opts.econ = 0 ; % get the rank-sized factorization
opts.tol = tol ; % columns with norm <= tol treated as zero
opts.permutation = 'vector' ; % return permutation as a vector, not a matrix
if (~issparse (A))
A = sparse (A) ; % make sure A is sparse
end
m = size (A,1) ;
if (strcmp (Q_option, 'keep Q'))
% compute Q*R = A(:,p) and keep Q in Householder form
opts.Q = 'Householder' ;
[Q,R,p,info] = spqr (A, opts) ;
if (isempty (B))
% C is empty
C = zeros (m,0) ;
else
% also compute C = Q'*B if B is present
C = spqr_qmult (Q, B, 0) ;
end
else
% compute Q*R = A(:,p), but discard Q
opts.Q = 'discard' ;
if (isempty (B))
[Q,R,p,info] = spqr (A, opts) ;
% C is empty
C = zeros (m,0) ;
else
% also compute C = Q'*B if B is present
[C,R,p,info] = spqr (A, B, opts) ;
Q = [ ] ;
end
end
if (get_details)
info.time = toc (t) ;
end
|