comparison liboctave/CmplxQRP.cc @ 5275:23b37da9fd5b

[project @ 2005-04-08 16:07:35 by jwe]
author jwe
date Fri, 08 Apr 2005 16:07:37 +0000
parents e35b034d3523
children 4c8a2e4e0717
comparison
equal deleted inserted replaced
5274:eae7b40388e9 5275:23b37da9fd5b
31 #include "lo-error.h" 31 #include "lo-error.h"
32 32
33 extern "C" 33 extern "C"
34 { 34 {
35 F77_RET_T 35 F77_RET_T
36 F77_FUNC (zgeqpf, ZGEQPF) (const int&, const int&, Complex*, 36 F77_FUNC (zgeqpf, ZGEQPF) (const octave_idx_type&, const octave_idx_type&, Complex*,
37 const int&, int*, Complex*, Complex*, 37 const octave_idx_type&, octave_idx_type*, Complex*, Complex*,
38 double*, int&); 38 double*, octave_idx_type&);
39 39
40 F77_RET_T 40 F77_RET_T
41 F77_FUNC (zungqr, ZUNGQR) (const int&, const int&, const int&, 41 F77_FUNC (zungqr, ZUNGQR) (const octave_idx_type&, const octave_idx_type&, const octave_idx_type&,
42 Complex*, const int&, Complex*, 42 Complex*, const octave_idx_type&, Complex*,
43 Complex*, const int&, int&); 43 Complex*, const octave_idx_type&, octave_idx_type&);
44 } 44 }
45 45
46 // It would be best to share some of this code with ComplexQR class... 46 // It would be best to share some of this code with ComplexQR class...
47 47
48 ComplexQRP::ComplexQRP (const ComplexMatrix& a, QR::type qr_type) 48 ComplexQRP::ComplexQRP (const ComplexMatrix& a, QR::type qr_type)
54 void 54 void
55 ComplexQRP::init (const ComplexMatrix& a, QR::type qr_type) 55 ComplexQRP::init (const ComplexMatrix& a, QR::type qr_type)
56 { 56 {
57 assert (qr_type != QR::raw); 57 assert (qr_type != QR::raw);
58 58
59 int m = a.rows (); 59 octave_idx_type m = a.rows ();
60 int n = a.cols (); 60 octave_idx_type n = a.cols ();
61 61
62 if (m == 0 || n == 0) 62 if (m == 0 || n == 0)
63 { 63 {
64 (*current_liboctave_error_handler) 64 (*current_liboctave_error_handler)
65 ("ComplexQR must have non-empty matrix"); 65 ("ComplexQR must have non-empty matrix");
66 return; 66 return;
67 } 67 }
68 68
69 int min_mn = m < n ? m : n; 69 octave_idx_type min_mn = m < n ? m : n;
70 Array<Complex> tau (min_mn); 70 Array<Complex> tau (min_mn);
71 Complex *ptau = tau.fortran_vec (); 71 Complex *ptau = tau.fortran_vec ();
72 72
73 int lwork = 3*n > 32*m ? 3*n : 32*m; 73 octave_idx_type lwork = 3*n > 32*m ? 3*n : 32*m;
74 Array<Complex> work (lwork); 74 Array<Complex> work (lwork);
75 Complex *pwork = work.fortran_vec (); 75 Complex *pwork = work.fortran_vec ();
76 76
77 int info = 0; 77 octave_idx_type info = 0;
78 78
79 ComplexMatrix A_fact = a; 79 ComplexMatrix A_fact = a;
80 if (m > n && qr_type != QR::economy) 80 if (m > n && qr_type != QR::economy)
81 A_fact.resize (m, m, 0.0); 81 A_fact.resize (m, m, 0.0);
82 82
83 Complex *tmp_data = A_fact.fortran_vec (); 83 Complex *tmp_data = A_fact.fortran_vec ();
84 84
85 Array<double> rwork (2*n); 85 Array<double> rwork (2*n);
86 double *prwork = rwork.fortran_vec (); 86 double *prwork = rwork.fortran_vec ();
87 87
88 Array<int> jpvt (n, 0); 88 Array<octave_idx_type> jpvt (n, 0);
89 int *pjpvt = jpvt.fortran_vec (); 89 octave_idx_type *pjpvt = jpvt.fortran_vec ();
90 90
91 // Code to enforce a certain permutation could go here... 91 // Code to enforce a certain permutation could go here...
92 92
93 F77_XFCN (zgeqpf, ZGEQPF, (m, n, tmp_data, m, pjpvt, ptau, pwork, 93 F77_XFCN (zgeqpf, ZGEQPF, (m, n, tmp_data, m, pjpvt, ptau, pwork,
94 prwork, info)); 94 prwork, info));
101 // indices only!) 101 // indices only!)
102 102
103 if (qr_type == QR::economy) 103 if (qr_type == QR::economy)
104 { 104 {
105 p.resize (1, n, 0.0); 105 p.resize (1, n, 0.0);
106 for (int j = 0; j < n; j++) 106 for (octave_idx_type j = 0; j < n; j++)
107 p.elem (0, j) = jpvt.elem (j); 107 p.elem (0, j) = jpvt.elem (j);
108 } 108 }
109 else 109 else
110 { 110 {
111 p.resize (n, n, 0.0); 111 p.resize (n, n, 0.0);
112 for (int j = 0; j < n; j++) 112 for (octave_idx_type j = 0; j < n; j++)
113 p.elem (jpvt.elem (j) - 1, j) = 1.0; 113 p.elem (jpvt.elem (j) - 1, j) = 1.0;
114 } 114 }
115 115
116 int n2 = (qr_type == QR::economy) ? min_mn : m; 116 octave_idx_type n2 = (qr_type == QR::economy) ? min_mn : m;
117 117
118 if (qr_type == QR::economy && m > n) 118 if (qr_type == QR::economy && m > n)
119 r.resize (n, n, 0.0); 119 r.resize (n, n, 0.0);
120 else 120 else
121 r.resize (m, n, 0.0); 121 r.resize (m, n, 0.0);
122 122
123 for (int j = 0; j < n; j++) 123 for (octave_idx_type j = 0; j < n; j++)
124 { 124 {
125 int limit = j < min_mn-1 ? j : min_mn-1; 125 octave_idx_type limit = j < min_mn-1 ? j : min_mn-1;
126 for (int i = 0; i <= limit; i++) 126 for (octave_idx_type i = 0; i <= limit; i++)
127 r.elem (i, j) = A_fact.elem (i, j); 127 r.elem (i, j) = A_fact.elem (i, j);
128 } 128 }
129 129
130 F77_XFCN (zungqr, ZUNGQR, (m, n2, min_mn, tmp_data, m, ptau, 130 F77_XFCN (zungqr, ZUNGQR, (m, n2, min_mn, tmp_data, m, ptau,
131 pwork, lwork, info)); 131 pwork, lwork, info));