Mercurial > octave
annotate liboctave/numeric/svd.cc @ 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 | bc2a5db96754 |
children | 93b3cdd36854 |
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:
22135
diff
changeset
|
3 Copyright (C) 2016 Carnë Draug |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
17769
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 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
24 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21273
diff
changeset
|
25 # include "config.h" |
457 | 26 #endif |
27 | |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
28 #include "svd.h" |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
29 |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
30 #include <cassert> |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
31 #include <algorithm> |
1631 | 32 |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
33 #include "CMatrix.h" |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
34 #include "dDiagMatrix.h" |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
35 #include "fDiagMatrix.h" |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
36 #include "dMatrix.h" |
1847 | 37 #include "f77-fcn.h" |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
38 #include "fCMatrix.h" |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
39 #include "fMatrix.h" |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
40 #include "lo-error.h" |
10601 | 41 #include "oct-locbuf.h" |
457 | 42 |
43 extern "C" | |
44 { | |
4552 | 45 F77_RET_T |
46 F77_FUNC (dgesvd, DGESVD) (F77_CONST_CHAR_ARG_DECL, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
47 F77_CONST_CHAR_ARG_DECL, |
22133
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
48 const F77_INT&, const F77_INT&, |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
49 F77_DBLE*, const F77_INT&, F77_DBLE*, |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
50 F77_DBLE*, const F77_INT&, F77_DBLE*, |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
51 const F77_INT&, F77_DBLE*, |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
52 const F77_INT&, F77_INT& |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
53 F77_CHAR_ARG_LEN_DECL |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10258
diff
changeset
|
54 F77_CHAR_ARG_LEN_DECL); |
10601 | 55 |
56 F77_RET_T | |
57 F77_FUNC (dgesdd, DGESDD) (F77_CONST_CHAR_ARG_DECL, | |
22133
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
58 const F77_INT&, const F77_INT&, |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
59 F77_DBLE*, const F77_INT&, F77_DBLE*, |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
60 F77_DBLE*, const F77_INT&, F77_DBLE*, |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
61 const F77_INT&, F77_DBLE*, |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
62 const F77_INT&, F77_INT *, |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
63 F77_INT& |
10601 | 64 F77_CHAR_ARG_LEN_DECL); |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
65 |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
66 F77_RET_T |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
67 F77_FUNC (sgesvd, SGESVD) (F77_CONST_CHAR_ARG_DECL, |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
68 F77_CONST_CHAR_ARG_DECL, |
22133
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
69 const F77_INT&, const F77_INT&, |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
70 F77_REAL*, const F77_INT&, F77_REAL*, |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
71 F77_REAL*, const F77_INT&, F77_REAL*, |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
72 const F77_INT&, F77_REAL*, |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
73 const F77_INT&, F77_INT& |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
74 F77_CHAR_ARG_LEN_DECL |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
75 F77_CHAR_ARG_LEN_DECL); |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
76 |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
77 F77_RET_T |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
78 F77_FUNC (sgesdd, SGESDD) (F77_CONST_CHAR_ARG_DECL, |
22133
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
79 const F77_INT&, const F77_INT&, |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
80 F77_REAL*, const F77_INT&, F77_REAL*, |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
81 F77_REAL*, const F77_INT&, F77_REAL*, |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
82 const F77_INT&, F77_REAL*, |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
83 const F77_INT&, F77_INT *, |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
84 F77_INT& |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
85 F77_CHAR_ARG_LEN_DECL); |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
86 |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
87 F77_RET_T |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
88 F77_FUNC (zgesvd, ZGESVD) (F77_CONST_CHAR_ARG_DECL, |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
89 F77_CONST_CHAR_ARG_DECL, |
22133
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
90 const F77_INT&, const F77_INT&, |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
91 F77_DBLE_CMPLX*, const F77_INT&, |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
92 F77_DBLE*, F77_DBLE_CMPLX*, const F77_INT&, |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
93 F77_DBLE_CMPLX*, const F77_INT&, F77_DBLE_CMPLX*, |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
94 const F77_INT&, F77_DBLE*, F77_INT& |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
95 F77_CHAR_ARG_LEN_DECL |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
96 F77_CHAR_ARG_LEN_DECL); |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
97 |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
98 F77_RET_T |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
99 F77_FUNC (zgesdd, ZGESDD) (F77_CONST_CHAR_ARG_DECL, |
22133
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
100 const F77_INT&, const F77_INT&, |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
101 F77_DBLE_CMPLX*, const F77_INT&, |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
102 F77_DBLE*, F77_DBLE_CMPLX*, const F77_INT&, |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
103 F77_DBLE_CMPLX*, const F77_INT&, F77_DBLE_CMPLX*, |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
104 const F77_INT&, F77_DBLE*, |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
105 F77_INT *, F77_INT& |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
106 F77_CHAR_ARG_LEN_DECL); |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
107 F77_RET_T |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
108 F77_FUNC (cgesvd, CGESVD) (F77_CONST_CHAR_ARG_DECL, |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
109 F77_CONST_CHAR_ARG_DECL, |
22133
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
110 const F77_INT&, const F77_INT&, |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
111 F77_CMPLX*, const F77_INT&, F77_REAL*, |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
112 F77_CMPLX*, const F77_INT&, |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
113 F77_CMPLX*, const F77_INT&, |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
114 F77_CMPLX*, const F77_INT&, |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
115 F77_REAL*, F77_INT& |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
116 F77_CHAR_ARG_LEN_DECL |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
117 F77_CHAR_ARG_LEN_DECL); |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
118 |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
119 F77_RET_T |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
120 F77_FUNC (cgesdd, CGESDD) (F77_CONST_CHAR_ARG_DECL, |
22133
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
121 const F77_INT&, const F77_INT&, |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
122 F77_CMPLX*, const F77_INT&, F77_REAL*, |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
123 F77_CMPLX*, const F77_INT&, |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
124 F77_CMPLX*, const F77_INT&, |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
125 F77_CMPLX*, const F77_INT&, |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
126 F77_REAL*, F77_INT *, F77_INT& |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
127 F77_CHAR_ARG_LEN_DECL); |
457 | 128 } |
129 | |
22317
6ca3acf5fad8
move some new numeric classes to namespace octave::math
John W. Eaton <jwe@octave.org>
parents:
22297
diff
changeset
|
130 namespace octave |
6ca3acf5fad8
move some new numeric classes to namespace octave::math
John W. Eaton <jwe@octave.org>
parents:
22297
diff
changeset
|
131 { |
6ca3acf5fad8
move some new numeric classes to namespace octave::math
John W. Eaton <jwe@octave.org>
parents:
22297
diff
changeset
|
132 namespace math |
6ca3acf5fad8
move some new numeric classes to namespace octave::math
John W. Eaton <jwe@octave.org>
parents:
22297
diff
changeset
|
133 { |
6ca3acf5fad8
move some new numeric classes to namespace octave::math
John W. Eaton <jwe@octave.org>
parents:
22297
diff
changeset
|
134 |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
135 template <typename T> |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
136 T |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
137 svd<T>::left_singular_matrix (void) const |
1543 | 138 { |
22228
4afe3705ea75
svd: do not shadow member variables with local variables.
Carnë Draug <carandraug@octave.org>
parents:
22204
diff
changeset
|
139 if (m_type == svd::Type::sigma_only) |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
140 (*current_liboctave_error_handler) |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
141 ("svd: U not computed because type == svd::sigma_only"); |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
142 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
143 return left_sm; |
1543 | 144 } |
145 | |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
146 template <typename T> |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
147 T |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
148 svd<T>::right_singular_matrix (void) const |
1543 | 149 { |
22228
4afe3705ea75
svd: do not shadow member variables with local variables.
Carnë Draug <carandraug@octave.org>
parents:
22204
diff
changeset
|
150 if (m_type == svd::Type::sigma_only) |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
151 (*current_liboctave_error_handler) |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
152 ("svd: V not computed because type == svd::sigma_only"); |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
153 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
154 return right_sm; |
1543 | 155 } |
156 | |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
157 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
158 // GESVD specializations |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
159 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
160 #define GESVD_REAL_STEP(f, F) \ |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
161 F77_XFCN (f, F, (F77_CONST_CHAR_ARG2 (&jobu, 1), \ |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
162 F77_CONST_CHAR_ARG2 (&jobv, 1), \ |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
163 m, n, tmp_data, m1, s_vec, u, m1, vt, \ |
22248
60986498af9e
svd: use std::vector instead of Matrix when a std::vector is enough.
Carnë Draug <carandraug@octave.org>
parents:
22228
diff
changeset
|
164 nrow_vt1, work.data (), lwork, info \ |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
165 F77_CHAR_ARG_LEN (1) \ |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
166 F77_CHAR_ARG_LEN (1))) |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
167 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
168 #define GESVD_COMPLEX_STEP(f, F, CMPLX_ARG) \ |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
169 F77_XFCN (f, F, (F77_CONST_CHAR_ARG2 (&jobu, 1), \ |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
170 F77_CONST_CHAR_ARG2 (&jobv, 1), \ |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
171 m, n, CMPLX_ARG (tmp_data), \ |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
172 m1, s_vec, CMPLX_ARG (u), m1, \ |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
173 CMPLX_ARG (vt), nrow_vt1, \ |
22248
60986498af9e
svd: use std::vector instead of Matrix when a std::vector is enough.
Carnë Draug <carandraug@octave.org>
parents:
22228
diff
changeset
|
174 CMPLX_ARG (work.data ()), \ |
60986498af9e
svd: use std::vector instead of Matrix when a std::vector is enough.
Carnë Draug <carandraug@octave.org>
parents:
22228
diff
changeset
|
175 lwork, rwork.data (), info \ |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
176 F77_CHAR_ARG_LEN (1) \ |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
177 F77_CHAR_ARG_LEN (1))) |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
178 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
179 // DGESVD |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
180 template<> |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
181 void |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
182 svd<Matrix>::gesvd (char& jobu, char& jobv, octave_idx_type m, |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
183 octave_idx_type n, double* tmp_data, octave_idx_type m1, |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
184 double* s_vec, double* u, double* vt, |
22248
60986498af9e
svd: use std::vector instead of Matrix when a std::vector is enough.
Carnë Draug <carandraug@octave.org>
parents:
22228
diff
changeset
|
185 octave_idx_type nrow_vt1, std::vector<double>& work, |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
186 octave_idx_type& lwork, octave_idx_type& info) |
457 | 187 { |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
188 GESVD_REAL_STEP (dgesvd, DGESVD); |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
189 |
22248
60986498af9e
svd: use std::vector instead of Matrix when a std::vector is enough.
Carnë Draug <carandraug@octave.org>
parents:
22228
diff
changeset
|
190 lwork = work[0]; |
60986498af9e
svd: use std::vector instead of Matrix when a std::vector is enough.
Carnë Draug <carandraug@octave.org>
parents:
22228
diff
changeset
|
191 work.reserve (lwork); |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
192 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
193 GESVD_REAL_STEP (dgesvd, DGESVD); |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
194 } |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
195 |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
196 // SGESVD |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
197 template<> |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
198 void |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
199 svd<FloatMatrix>::gesvd (char& jobu, char& jobv, octave_idx_type m, |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
200 octave_idx_type n, float* tmp_data, |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
201 octave_idx_type m1, float* s_vec, float* u, float* vt, |
22248
60986498af9e
svd: use std::vector instead of Matrix when a std::vector is enough.
Carnë Draug <carandraug@octave.org>
parents:
22228
diff
changeset
|
202 octave_idx_type nrow_vt1, std::vector<float>& work, |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
203 octave_idx_type& lwork, octave_idx_type& info) |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
204 { |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
205 GESVD_REAL_STEP (sgesvd, SGESVD); |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
206 |
22248
60986498af9e
svd: use std::vector instead of Matrix when a std::vector is enough.
Carnë Draug <carandraug@octave.org>
parents:
22228
diff
changeset
|
207 lwork = work[0]; |
60986498af9e
svd: use std::vector instead of Matrix when a std::vector is enough.
Carnë Draug <carandraug@octave.org>
parents:
22228
diff
changeset
|
208 work.reserve (lwork); |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
209 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
210 GESVD_REAL_STEP (sgesvd, SGESVD); |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
211 } |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
212 |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
213 // ZGESVD |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
214 template<> |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
215 void |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
216 svd<ComplexMatrix>::gesvd (char& jobu, char& jobv, octave_idx_type m, |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
217 octave_idx_type n, Complex* tmp_data, |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
218 octave_idx_type m1, double* s_vec, Complex* u, |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
219 Complex* vt, octave_idx_type nrow_vt1, |
22248
60986498af9e
svd: use std::vector instead of Matrix when a std::vector is enough.
Carnë Draug <carandraug@octave.org>
parents:
22228
diff
changeset
|
220 std::vector<Complex>& work, |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
221 octave_idx_type& lwork, octave_idx_type& info) |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
222 { |
22248
60986498af9e
svd: use std::vector instead of Matrix when a std::vector is enough.
Carnë Draug <carandraug@octave.org>
parents:
22228
diff
changeset
|
223 std::vector<double> rwork (5 * std::max (m, n)); |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
224 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
225 GESVD_COMPLEX_STEP (zgesvd, ZGESVD, F77_DBLE_CMPLX_ARG); |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
226 |
22248
60986498af9e
svd: use std::vector instead of Matrix when a std::vector is enough.
Carnë Draug <carandraug@octave.org>
parents:
22228
diff
changeset
|
227 lwork = work[0].real (); |
60986498af9e
svd: use std::vector instead of Matrix when a std::vector is enough.
Carnë Draug <carandraug@octave.org>
parents:
22228
diff
changeset
|
228 work.reserve (lwork); |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
229 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
230 GESVD_COMPLEX_STEP (zgesvd, ZGESVD, F77_DBLE_CMPLX_ARG); |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
231 } |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
232 |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
233 // CGESVD |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
234 template<> |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
235 void |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
236 svd<FloatComplexMatrix>::gesvd (char& jobu, char& jobv, |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
237 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:
22135
diff
changeset
|
238 FloatComplex* tmp_data, octave_idx_type m1, |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
239 float* s_vec, FloatComplex* u, |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
240 FloatComplex* vt, octave_idx_type nrow_vt1, |
22248
60986498af9e
svd: use std::vector instead of Matrix when a std::vector is enough.
Carnë Draug <carandraug@octave.org>
parents:
22228
diff
changeset
|
241 std::vector<FloatComplex>& work, |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
242 octave_idx_type& lwork, octave_idx_type& info) |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
243 { |
22248
60986498af9e
svd: use std::vector instead of Matrix when a std::vector is enough.
Carnë Draug <carandraug@octave.org>
parents:
22228
diff
changeset
|
244 std::vector<float> rwork (5 * std::max (m, n)); |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
245 |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
246 GESVD_COMPLEX_STEP (cgesvd, CGESVD, F77_CMPLX_ARG); |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
247 |
22248
60986498af9e
svd: use std::vector instead of Matrix when a std::vector is enough.
Carnë Draug <carandraug@octave.org>
parents:
22228
diff
changeset
|
248 lwork = work[0].real (); |
60986498af9e
svd: use std::vector instead of Matrix when a std::vector is enough.
Carnë Draug <carandraug@octave.org>
parents:
22228
diff
changeset
|
249 work.reserve (lwork); |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
250 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
251 GESVD_COMPLEX_STEP (cgesvd, CGESVD, F77_CMPLX_ARG); |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
252 } |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
253 |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
254 #undef GESVD_REAL_STEP |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
255 #undef GESVD_COMPLEX_STEP |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
256 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
257 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
258 // GESDD specializations |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
259 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
260 #define GESDD_REAL_STEP(f, F) \ |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
261 F77_XFCN (f, F, (F77_CONST_CHAR_ARG2 (&jobz, 1), \ |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
262 m, n, tmp_data, m1, s_vec, u, m1, vt, nrow_vt1, \ |
22248
60986498af9e
svd: use std::vector instead of Matrix when a std::vector is enough.
Carnë Draug <carandraug@octave.org>
parents:
22228
diff
changeset
|
263 work.data (), lwork, iwork, info \ |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
264 F77_CHAR_ARG_LEN (1))) |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
265 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
266 #define GESDD_COMPLEX_STEP(f, F, CMPLX_ARG) \ |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
267 F77_XFCN (f, F, (F77_CONST_CHAR_ARG2 (&jobz, 1), m, n, \ |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
268 CMPLX_ARG (tmp_data), m1, \ |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
269 s_vec, CMPLX_ARG (u), m1, \ |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
270 CMPLX_ARG (vt), nrow_vt1, \ |
22248
60986498af9e
svd: use std::vector instead of Matrix when a std::vector is enough.
Carnë Draug <carandraug@octave.org>
parents:
22228
diff
changeset
|
271 CMPLX_ARG (work.data ()), lwork, \ |
60986498af9e
svd: use std::vector instead of Matrix when a std::vector is enough.
Carnë Draug <carandraug@octave.org>
parents:
22228
diff
changeset
|
272 rwork.data (), iwork, info \ |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
273 F77_CHAR_ARG_LEN (1))) |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
274 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
275 // DGESDD |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
276 template<> |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
277 void |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
278 svd<Matrix>::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:
22135
diff
changeset
|
279 double* tmp_data, octave_idx_type m1, |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
280 double* s_vec, double* u, |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
281 double* vt, octave_idx_type nrow_vt1, |
22248
60986498af9e
svd: use std::vector instead of Matrix when a std::vector is enough.
Carnë Draug <carandraug@octave.org>
parents:
22228
diff
changeset
|
282 std::vector<double>& work, octave_idx_type& lwork, |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
283 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:
22135
diff
changeset
|
284 { |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
285 GESDD_REAL_STEP (dgesdd, DGESDD); |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
286 |
22248
60986498af9e
svd: use std::vector instead of Matrix when a std::vector is enough.
Carnë Draug <carandraug@octave.org>
parents:
22228
diff
changeset
|
287 lwork = work[0]; |
60986498af9e
svd: use std::vector instead of Matrix when a std::vector is enough.
Carnë Draug <carandraug@octave.org>
parents:
22228
diff
changeset
|
288 work.reserve (lwork); |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
289 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
290 GESDD_REAL_STEP (dgesdd, DGESDD); |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
291 } |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
292 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
293 // SGESDD |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
294 template<> |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
295 void |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
296 svd<FloatMatrix>::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:
22135
diff
changeset
|
297 float* tmp_data, octave_idx_type m1, |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
298 float* s_vec, float* u, |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
299 float* vt, octave_idx_type nrow_vt1, |
22248
60986498af9e
svd: use std::vector instead of Matrix when a std::vector is enough.
Carnë Draug <carandraug@octave.org>
parents:
22228
diff
changeset
|
300 std::vector<float>& work, octave_idx_type& lwork, |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
301 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:
22135
diff
changeset
|
302 { |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
303 GESDD_REAL_STEP (sgesdd, SGESDD); |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
304 |
22248
60986498af9e
svd: use std::vector instead of Matrix when a std::vector is enough.
Carnë Draug <carandraug@octave.org>
parents:
22228
diff
changeset
|
305 lwork = work[0]; |
60986498af9e
svd: use std::vector instead of Matrix when a std::vector is enough.
Carnë Draug <carandraug@octave.org>
parents:
22228
diff
changeset
|
306 work.reserve (lwork); |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
307 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
308 GESDD_REAL_STEP (sgesdd, SGESDD); |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
309 } |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
310 |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
311 // ZGESDD |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
312 template<> |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
313 void |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
314 svd<ComplexMatrix>::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:
22135
diff
changeset
|
315 Complex* tmp_data, octave_idx_type m1, |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
316 double* s_vec, Complex* u, |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
317 Complex* vt, octave_idx_type nrow_vt1, |
22248
60986498af9e
svd: use std::vector instead of Matrix when a std::vector is enough.
Carnë Draug <carandraug@octave.org>
parents:
22228
diff
changeset
|
318 std::vector<Complex>& work, octave_idx_type& lwork, |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
319 octave_idx_type* iwork, octave_idx_type& info) |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
320 { |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
321 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
322 octave_idx_type min_mn = std::min (m, n); |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
323 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
324 octave_idx_type lrwork; |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
325 if (jobz == 'N') |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
326 lrwork = 7*min_mn; |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
327 else |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
328 lrwork = 5*min_mn*min_mn + 5*min_mn; |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
329 |
22248
60986498af9e
svd: use std::vector instead of Matrix when a std::vector is enough.
Carnë Draug <carandraug@octave.org>
parents:
22228
diff
changeset
|
330 std::vector<double> rwork (lrwork); |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
331 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
332 GESDD_COMPLEX_STEP (zgesdd, ZGESDD, F77_DBLE_CMPLX_ARG); |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
333 |
22248
60986498af9e
svd: use std::vector instead of Matrix when a std::vector is enough.
Carnë Draug <carandraug@octave.org>
parents:
22228
diff
changeset
|
334 lwork = work[0].real (); |
60986498af9e
svd: use std::vector instead of Matrix when a std::vector is enough.
Carnë Draug <carandraug@octave.org>
parents:
22228
diff
changeset
|
335 work.reserve (lwork); |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
336 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
337 GESDD_COMPLEX_STEP (zgesdd, ZGESDD, F77_DBLE_CMPLX_ARG); |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
338 } |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
339 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
340 // CGESDD |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
341 template<> |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
342 void |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
343 svd<FloatComplexMatrix>::gesdd (char& jobz, octave_idx_type m, |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
344 octave_idx_type n, |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
345 FloatComplex* tmp_data, octave_idx_type m1, |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
346 float* s_vec, FloatComplex* u, |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
347 FloatComplex* vt, octave_idx_type nrow_vt1, |
22248
60986498af9e
svd: use std::vector instead of Matrix when a std::vector is enough.
Carnë Draug <carandraug@octave.org>
parents:
22228
diff
changeset
|
348 std::vector<FloatComplex>& work, |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
349 octave_idx_type& lwork, octave_idx_type* iwork, |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
350 octave_idx_type& info) |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
351 { |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
352 octave_idx_type min_mn = std::min (m, n); |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
353 octave_idx_type max_mn = std::max (m, n); |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
354 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
355 octave_idx_type lrwork; |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
356 if (jobz == 'N') |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
357 lrwork = 5*min_mn; |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
358 else |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
359 lrwork = min_mn * std::max (5*min_mn+7, 2*max_mn+2*min_mn+1); |
22248
60986498af9e
svd: use std::vector instead of Matrix when a std::vector is enough.
Carnë Draug <carandraug@octave.org>
parents:
22228
diff
changeset
|
360 std::vector<float> rwork (lrwork); |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
361 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
362 GESDD_COMPLEX_STEP (cgesdd, CGESDD, F77_CMPLX_ARG); |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
363 |
22248
60986498af9e
svd: use std::vector instead of Matrix when a std::vector is enough.
Carnë Draug <carandraug@octave.org>
parents:
22228
diff
changeset
|
364 lwork = work[0].real (); |
60986498af9e
svd: use std::vector instead of Matrix when a std::vector is enough.
Carnë Draug <carandraug@octave.org>
parents:
22228
diff
changeset
|
365 work.reserve (lwork); |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
366 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
367 GESDD_COMPLEX_STEP (cgesdd, CGESDD, F77_CMPLX_ARG); |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
368 } |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
369 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
370 #undef GESDD_REAL_STEP |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
371 #undef GESDD_COMPLEX_STEP |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
372 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
373 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
374 template<typename T> |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
375 svd<T>::svd (const T& a, svd::Type type, |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
376 svd::Driver driver) |
22228
4afe3705ea75
svd: do not shadow member variables with local variables.
Carnë Draug <carandraug@octave.org>
parents:
22204
diff
changeset
|
377 : m_type (type), m_driver (driver), left_sm (), sigma (), right_sm () |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
378 { |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
379 octave_idx_type info; |
457 | 380 |
5275 | 381 octave_idx_type m = a.rows (); |
382 octave_idx_type n = a.cols (); | |
457 | 383 |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
384 if (m == 0 || n == 0) |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
385 { |
22228
4afe3705ea75
svd: do not shadow member variables with local variables.
Carnë Draug <carandraug@octave.org>
parents:
22204
diff
changeset
|
386 switch (m_type) |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
387 { |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
388 case svd::Type::std: |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
389 left_sm = T (m, m, 0); |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
390 for (octave_idx_type i = 0; i < m; i++) |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
391 left_sm.xelem (i, i) = 1; |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
392 sigma = DM_T (m, n); |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
393 right_sm = T (n, n, 0); |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
394 for (octave_idx_type i = 0; i < n; i++) |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
395 right_sm.xelem (i, i) = 1; |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
396 break; |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
397 |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
398 case svd::Type::economy: |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
399 left_sm = T (m, 0, 0); |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
400 sigma = DM_T (0, 0); |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
401 right_sm = T (0, n, 0); |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
402 break; |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
403 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
404 case svd::Type::sigma_only: |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
405 default: |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
406 sigma = DM_T (0, 1); |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
407 break; |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
408 } |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
409 return; |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
410 } |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
411 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
412 T atmp = a; |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
413 P* tmp_data = atmp.fortran_vec (); |
457 | 414 |
5275 | 415 octave_idx_type min_mn = m < n ? m : n; |
457 | 416 |
1930 | 417 char jobu = 'A'; |
418 char jobv = 'A'; | |
537 | 419 |
5275 | 420 octave_idx_type ncol_u = m; |
421 octave_idx_type nrow_vt = n; | |
422 octave_idx_type nrow_s = m; | |
423 octave_idx_type ncol_s = n; | |
537 | 424 |
22228
4afe3705ea75
svd: do not shadow member variables with local variables.
Carnë Draug <carandraug@octave.org>
parents:
22204
diff
changeset
|
425 switch (m_type) |
537 | 426 { |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
427 case svd::Type::economy: |
1930 | 428 jobu = jobv = 'S'; |
537 | 429 ncol_u = nrow_vt = nrow_s = ncol_s = min_mn; |
1543 | 430 break; |
431 | |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
432 case svd::Type::sigma_only: |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
433 |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
434 // Note: for this case, both jobu and jobv should be 'N', but |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
435 // there seems to be a bug in dgesvd from Lapack V2.0. To |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
436 // demonstrate the bug, set both jobu and jobv to 'N' and find |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
437 // the singular values of [eye(3), eye(3)]. The result is |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
438 // [-sqrt(2), -sqrt(2), -sqrt(2)]. |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
439 // |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
440 // For Lapack 3.0, this problem seems to be fixed. |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
441 |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
442 jobu = jobv = 'N'; |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
443 ncol_u = nrow_vt = 1; |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
444 break; |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
445 |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
446 default: |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
447 break; |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
448 } |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
449 |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
450 if (! (jobu == 'N' || jobu == 'O')) |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
451 left_sm.resize (m, ncol_u); |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
452 |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
453 P* u = left_sm.fortran_vec (); |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
454 |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
455 sigma.resize (nrow_s, ncol_s); |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
456 DM_P* s_vec = sigma.fortran_vec (); |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
457 |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
458 if (! (jobv == 'N' || jobv == 'O')) |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
459 right_sm.resize (nrow_vt, n); |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
460 |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
461 P* vt = right_sm.fortran_vec (); |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
462 |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
463 // Query _GESVD for the correct dimension of WORK. |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
464 |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
465 octave_idx_type lwork = -1; |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
466 |
22248
60986498af9e
svd: use std::vector instead of Matrix when a std::vector is enough.
Carnë Draug <carandraug@octave.org>
parents:
22228
diff
changeset
|
467 std::vector<P> work (1); |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
468 |
22297
bc2a5db96754
Resolve compile time issues, when octave_idx_type is long int.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22249
diff
changeset
|
469 octave_idx_type m1 = std::max (m, static_cast<octave_idx_type> (1)); |
bc2a5db96754
Resolve compile time issues, when octave_idx_type is long int.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22249
diff
changeset
|
470 octave_idx_type nrow_vt1 = std::max (nrow_vt, |
bc2a5db96754
Resolve compile time issues, when octave_idx_type is long int.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22249
diff
changeset
|
471 static_cast<octave_idx_type> (1)); |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
472 |
22228
4afe3705ea75
svd: do not shadow member variables with local variables.
Carnë Draug <carandraug@octave.org>
parents:
22204
diff
changeset
|
473 if (m_driver == svd::Driver::GESVD) |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
474 gesvd (jobu, jobv, m, n, tmp_data, m1, s_vec, u, vt, nrow_vt1, |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
475 work, lwork, info); |
22228
4afe3705ea75
svd: do not shadow member variables with local variables.
Carnë Draug <carandraug@octave.org>
parents:
22204
diff
changeset
|
476 else if (m_driver == svd::Driver::GESDD) |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
477 { |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
478 assert (jobu == jobv); |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
479 char jobz = jobu; |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
480 |
22248
60986498af9e
svd: use std::vector instead of Matrix when a std::vector is enough.
Carnë Draug <carandraug@octave.org>
parents:
22228
diff
changeset
|
481 std::vector<octave_idx_type> iwork (8 * std::min (m, n)); |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
482 |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
483 gesdd (jobz, m, n, tmp_data, m1, s_vec, u, vt, nrow_vt1, |
22248
60986498af9e
svd: use std::vector instead of Matrix when a std::vector is enough.
Carnë Draug <carandraug@octave.org>
parents:
22228
diff
changeset
|
484 work, lwork, iwork.data (), info); |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
485 } |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
486 else |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
487 abort (); |
3336 | 488 |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
489 if (! (jobv == 'N' || jobv == 'O')) |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
490 right_sm = right_sm.transpose (); |
457 | 491 } |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
492 |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
493 // Instantiations we need. |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
494 |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
495 template class svd<Matrix>; |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
496 |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
497 template class svd<FloatMatrix>; |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
498 |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
499 template class svd<ComplexMatrix>; |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
500 |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
501 template class svd<FloatComplexMatrix>; |
22317
6ca3acf5fad8
move some new numeric classes to namespace octave::math
John W. Eaton <jwe@octave.org>
parents:
22297
diff
changeset
|
502 |
6ca3acf5fad8
move some new numeric classes to namespace octave::math
John W. Eaton <jwe@octave.org>
parents:
22297
diff
changeset
|
503 } |
6ca3acf5fad8
move some new numeric classes to namespace octave::math
John W. Eaton <jwe@octave.org>
parents:
22297
diff
changeset
|
504 } |