SparseQRSolver.hh 5.47 KB
Newer Older
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
/*===========================================================================*\
 *                                                                           *
 *                               CoMISo                                      *
 *      Copyright (C) 2008-2009 by Computer Graphics Group, RWTH Aachen      *
 *                           www.rwth-graphics.de                            *
 *                                                                           *
 *---------------------------------------------------------------------------* 
 *  This file is part of CoMISo.                                             *
 *                                                                           *
 *  CoMISo is free software: you can redistribute it and/or modify           *
 *  it under the terms of the GNU General Public License as published by     *
 *  the Free Software Foundation, either version 3 of the License, or        *
 *  (at your option) any later version.                                      *
 *                                                                           *
 *  CoMISo is distributed in the hope that it will be useful,                *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
 *  GNU General Public License for more details.                             *
 *                                                                           *
 *  You should have received a copy of the GNU General Public License        *
 *  along with CoMISo.  If not, see <http://www.gnu.org/licenses/>.          *
 *                                                                           *
\*===========================================================================*/ 


//=============================================================================
//
//  CLASS CholmodSolver
//
//=============================================================================

#ifndef COMISO_SPARSE_QR_SOLVER_HH
#define COMISO_SPARSE_QR_SOLVER_HH


//== INCLUDES =================================================================


#include <CoMISo/Config/CoMISoDefines.hh>
David Bommes's avatar
changed    
David Bommes committed
40
#include <CoMISo/Config/config.hh>
41
42
43
44
45
46
47
#include "GMM_Tools.hh"

#include <CoMISo/Utils/StopWatch.hh>

#include <iostream>
#include <vector>

David Bommes's avatar
changed    
David Bommes committed
48
49
50
51
52

//== BUILD-TIME DEPENDENCIES =================================================================
#if(COMISO_SUITESPARSE_SPQR_AVAILABLE)
//============================================================================================

53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include "SuiteSparseQR.hpp"
#include "cholmod.h"


//typedef struct cholmod_common_struct               cholmod_common;

//== NAMESPACES ===============================================================

namespace COMISO {

typedef struct SuiteSparseQR_factorization<double> sparseqr_factor;


//== CLASS DEFINITION =========================================================
class COMISODLLEXPORT SparseQRSolver
{
public:

  typedef UF_long Int;


    SparseQRSolver();
    ~SparseQRSolver();
    
    bool calc_system( const std::vector<Int>&    _colptr,
		      const std::vector<Int>&    _rowind,
		      const std::vector<double>& _values );


    template< class GMM_MatrixT>
    bool calc_system_gmm( const GMM_MatrixT& _mat);


    bool update_system( const std::vector<Int>&    _colptr,
 			const std::vector<Int>&    _rowind,
 			const std::vector<double>& _values );


    template< class GMM_MatrixT>
    bool update_system_gmm( const GMM_MatrixT& _mat);


    bool solve ( double *             _x0, double *             _b);

    bool solve ( std::vector<double>& _x0, const std::vector<double>& _b)
    {return solve( &(_x0[0]), (double*)&(_b[0]));}

    double tolerance() { return tolerance_; }

    int ordering() { return ordering_; }

    bool& show_timings() { return show_timings_;}
    
    // factorize _A*P = _Q*_R and return rank
    template< class GMM_MatrixT, class GMM_MatrixT2, class GMM_MatrixT3, class IntT>
    int factorize_system_gmm( const GMM_MatrixT& _A, GMM_MatrixT2& _Q, GMM_MatrixT3& _R, std::vector<IntT>& _P);

private:

    cholmod_common * mp_cholmodCommon;

    sparseqr_factor * mp_F;

    double tolerance_;

    // specify Permutation ordering
    // 1. user-provided permutation (only for cholmod analyze p).
    // 2. AMD with default parameters.
    // 3. METIS with default parameters.
    // 4. NESDIS with default parameters
    // 5. natural ordering (with weighted postorder).
    // 6. NESDIS, nd small = 20000, prune dense = 10.
    // 7. NESDIS, nd small = 4, prune dense = 10, no constrained minimum degree.
    // 8. NESDIS, nd small = 200, prune dense = 0.
    // 9. COLAMD for A*A^T or AMD for A
    int ordering_;
    
    // dimension of the mxn matrix
    int m_;
    int n_;

    std::vector<double> values_;
    std::vector<Int>    colptr_;
    std::vector<Int>    rowind_;

    bool show_timings_;
    StopWatch sw_;
};

//=============================================================================
} // namespace COMISO
//=============================================================================
#if defined(INCLUDE_TEMPLATES) && !defined(COMISO_SPARSE_QR_SOLVER_TEMPLATES_C)
#define COMISO_SPARSE_QR_SOLVER_TEMPLATES
#include "SparseQRSolverT.cc"
#endif
David Bommes's avatar
changed    
David Bommes committed
149
150
//== BUILD-TIME DEPENDENCIES ==================================================
#endif
151
152
153
//=============================================================================
#endif // COMISO_SPARSE_QR_SOLVER_HH defined
//=============================================================================