457
|
1 // -*- C++ -*- |
|
2 /* |
|
3 |
1011
|
4 Copyright (C) 1992, 1993, 1994, 1995 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 |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
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 |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
1315
|
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
457
|
21 |
|
22 */ |
|
23 |
1296
|
24 #if defined (__GNUG__) |
|
25 #pragma implementation |
|
26 #endif |
|
27 |
457
|
28 #ifdef HAVE_CONFIG_H |
1192
|
29 #include <config.h> |
457
|
30 #endif |
|
31 |
|
32 #include "CmplxSVD.h" |
1368
|
33 #include "f77-uscore.h" |
457
|
34 #include "mx-inlines.cc" |
|
35 |
|
36 extern "C" |
|
37 { |
1253
|
38 int F77_FCN (zgesvd, ZGESVD) (const char*, const char*, const int&, |
|
39 const int&, Complex*, const int&, |
|
40 double*, Complex*, const int&, |
|
41 Complex*, const int&, Complex*, |
|
42 const int&, double*, int&, long, |
|
43 long); |
457
|
44 } |
|
45 |
|
46 int |
537
|
47 ComplexSVD::init (const ComplexMatrix& a, SVD::type svd_type) |
457
|
48 { |
|
49 int info; |
|
50 |
|
51 int m = a.rows (); |
|
52 int n = a.cols (); |
|
53 |
|
54 Complex *tmp_data = dup (a.data (), a.length ()); |
|
55 |
|
56 int min_mn = m < n ? m : n; |
|
57 int max_mn = m > n ? m : n; |
|
58 |
1251
|
59 char *jobu = "A"; |
|
60 char *jobv = "A"; |
537
|
61 |
|
62 int ncol_u = m; |
|
63 int nrow_vt = n; |
|
64 int nrow_s = m; |
|
65 int ncol_s = n; |
|
66 |
|
67 if (svd_type == SVD::economy) |
|
68 { |
1251
|
69 jobu = jobv = "S"; |
537
|
70 ncol_u = nrow_vt = nrow_s = ncol_s = min_mn; |
|
71 } |
|
72 |
|
73 Complex *u = new Complex[m * ncol_u]; |
457
|
74 double *s_vec = new double[min_mn]; |
537
|
75 Complex *vt = new Complex[nrow_vt * n]; |
457
|
76 |
|
77 int lwork = 2*min_mn + max_mn; |
|
78 Complex *work = new Complex[lwork]; |
|
79 |
|
80 int lrwork = 5*max_mn; |
|
81 double *rwork = new double[lrwork]; |
|
82 |
1253
|
83 F77_FCN (zgesvd, ZGESVD) (jobu, jobv, m, n, tmp_data, m, s_vec, u, |
|
84 m, vt, nrow_vt, work, lwork, rwork, info, |
|
85 1L, 1L); |
457
|
86 |
537
|
87 left_sm = ComplexMatrix (u, m, ncol_u); |
|
88 sigma = DiagMatrix (s_vec, nrow_s, ncol_s); |
|
89 ComplexMatrix vt_m (vt, nrow_vt, n); |
|
90 right_sm = vt_m.hermitian (); |
457
|
91 |
|
92 delete [] tmp_data; |
|
93 delete [] work; |
|
94 |
|
95 return info; |
|
96 } |
|
97 |
|
98 /* |
|
99 ;;; Local Variables: *** |
|
100 ;;; mode: C++ *** |
|
101 ;;; page-delimiter: "^/\\*" *** |
|
102 ;;; End: *** |
|
103 */ |