File: get_problem.m

package info (click to toggle)
ufsparse 1.2-7
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 27,536 kB
  • ctags: 5,848
  • sloc: ansic: 89,328; makefile: 4,721; fortran: 1,991; csh: 207; sed: 162; awk: 33; java: 30; sh: 8
file content (50 lines) | stat: -rw-r--r-- 1,160 bytes parent folder | download
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
function [C sym] = get_problem (name, tol)
% [C sym] = get_problem(name,tol)
% read a problem from a file, drop entries with abs value < tol
% tol defaults to zero if not present

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

if (nargin < 2)
    tol = 0 ;
end

s = find (name == '/') ;
if (isempty (s))
    s = 0 ;
end
f = sprintf ('..%s..%sMatrix%s%s', ...
    filesep, filesep, filesep, name (s+1:end)) ;

% load the triplet version of the matrix
T = load (f) ;

% convert into a sparse matrix and compare with cs_triplet
A  = sparse     (T (:,1)+1, T (:,2)+1, T (:,3)) ;
A2 = cs_triplet (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