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

« back to all changes in this revision

Viewing changes to SPQR/Demo/qrsimple.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Rafael Laboissiere
  • Date: 2009-02-24 11:08:12 UTC
  • mfrom: (7.2.2 sid)
  • Revision ID: james.westby@ubuntu.com-20090224110812-hawvr3dh5kjbvlae
debian/control: Add an epoch to the version number of
libsuitesparse-3.0.2 in replaces/conflicts for libcolamd-3.2.0
(really, closes: #516725)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// =============================================================================
 
2
// === qrsimple.cpp ============================================================
 
3
// =============================================================================
 
4
 
 
5
// A very simple example of the use of SuiteSparseQR by a C++ main program.
 
6
// Usage:  qrsimple < Matrix_in_MatrixMarket_format
 
7
 
 
8
#include "SuiteSparseQR.hpp"
 
9
int main (int argc, char **argv)
 
10
{
 
11
    cholmod_common Common, *cc ;
 
12
    cholmod_sparse *A ;
 
13
    cholmod_dense *X, *B, *Residual ;
 
14
    double rnorm, one [2] = {1,0}, minusone [2] = {-1,0} ;
 
15
    int mtype ;
 
16
 
 
17
    // start CHOLMOD
 
18
    cc = &Common ;
 
19
    cholmod_l_start (cc) ;
 
20
 
 
21
    // load A
 
22
    A = (cholmod_sparse *)
 
23
        cholmod_l_read_matrix (stdin, 1, &mtype, cc) ;
 
24
 
 
25
    // B = ones (size (A,1),1)
 
26
    B = cholmod_l_ones (A->nrow, 1, A->xtype, cc) ;
 
27
 
 
28
    // X = A\B
 
29
    X = SuiteSparseQR <double> (A, B, cc) ;
 
30
 
 
31
    // rnorm = norm (B-A*X)
 
32
    Residual = cholmod_l_copy_dense (B, cc) ;
 
33
    cholmod_l_sdmult (A, 0, minusone, one, X, Residual, cc) ;
 
34
    rnorm = cholmod_l_norm_dense (Residual, 2, cc) ;
 
35
    printf ("2-norm of residual: %8.1e\n", rnorm) ;
 
36
    printf ("rank %ld\n", cc->SPQR_istat [4]) ;
 
37
 
 
38
    // free everything and finish CHOLMOD
 
39
    cholmod_l_free_dense (&Residual, cc) ;
 
40
    cholmod_l_free_sparse (&A, cc) ;
 
41
    cholmod_l_free_dense (&X, cc) ;
 
42
    cholmod_l_free_dense (&B, cc) ;
 
43
    cholmod_l_finish (cc) ;
 
44
    return (0) ;
 
45
}