GNU Octave  3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SparseQR.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2005-2013 David Bateman
4 
5 This file is part of Octave.
6 
7 Octave is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if !defined (octave_SparseQR_h)
24 #define octave_SparseQR_h 1
25 
26 #include <iosfwd>
27 
28 #include "dMatrix.h"
29 #include "CMatrix.h"
30 #include "dSparse.h"
31 #include "CSparse.h"
32 #include "oct-sparse.h"
33 
34 #ifdef USE_64_BIT_IDX_T
35 #define CXSPARSE_DNAME(name) cs_dl ## name
36 #else
37 #define CXSPARSE_DNAME(name) cs_di ## name
38 #endif
39 
40 class
41 OCTAVE_API
43 {
44 protected:
46  {
47  public:
48  SparseQR_rep (const SparseMatrix& a, int order);
49 
50  ~SparseQR_rep (void);
51 #ifdef HAVE_CXSPARSE
52  bool ok (void) const { return (N && S); }
53 #else
54  bool ok (void) const { return false; }
55 #endif
56  SparseMatrix V (void) const;
57 
58  ColumnVector Pinv (void) const;
59 
60  ColumnVector P (void) const;
61 
62  SparseMatrix R (const bool econ) const;
63 
64  Matrix C (const Matrix &b) const;
65 
66  Matrix Q (void) const;
67 
69 
71 #ifdef HAVE_CXSPARSE
73 
75 #endif
76 
77  private:
78 
79  // No copying!
80 
81  SparseQR_rep (const SparseQR_rep&);
82 
83  SparseQR_rep& operator = (const SparseQR_rep&);
84  };
85 
86 private:
87 
89 
90 public:
91 
92  SparseQR (void) : rep (new SparseQR_rep (SparseMatrix (), 0)) { }
93 
94  SparseQR (const SparseMatrix& a, int order = 0) :
95  rep (new SparseQR_rep (a, order)) { }
96 
97  SparseQR (const SparseQR& a) : rep (a.rep) { rep->count++; }
98 
99  ~SparseQR (void)
100  {
101  if (--rep->count == 0)
102  delete rep;
103  }
104 
105  SparseQR& operator = (const SparseQR& a)
106  {
107  if (this != &a)
108  {
109  if (--rep->count == 0)
110  delete rep;
111 
112  rep = a.rep;
113  rep->count++;
114  }
115  return *this;
116  }
117 
118  bool ok (void) const { return rep->ok (); }
119 
120  SparseMatrix V (void) const { return rep->V (); }
121 
122  ColumnVector Pinv (void) const { return rep->P (); }
123 
124  ColumnVector P (void) const { return rep->P (); }
125 
126  SparseMatrix R (const bool econ = false) const { return rep->R(econ); }
127 
128  Matrix C (const Matrix &b) const { return rep->C(b); }
129 
130  Matrix Q (void) const { return rep->Q (); }
131 
132  friend Matrix qrsolve (const SparseMatrix &a, const Matrix &b,
133  octave_idx_type &info);
134 
135  friend SparseMatrix qrsolve (const SparseMatrix &a, const SparseMatrix &b,
136  octave_idx_type &info);
137 
138  friend ComplexMatrix qrsolve (const SparseMatrix &a, const ComplexMatrix &b,
139  octave_idx_type &info);
140 
141  friend SparseComplexMatrix qrsolve (const SparseMatrix &a,
142  const SparseComplexMatrix &b,
143  octave_idx_type &info);
144 
145 protected:
146 #ifdef HAVE_CXSPARSE
147  CXSPARSE_DNAME (s) * S (void) { return rep->S; }
148 
149  CXSPARSE_DNAME (n) * N (void) { return rep->N; }
150 #endif
151 };
152 
153 
154 // Publish externally used friend functions.
155 
156 extern Matrix qrsolve (const SparseMatrix &a, const Matrix &b,
157  octave_idx_type &info);
158 
159 extern Matrix qrsolve (const SparseMatrix &a, const MArray<double> &b,
160  octave_idx_type &info);
161 
162 extern SparseMatrix qrsolve (const SparseMatrix &a, const SparseMatrix &b,
163  octave_idx_type &info);
164 
165 extern ComplexMatrix qrsolve (const SparseMatrix &a, const ComplexMatrix &b,
166  octave_idx_type &info);
167 
168 extern ComplexMatrix qrsolve (const SparseMatrix &a, const MArray<Complex> &b,
169  octave_idx_type &info);
170 
171 extern SparseComplexMatrix qrsolve (const SparseMatrix &a,
172  const SparseComplexMatrix &b,
173  octave_idx_type &info);
174 
175 #endif