Mercurial > octave
annotate liboctave/numeric/svd.h @ 22317:6ca3acf5fad8
move some new numeric classes to namespace octave::math
* aepbalance.cc, aepbalance.h, chol.cc, chol.h, gepbalance.cc,
gepbalance.h, hess.cc, hess.h, lu.cc, lu.h, qr.cc, qr.h, qrp.cc,
qrp.h, schur.cc, schur.h, sparse-chol.cc, sparse-chol.h,
sparse-dmsolve.cc,sparse-lu.cc, sparse-lu.h, sparse-qr.cc,
sparse-qr.h, svd.cc, svd.h: Move classes to namespace octave::math.
* __luinc__.cc, __qp__.cc, balance.cc, hess.cc, lu.cc, qz.cc,
schur.cc, sqrtm.cc, svd.cc, chol.cc, dmperm.cc, qr.cc, lex.h,
CMatrix.cc, CSparse.cc, dMatrix.cc, dSparse.cc, fCMatrix.cc,
fMatrix.cc, eigs-base.cc, oct-norm.cc: Update for new namespaces.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 16 Aug 2016 15:48:22 -0400 |
parents | da201af35c97 |
children | bac0d6f07a3e |
rev | line source |
---|---|
457 | 1 /* |
2 | |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
21273
diff
changeset
|
3 Copyright (C) 2016 Carnë Draug |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
17822
diff
changeset
|
4 Copyright (C) 1994-2015 John W. Eaton |
457 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
457 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
457 | 21 |
22 */ | |
23 | |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
24 #if ! defined (octave_svd_h) |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
25 #define octave_svd_h 1 |
457 | 26 |
21244
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
27 #include "octave-config.h" |
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
28 |
22249
da201af35c97
maint: properly include <vector> in svd classes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22248
diff
changeset
|
29 #include <vector> |
22248
60986498af9e
svd: use std::vector instead of Matrix when a std::vector is enough.
Carnë Draug <carandraug@octave.org>
parents:
22230
diff
changeset
|
30 |
22317
6ca3acf5fad8
move some new numeric classes to namespace octave::math
John W. Eaton <jwe@octave.org>
parents:
22249
diff
changeset
|
31 namespace octave |
6ca3acf5fad8
move some new numeric classes to namespace octave::math
John W. Eaton <jwe@octave.org>
parents:
22249
diff
changeset
|
32 { |
6ca3acf5fad8
move some new numeric classes to namespace octave::math
John W. Eaton <jwe@octave.org>
parents:
22249
diff
changeset
|
33 namespace math |
6ca3acf5fad8
move some new numeric classes to namespace octave::math
John W. Eaton <jwe@octave.org>
parents:
22249
diff
changeset
|
34 { |
6ca3acf5fad8
move some new numeric classes to namespace octave::math
John W. Eaton <jwe@octave.org>
parents:
22249
diff
changeset
|
35 |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
36 template <typename T> |
1880 | 37 class |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
38 svd |
457 | 39 { |
40 public: | |
41 | |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
42 typedef typename T::real_diag_matrix_type DM_T; |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
43 |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
21273
diff
changeset
|
44 enum class Type |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
45 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
46 std, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
47 economy, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
48 sigma_only |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
49 }; |
537 | 50 |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
21273
diff
changeset
|
51 enum class Driver |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
52 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
53 GESVD, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
54 GESDD |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
55 }; |
10601 | 56 |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
57 svd (void) |
22228
4afe3705ea75
svd: do not shadow member variables with local variables.
Carnë Draug <carandraug@octave.org>
parents:
22204
diff
changeset
|
58 : m_type (), m_driver (), left_sm (), sigma (), right_sm () |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
59 { } |
1528 | 60 |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
21273
diff
changeset
|
61 svd (const T& a, svd::Type type = svd::Type::std, |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
21273
diff
changeset
|
62 svd::Driver driver = svd::Driver::GESVD); |
457 | 63 |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
64 svd (const svd& a) |
22228
4afe3705ea75
svd: do not shadow member variables with local variables.
Carnë Draug <carandraug@octave.org>
parents:
22204
diff
changeset
|
65 : m_type (a.m_type), m_driver (a.m_driver), left_sm (a.left_sm), |
4afe3705ea75
svd: do not shadow member variables with local variables.
Carnë Draug <carandraug@octave.org>
parents:
22204
diff
changeset
|
66 sigma (a.sigma), right_sm (a.right_sm) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
67 { } |
457 | 68 |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
69 svd& operator = (const svd& a) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
70 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
71 if (this != &a) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
72 { |
22228
4afe3705ea75
svd: do not shadow member variables with local variables.
Carnë Draug <carandraug@octave.org>
parents:
22204
diff
changeset
|
73 m_type = a.m_type; |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
74 left_sm = a.left_sm; |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
75 sigma = a.sigma; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
76 right_sm = a.right_sm; |
22228
4afe3705ea75
svd: do not shadow member variables with local variables.
Carnë Draug <carandraug@octave.org>
parents:
22204
diff
changeset
|
77 m_driver = a.m_driver; |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
78 } |
1528 | 79 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
80 return *this; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
81 } |
1528 | 82 |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
83 ~svd (void) { } |
1930 | 84 |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
85 T left_singular_matrix (void) const; |
1528 | 86 |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
87 DM_T singular_values (void) const { return sigma; } |
1528 | 88 |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
89 T right_singular_matrix (void) const; |
457 | 90 |
91 private: | |
92 | |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
21273
diff
changeset
|
93 typedef typename T::element_type P; |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
21273
diff
changeset
|
94 typedef typename DM_T::element_type DM_P; |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
21273
diff
changeset
|
95 |
22228
4afe3705ea75
svd: do not shadow member variables with local variables.
Carnë Draug <carandraug@octave.org>
parents:
22204
diff
changeset
|
96 svd::Type m_type; |
4afe3705ea75
svd: do not shadow member variables with local variables.
Carnë Draug <carandraug@octave.org>
parents:
22204
diff
changeset
|
97 svd::Driver m_driver; |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
98 |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
99 T left_sm; |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
100 DM_T sigma; |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
101 T right_sm; |
1544 | 102 |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
21273
diff
changeset
|
103 void gesvd (char& jobu, char& jobv, octave_idx_type m, octave_idx_type n, |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
21273
diff
changeset
|
104 P* tmp_data, octave_idx_type m1, DM_P* s_vec, P* u, P* vt, |
22248
60986498af9e
svd: use std::vector instead of Matrix when a std::vector is enough.
Carnë Draug <carandraug@octave.org>
parents:
22230
diff
changeset
|
105 octave_idx_type nrow_vt1, std::vector<P>& work, octave_idx_type& lwork, |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
21273
diff
changeset
|
106 octave_idx_type& info); |
1880 | 107 |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
21273
diff
changeset
|
108 void gesdd (char& jobz, octave_idx_type m, octave_idx_type n, |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
21273
diff
changeset
|
109 P* tmp_data, octave_idx_type m1, DM_P* s_vec, P* u, P* vt, |
22248
60986498af9e
svd: use std::vector instead of Matrix when a std::vector is enough.
Carnë Draug <carandraug@octave.org>
parents:
22230
diff
changeset
|
110 octave_idx_type nrow_vt1, std::vector<P>& work, |
60986498af9e
svd: use std::vector instead of Matrix when a std::vector is enough.
Carnë Draug <carandraug@octave.org>
parents:
22230
diff
changeset
|
111 octave_idx_type& lwork, |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
21273
diff
changeset
|
112 octave_idx_type* iwork, octave_idx_type& info); |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
21273
diff
changeset
|
113 |
457 | 114 }; |
115 | |
22317
6ca3acf5fad8
move some new numeric classes to namespace octave::math
John W. Eaton <jwe@octave.org>
parents:
22249
diff
changeset
|
116 } |
6ca3acf5fad8
move some new numeric classes to namespace octave::math
John W. Eaton <jwe@octave.org>
parents:
22249
diff
changeset
|
117 } |
6ca3acf5fad8
move some new numeric classes to namespace octave::math
John W. Eaton <jwe@octave.org>
parents:
22249
diff
changeset
|
118 |
457 | 119 #endif |