457
|
1 // -*- C++ -*- |
|
2 /* |
|
3 |
|
4 Copyright (C) 1992, 1993, 1994 John W. Eaton |
|
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 |
|
20 Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include "config.h" |
|
26 #endif |
|
27 |
|
28 #if defined (__GNUG__) |
|
29 #pragma implementation |
|
30 #endif |
|
31 |
|
32 #include "CmplxSVD.h" |
|
33 #include "mx-inlines.cc" |
|
34 #include "f77-uscore.h" |
|
35 |
|
36 extern "C" |
|
37 { |
|
38 int F77_FCN (zgesvd) (const char*, const char*, const int*, |
|
39 const int*, Complex*, const int*, double*, |
|
40 Complex*, const int*, Complex*, const int*, |
|
41 Complex*, const int*, double*, int*, long, long); |
|
42 } |
|
43 |
|
44 int |
|
45 ComplexSVD::init (const ComplexMatrix& a) |
|
46 { |
|
47 int info; |
|
48 |
|
49 int m = a.rows (); |
|
50 int n = a.cols (); |
|
51 |
|
52 char jobu = 'A'; |
|
53 char jobv = 'A'; |
|
54 |
|
55 Complex *tmp_data = dup (a.data (), a.length ()); |
|
56 |
|
57 int min_mn = m < n ? m : n; |
|
58 int max_mn = m > n ? m : n; |
|
59 |
|
60 Complex *u = new Complex[m*m]; |
|
61 double *s_vec = new double[min_mn]; |
|
62 Complex *vt = new Complex[n*n]; |
|
63 |
|
64 int lwork = 2*min_mn + max_mn; |
|
65 Complex *work = new Complex[lwork]; |
|
66 |
|
67 int lrwork = 5*max_mn; |
|
68 double *rwork = new double[lrwork]; |
|
69 |
|
70 F77_FCN (zgesvd) (&jobu, &jobv, &m, &n, tmp_data, &m, s_vec, u, &m, |
|
71 vt, &n, work, &lwork, rwork, &info, 1L, 1L); |
|
72 |
|
73 left_sm = ComplexMatrix (u, m, m); |
|
74 sigma = DiagMatrix (s_vec, m, n); |
|
75 ComplexMatrix vt_m (vt, n, n); |
|
76 right_sm = ComplexMatrix (vt_m.hermitian ()); |
|
77 |
|
78 delete [] tmp_data; |
|
79 delete [] work; |
|
80 |
|
81 return info; |
|
82 } |
|
83 |
|
84 /* |
|
85 ;;; Local Variables: *** |
|
86 ;;; mode: C++ *** |
|
87 ;;; page-delimiter: "^/\\*" *** |
|
88 ;;; End: *** |
|
89 */ |