annotate liboctave/fCmplxQRP.cc @ 7948:af10baa63915 ss-3-1-50

3.1.50 snapshot
author John W. Eaton <jwe@octave.org>
date Fri, 18 Jul 2008 17:42:48 -0400
parents 39c1026191e9
children 445d27d79f4e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7792
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1 /*
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3 Copyright (C) 1994, 1995, 1996, 1997, 2002, 2003, 2004, 2005, 2007
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4 John W. Eaton
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6 This file is part of Octave.
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
7
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
8 Octave is free software; you can redistribute it and/or modify it
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
9 under the terms of the GNU General Public License as published by the
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
10 Free Software Foundation; either version 3 of the License, or (at your
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
11 option) any later version.
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
12
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
13 Octave is distributed in the hope that it will be useful, but WITHOUT
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
16 for more details.
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
17
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
19 along with Octave; see the file COPYING. If not, see
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
20 <http://www.gnu.org/licenses/>.
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
21
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
22 */
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
23
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
24 #ifdef HAVE_CONFIG_H
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25 #include <config.h>
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
26 #endif
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
27
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
28 #include <cassert>
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
29
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
30 #include "fCmplxQRP.h"
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
31 #include "f77-fcn.h"
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
32 #include "lo-error.h"
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
33
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
34 extern "C"
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
35 {
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
36 F77_RET_T
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
37 F77_FUNC (cgeqpf, CGEQPF) (const octave_idx_type&, const octave_idx_type&, FloatComplex*,
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
38 const octave_idx_type&, octave_idx_type*, FloatComplex*, FloatComplex*,
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
39 float*, octave_idx_type&);
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
40
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
41 F77_RET_T
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
42 F77_FUNC (cungqr, CUNGQR) (const octave_idx_type&, const octave_idx_type&, const octave_idx_type&,
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
43 FloatComplex*, const octave_idx_type&, FloatComplex*,
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
44 FloatComplex*, const octave_idx_type&, octave_idx_type&);
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
45 }
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
46
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
47 // It would be best to share some of this code with FloatComplexQR class...
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
48
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
49 FloatComplexQRP::FloatComplexQRP (const FloatComplexMatrix& a, QR::type qr_type)
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
50 : FloatComplexQR (), p ()
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
51 {
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
52 init (a, qr_type);
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
53 }
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
54
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
55 void
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
56 FloatComplexQRP::init (const FloatComplexMatrix& a, QR::type qr_type)
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
57 {
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
58 assert (qr_type != QR::raw);
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
59
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
60 octave_idx_type m = a.rows ();
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
61 octave_idx_type n = a.cols ();
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
62
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
63 if (m == 0 || n == 0)
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
64 {
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
65 (*current_liboctave_error_handler)
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
66 ("FloatComplexQR must have non-empty matrix");
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
67 return;
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
68 }
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
69
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
70 octave_idx_type min_mn = m < n ? m : n;
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
71 Array<FloatComplex> tau (min_mn);
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
72 FloatComplex *ptau = tau.fortran_vec ();
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
73
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
74 octave_idx_type lwork = 3*n > 32*m ? 3*n : 32*m;
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
75 Array<FloatComplex> work (lwork);
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
76 FloatComplex *pwork = work.fortran_vec ();
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
77
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
78 octave_idx_type info = 0;
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
79
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
80 FloatComplexMatrix A_fact = a;
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
81 if (m > n && qr_type != QR::economy)
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
82 A_fact.resize (m, m, 0.0);
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
83
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
84 FloatComplex *tmp_data = A_fact.fortran_vec ();
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
85
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
86 Array<float> rwork (2*n);
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
87 float *prwork = rwork.fortran_vec ();
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
88
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
89 Array<octave_idx_type> jpvt (n, 0);
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
90 octave_idx_type *pjpvt = jpvt.fortran_vec ();
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
91
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
92 // Code to enforce a certain permutation could go here...
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
93
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
94 F77_XFCN (cgeqpf, CGEQPF, (m, n, tmp_data, m, pjpvt, ptau, pwork,
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
95 prwork, info));
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
96
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
97 // Form Permutation matrix (if economy is requested, return the
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
98 // indices only!)
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
99
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
100 if (qr_type == QR::economy)
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
101 {
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
102 p.resize (1, n, 0.0);
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
103 for (octave_idx_type j = 0; j < n; j++)
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
104 p.elem (0, j) = jpvt.elem (j);
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
105 }
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
106 else
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
107 {
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
108 p.resize (n, n, 0.0);
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
109 for (octave_idx_type j = 0; j < n; j++)
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
110 p.elem (jpvt.elem (j) - 1, j) = 1.0;
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
111 }
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
112
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
113 octave_idx_type n2 = (qr_type == QR::economy) ? min_mn : m;
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
114
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
115 if (qr_type == QR::economy && m > n)
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
116 r.resize (n, n, 0.0);
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
117 else
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
118 r.resize (m, n, 0.0);
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
119
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
120 for (octave_idx_type j = 0; j < n; j++)
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
121 {
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
122 octave_idx_type limit = j < min_mn-1 ? j : min_mn-1;
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
123 for (octave_idx_type i = 0; i <= limit; i++)
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
124 r.elem (i, j) = A_fact.elem (i, j);
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
125 }
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
126
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
127 F77_XFCN (cungqr, CUNGQR, (m, n2, min_mn, tmp_data, m, ptau,
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
128 pwork, lwork, info));
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
129
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
130 q = A_fact;
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
131 q.resize (m, n2);
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
132 }
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
133
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
134 /*
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
135 ;;; Local Variables: ***
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
136 ;;; mode: C++ ***
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
137 ;;; End: ***
39c1026191e9 add missing files from single-precision merge
John W. Eaton <jwe@octave.org>
parents:
diff changeset
138 */