File: get_problem.m

package info (click to toggle)
suitesparse 1%3A5.12.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 176,720 kB
  • sloc: ansic: 1,193,914; cpp: 31,704; makefile: 6,638; fortran: 1,927; java: 1,826; csh: 765; ruby: 725; sh: 529; python: 333; perl: 225; sed: 164; awk: 35
file content (54 lines) | stat: -rw-r--r-- 1,263 bytes parent folder | download | duplicates (10)
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
function [C, sym] = get_problem (prefix, name, tol)
% [C, sym] = get_problem(prefix, name,tol)
% read a problem from a file, drop entries with abs value < tol
% tol defaults to zero if not present
%
% Example:
%    [C, sym] = get_problem ('', 'west0067') ;
% See also: cs_demo

% Copyright 2006-2012, Timothy A. Davis, http://www.suitesparse.com

fprintf ('\n------------------- Matrix: %s\n', name) ;

if (nargin < 2)
    tol = 0 ;
end

s = find (name == '/') ;
if (isempty (s))
    s = 0 ;
end

% load the triplet version of the matrix
T = load ([ prefix '/' name(s+1:end) ]) ;

% convert into a sparse matrix and compare with cs_sparse
A  = sparse    (T (:,1)+1, T (:,2)+1, T (:,3)) ;
A2 = cs_sparse (T (:,1)+1, T (:,2)+1, T (:,3)) ;
err = norm (A-A2,1) ;
if (err > 0)
    fprintf ('A difference: %g\n', err) ;
end

[m n] = size (A) ;
nz2 = nnz (A) ;

if (tol > 0)
    A = cs_droptol (A, tol) ;
end

% assume A is symmetric if it is upper or lower triangular
sym = is_sym (A) ;
if (sym)
    C = A + (A' - diag (diag (A))) ;
else
    C = A ;
end

fprintf ('--- Matrix: %d-by-%d, nnz: %d (sym: %d nnz %d), norm: %8.2e\n', ...
    m, n, nnz(A), sym, abs(sym)*nnz(C), norm (C,1)) ;

if (nz2 ~= nnz(A))
    fprintf ('tiny entries dropped: %d\n', nz2 - nnz(A)) 
end