Mercurial > octave
annotate liboctave/numeric/svd.h @ 22249:da201af35c97
maint: properly include <vector> in svd classes.
* liboctave/numeric/gsvd.cc: insert missing include.
* liboctave/numeric/svd.h: use <> rather than "".
* liboctave/numeric/svd.cc: remove include, done in the header already.
author | Kai T. Ohlhus <k.ohlhus@gmail.com> |
---|---|
date | Wed, 10 Aug 2016 09:09:41 +0200 |
parents | 60986498af9e |
children | 6ca3acf5fad8 |
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 |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
31 template <typename T> |
1880 | 32 class |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
33 svd |
457 | 34 { |
35 public: | |
36 | |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
37 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
|
38 |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
21273
diff
changeset
|
39 enum class Type |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
40 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
41 std, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
42 economy, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
43 sigma_only |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
44 }; |
537 | 45 |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
21273
diff
changeset
|
46 enum class Driver |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
47 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
48 GESVD, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
49 GESDD |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
50 }; |
10601 | 51 |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
52 svd (void) |
22228
4afe3705ea75
svd: do not shadow member variables with local variables.
Carnë Draug <carandraug@octave.org>
parents:
22204
diff
changeset
|
53 : 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
|
54 { } |
1528 | 55 |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
21273
diff
changeset
|
56 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
|
57 svd::Driver driver = svd::Driver::GESVD); |
457 | 58 |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
59 svd (const svd& a) |
22228
4afe3705ea75
svd: do not shadow member variables with local variables.
Carnë Draug <carandraug@octave.org>
parents:
22204
diff
changeset
|
60 : 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
|
61 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
|
62 { } |
457 | 63 |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
64 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
|
65 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
66 if (this != &a) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
67 { |
22228
4afe3705ea75
svd: do not shadow member variables with local variables.
Carnë Draug <carandraug@octave.org>
parents:
22204
diff
changeset
|
68 m_type = a.m_type; |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
69 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
|
70 sigma = a.sigma; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
71 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
|
72 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
|
73 } |
1528 | 74 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
75 return *this; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
76 } |
1528 | 77 |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
78 ~svd (void) { } |
1930 | 79 |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
80 T left_singular_matrix (void) const; |
1528 | 81 |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
82 DM_T singular_values (void) const { return sigma; } |
1528 | 83 |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
84 T right_singular_matrix (void) const; |
457 | 85 |
86 private: | |
87 | |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
21273
diff
changeset
|
88 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
|
89 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
|
90 |
22228
4afe3705ea75
svd: do not shadow member variables with local variables.
Carnë Draug <carandraug@octave.org>
parents:
22204
diff
changeset
|
91 svd::Type m_type; |
4afe3705ea75
svd: do not shadow member variables with local variables.
Carnë Draug <carandraug@octave.org>
parents:
22204
diff
changeset
|
92 svd::Driver m_driver; |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
93 |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
94 T left_sm; |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
95 DM_T sigma; |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
96 T right_sm; |
1544 | 97 |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
21273
diff
changeset
|
98 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
|
99 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
|
100 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
|
101 octave_idx_type& info); |
1880 | 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 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
|
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, |
60986498af9e
svd: use std::vector instead of Matrix when a std::vector is enough.
Carnë Draug <carandraug@octave.org>
parents:
22230
diff
changeset
|
106 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
|
107 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
|
108 |
457 | 109 }; |
110 | |
111 #endif |