~ubuntu-branches/ubuntu/natty/suitesparse/natty

« back to all changes in this revision

Viewing changes to CSparse/MATLAB/Demo/private/get_problem.m

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Prud'homme
  • Date: 2006-12-22 10:16:15 UTC
  • Revision ID: james.westby@ubuntu.com-20061222101615-2ohaj8902oix2rnk
Tags: upstream-2.3.1
ImportĀ upstreamĀ versionĀ 2.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
function [C, sym] = get_problem (name, tol)
 
2
% [C, sym] = get_problem(name,tol)
 
3
% read a problem from a file, drop entries with abs value < tol
 
4
% tol defaults to zero if not present
 
5
%
 
6
% Example:
 
7
%    [C, sym] = get_problem ('HB/west0067') ;
 
8
% See also: cs_demo
 
9
 
 
10
%   Copyright 2006, Timothy A. Davis.
 
11
%   http://www.cise.ufl.edu/research/sparse
 
12
 
 
13
fprintf ('\n------------------- Matrix: %s\n', name) ;
 
14
 
 
15
if (nargin < 2)
 
16
    tol = 0 ;
 
17
end
 
18
 
 
19
s = find (name == '/') ;
 
20
if (isempty (s))
 
21
    s = 0 ;
 
22
end
 
23
f = sprintf ('..%s..%sMatrix%s%s', ...
 
24
    filesep, filesep, filesep, name (s+1:end)) ;
 
25
 
 
26
% load the triplet version of the matrix
 
27
T = load (f) ;
 
28
 
 
29
% convert into a sparse matrix and compare with cs_sparse
 
30
A  = sparse    (T (:,1)+1, T (:,2)+1, T (:,3)) ;
 
31
A2 = cs_sparse (T (:,1)+1, T (:,2)+1, T (:,3)) ;
 
32
err = norm (A-A2,1) ;
 
33
if (err > 0)
 
34
    fprintf ('A difference: %g\n', err) ;
 
35
end
 
36
 
 
37
[m n] = size (A) ;
 
38
nz2 = nnz (A) ;
 
39
 
 
40
if (tol > 0)
 
41
    A = cs_droptol (A, tol) ;
 
42
end
 
43
 
 
44
% assume A is symmetric if it is upper or lower triangular
 
45
sym = is_sym (A) ;
 
46
if (sym)
 
47
    C = A + (A' - diag (diag (A))) ;
 
48
else
 
49
    C = A ;
 
50
end
 
51
 
 
52
fprintf ('--- Matrix: %d-by-%d, nnz: %d (sym: %d nnz %d), norm: %8.2e\n', ...
 
53
    m, n, nnz(A), sym, abs(sym)*nnz(C), norm (C,1)) ;
 
54
 
 
55
if (nz2 ~= nnz(A))
 
56
    fprintf ('tiny entries dropped: %d\n', nz2 - nnz(A)) 
 
57
end