Mercurial > octave
annotate liboctave/numeric/svd.cc @ 22323:bac0d6f07a3e
maint: Update copyright notices for 2016.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 17 Aug 2016 01:05:19 -0400 |
parents | 93b3cdd36854 |
children | 7f3c7a8bd131 |
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 |
22323
bac0d6f07a3e
maint: Update copyright notices for 2016.
John W. Eaton <jwe@octave.org>
parents:
22322
diff
changeset
|
4 Copyright (C) 1994-2016 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" |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
37 #include "fCMatrix.h" |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
38 #include "fMatrix.h" |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
39 #include "lo-error.h" |
22322
93b3cdd36854
move most f77 function decls to separate header files
John W. Eaton <jwe@octave.org>
parents:
22317
diff
changeset
|
40 #include "lo-lapack-proto.h" |
10601 | 41 #include "oct-locbuf.h" |
457 | 42 |
22317
6ca3acf5fad8
move some new numeric classes to namespace octave::math
John W. Eaton <jwe@octave.org>
parents:
22297
diff
changeset
|
43 namespace octave |
6ca3acf5fad8
move some new numeric classes to namespace octave::math
John W. Eaton <jwe@octave.org>
parents:
22297
diff
changeset
|
44 { |
6ca3acf5fad8
move some new numeric classes to namespace octave::math
John W. Eaton <jwe@octave.org>
parents:
22297
diff
changeset
|
45 namespace math |
6ca3acf5fad8
move some new numeric classes to namespace octave::math
John W. Eaton <jwe@octave.org>
parents:
22297
diff
changeset
|
46 { |
6ca3acf5fad8
move some new numeric classes to namespace octave::math
John W. Eaton <jwe@octave.org>
parents:
22297
diff
changeset
|
47 |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
48 template <typename T> |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
49 T |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
50 svd<T>::left_singular_matrix (void) const |
1543 | 51 { |
22228
4afe3705ea75
svd: do not shadow member variables with local variables.
Carnë Draug <carandraug@octave.org>
parents:
22204
diff
changeset
|
52 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
|
53 (*current_liboctave_error_handler) |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
54 ("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
|
55 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
56 return left_sm; |
1543 | 57 } |
58 | |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
59 template <typename T> |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
60 T |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
61 svd<T>::right_singular_matrix (void) const |
1543 | 62 { |
22228
4afe3705ea75
svd: do not shadow member variables with local variables.
Carnë Draug <carandraug@octave.org>
parents:
22204
diff
changeset
|
63 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
|
64 (*current_liboctave_error_handler) |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
65 ("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
|
66 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
67 return right_sm; |
1543 | 68 } |
69 | |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
70 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
71 // GESVD specializations |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
72 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
73 #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
|
74 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
|
75 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
|
76 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
|
77 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
|
78 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
|
79 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
|
80 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
81 #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
|
82 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
|
83 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
|
84 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
|
85 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
|
86 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
|
87 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
|
88 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
|
89 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
|
90 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
|
91 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
92 // DGESVD |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
93 template<> |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
94 void |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
95 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
|
96 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
|
97 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
|
98 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
|
99 octave_idx_type& lwork, octave_idx_type& info) |
457 | 100 { |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
101 GESVD_REAL_STEP (dgesvd, DGESVD); |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
102 |
22248
60986498af9e
svd: use std::vector instead of Matrix when a std::vector is enough.
Carnë Draug <carandraug@octave.org>
parents:
22228
diff
changeset
|
103 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
|
104 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
|
105 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
106 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
|
107 } |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
108 |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
109 // SGESVD |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
110 template<> |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
111 void |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
112 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
|
113 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
|
114 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
|
115 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
|
116 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
|
117 { |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
118 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
|
119 |
22248
60986498af9e
svd: use std::vector instead of Matrix when a std::vector is enough.
Carnë Draug <carandraug@octave.org>
parents:
22228
diff
changeset
|
120 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
|
121 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
|
122 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
123 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
|
124 } |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
125 |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
126 // ZGESVD |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
127 template<> |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
128 void |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
129 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
|
130 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
|
131 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
|
132 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
|
133 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
|
134 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
|
135 { |
22248
60986498af9e
svd: use std::vector instead of Matrix when a std::vector is enough.
Carnë Draug <carandraug@octave.org>
parents:
22228
diff
changeset
|
136 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
|
137 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
138 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
|
139 |
22248
60986498af9e
svd: use std::vector instead of Matrix when a std::vector is enough.
Carnë Draug <carandraug@octave.org>
parents:
22228
diff
changeset
|
140 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
|
141 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
|
142 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
143 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
|
144 } |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
145 |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
146 // CGESVD |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
147 template<> |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
148 void |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
149 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
|
150 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
|
151 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
|
152 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
|
153 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
|
154 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
|
155 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
|
156 { |
22248
60986498af9e
svd: use std::vector instead of Matrix when a std::vector is enough.
Carnë Draug <carandraug@octave.org>
parents:
22228
diff
changeset
|
157 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
|
158 |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
159 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
|
160 |
22248
60986498af9e
svd: use std::vector instead of Matrix when a std::vector is enough.
Carnë Draug <carandraug@octave.org>
parents:
22228
diff
changeset
|
161 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
|
162 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
|
163 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
164 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
|
165 } |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
166 |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
167 #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
|
168 #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
|
169 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
170 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
171 // GESDD specializations |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
172 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
173 #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
|
174 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
|
175 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
|
176 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
|
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 #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
|
180 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
|
181 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
|
182 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
|
183 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
|
184 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
|
185 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
|
186 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
|
187 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
188 // DGESDD |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
189 template<> |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
190 void |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
191 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
|
192 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
|
193 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
|
194 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
|
195 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
|
196 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
|
197 { |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
198 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
|
199 |
22248
60986498af9e
svd: use std::vector instead of Matrix when a std::vector is enough.
Carnë Draug <carandraug@octave.org>
parents:
22228
diff
changeset
|
200 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
|
201 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
|
202 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
203 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
|
204 } |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
205 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
206 // SGESDD |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
207 template<> |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
208 void |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
209 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
|
210 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
|
211 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
|
212 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
|
213 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
|
214 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
|
215 { |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
216 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
|
217 |
22248
60986498af9e
svd: use std::vector instead of Matrix when a std::vector is enough.
Carnë Draug <carandraug@octave.org>
parents:
22228
diff
changeset
|
218 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
|
219 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
|
220 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
221 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
|
222 } |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
223 |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
224 // ZGESDD |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
225 template<> |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
226 void |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
227 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
|
228 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
|
229 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
|
230 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
|
231 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
|
232 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
|
233 { |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
234 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
235 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
|
236 |
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 lrwork; |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
238 if (jobz == 'N') |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
239 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
|
240 else |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
241 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
|
242 |
22248
60986498af9e
svd: use std::vector instead of Matrix when a std::vector is enough.
Carnë Draug <carandraug@octave.org>
parents:
22228
diff
changeset
|
243 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
|
244 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
245 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
|
246 |
22248
60986498af9e
svd: use std::vector instead of Matrix when a std::vector is enough.
Carnë Draug <carandraug@octave.org>
parents:
22228
diff
changeset
|
247 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
|
248 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
|
249 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
250 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
|
251 } |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
252 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
253 // CGESDD |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
254 template<> |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
255 void |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
256 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
|
257 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
|
258 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
|
259 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
|
260 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
|
261 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
|
262 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
|
263 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
|
264 { |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
265 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
|
266 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
|
267 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
268 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
|
269 if (jobz == 'N') |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
270 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
|
271 else |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
272 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
|
273 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
|
274 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
275 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
|
276 |
22248
60986498af9e
svd: use std::vector instead of Matrix when a std::vector is enough.
Carnë Draug <carandraug@octave.org>
parents:
22228
diff
changeset
|
277 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
|
278 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
|
279 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
280 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
|
281 } |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
282 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
283 #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
|
284 #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
|
285 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
286 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
287 template<typename T> |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
288 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
|
289 svd::Driver driver) |
22228
4afe3705ea75
svd: do not shadow member variables with local variables.
Carnë Draug <carandraug@octave.org>
parents:
22204
diff
changeset
|
290 : 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
|
291 { |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
292 octave_idx_type info; |
457 | 293 |
5275 | 294 octave_idx_type m = a.rows (); |
295 octave_idx_type n = a.cols (); | |
457 | 296 |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
297 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
|
298 { |
22228
4afe3705ea75
svd: do not shadow member variables with local variables.
Carnë Draug <carandraug@octave.org>
parents:
22204
diff
changeset
|
299 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
|
300 { |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
301 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
|
302 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
|
303 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
|
304 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
|
305 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
|
306 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
|
307 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
|
308 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
|
309 break; |
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 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
|
312 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
|
313 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
|
314 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
|
315 break; |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
316 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
317 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
|
318 default: |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
319 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
|
320 break; |
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 return; |
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 |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
325 T atmp = a; |
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
326 P* tmp_data = atmp.fortran_vec (); |
457 | 327 |
5275 | 328 octave_idx_type min_mn = m < n ? m : n; |
457 | 329 |
1930 | 330 char jobu = 'A'; |
331 char jobv = 'A'; | |
537 | 332 |
5275 | 333 octave_idx_type ncol_u = m; |
334 octave_idx_type nrow_vt = n; | |
335 octave_idx_type nrow_s = m; | |
336 octave_idx_type ncol_s = n; | |
537 | 337 |
22228
4afe3705ea75
svd: do not shadow member variables with local variables.
Carnë Draug <carandraug@octave.org>
parents:
22204
diff
changeset
|
338 switch (m_type) |
537 | 339 { |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
340 case svd::Type::economy: |
1930 | 341 jobu = jobv = 'S'; |
537 | 342 ncol_u = nrow_vt = nrow_s = ncol_s = min_mn; |
1543 | 343 break; |
344 | |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
345 case svd::Type::sigma_only: |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
346 |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
347 // 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
|
348 // 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
|
349 // 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
|
350 // 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
|
351 // [-sqrt(2), -sqrt(2), -sqrt(2)]. |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
352 // |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
353 // 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
|
354 |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
355 jobu = jobv = 'N'; |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
356 ncol_u = nrow_vt = 1; |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
357 break; |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
358 |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
359 default: |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
360 break; |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
361 } |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
362 |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
363 if (! (jobu == 'N' || jobu == 'O')) |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
364 left_sm.resize (m, ncol_u); |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
365 |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
366 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
|
367 |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
368 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
|
369 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
|
370 |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
371 if (! (jobv == 'N' || jobv == 'O')) |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
372 right_sm.resize (nrow_vt, n); |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
373 |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
374 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
|
375 |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
376 // 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
|
377 |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
378 octave_idx_type lwork = -1; |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
379 |
22248
60986498af9e
svd: use std::vector instead of Matrix when a std::vector is enough.
Carnë Draug <carandraug@octave.org>
parents:
22228
diff
changeset
|
380 std::vector<P> work (1); |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
381 |
22297
bc2a5db96754
Resolve compile time issues, when octave_idx_type is long int.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22249
diff
changeset
|
382 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
|
383 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
|
384 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
|
385 |
22228
4afe3705ea75
svd: do not shadow member variables with local variables.
Carnë Draug <carandraug@octave.org>
parents:
22204
diff
changeset
|
386 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
|
387 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
|
388 work, lwork, info); |
22228
4afe3705ea75
svd: do not shadow member variables with local variables.
Carnë Draug <carandraug@octave.org>
parents:
22204
diff
changeset
|
389 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
|
390 { |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
391 assert (jobu == jobv); |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
392 char jobz = jobu; |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
393 |
22248
60986498af9e
svd: use std::vector instead of Matrix when a std::vector is enough.
Carnë Draug <carandraug@octave.org>
parents:
22228
diff
changeset
|
394 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
|
395 |
22204
469c817eb256
svd: reduce code duplication with more use of template and macro.
Carnë Draug <carandraug@octave.org>
parents:
22135
diff
changeset
|
396 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
|
397 work, lwork, iwork.data (), info); |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
398 } |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
399 else |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
400 abort (); |
3336 | 401 |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
402 if (! (jobv == 'N' || jobv == 'O')) |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
403 right_sm = right_sm.transpose (); |
457 | 404 } |
21273
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
405 |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
406 // Instantiations we need. |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
407 |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
408 template class svd<Matrix>; |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
409 |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
410 template class svd<FloatMatrix>; |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
411 |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
412 template class svd<ComplexMatrix>; |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
413 |
cbced1c09916
better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
414 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
|
415 |
6ca3acf5fad8
move some new numeric classes to namespace octave::math
John W. Eaton <jwe@octave.org>
parents:
22297
diff
changeset
|
416 } |
6ca3acf5fad8
move some new numeric classes to namespace octave::math
John W. Eaton <jwe@octave.org>
parents:
22297
diff
changeset
|
417 } |