~logan/ubuntu/trusty/suitesparse/4.2.1-3ubuntu1

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Prud'homme
  • Date: 2007-05-29 09:36:29 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070529093629-zowquo0b7slkk6nc
Tags: 3.0.0-2
* suitesparse builds properly twice in a row
* Bug fix: "suitesparse - FTBFS: Broken build depens: libgfortran1-dev",
  thanks to Bastian Blank (Closes: #426349).
* Bug fix: "suitesparse_3.0.0-1: FTBFS: build-depends on
  libgfortran1-dev", thanks to Steve Langasek (Closes: #426354).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
function [C, sym] = get_problem (prefix, name, tol)
 
2
% [C, sym] = get_problem(prefix, 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 ('', 'west0067') ;
 
8
% See also: cs_demo
 
9
 
 
10
%   Copyright 2006-2007, 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..%s..%sMatrix%s%s', ...
 
24
%    prefix, filesep, filesep, filesep, name (s+1:end)) ;
 
25
 
 
26
% load the triplet version of the matrix
 
27
T = load ([ prefix '/' name(s+1:end) ]) ;
 
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