annotate liboctave/dbleQRP.cc @ 8368:c72c1c9bccdc

call blocked permuted qr factorization routines from LAPACK
author Jaroslav Hajek <highegg@gmail.com>
date Thu, 04 Dec 2008 09:15:17 +0100
parents 445d27d79f4e
children e3c9102431a9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
538
8e134d3b21c9 [project @ 1994-07-21 22:40:04 by jwe]
jwe
parents:
diff changeset
1 /*
8e134d3b21c9 [project @ 1994-07-21 22:40:04 by jwe]
jwe
parents:
diff changeset
2
7017
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
3 Copyright (C) 1994, 1995, 1996, 1997, 2002, 2003, 2004, 2005, 2007
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
4 John W. Eaton
538
8e134d3b21c9 [project @ 1994-07-21 22:40:04 by jwe]
jwe
parents:
diff changeset
5
8e134d3b21c9 [project @ 1994-07-21 22:40:04 by jwe]
jwe
parents:
diff changeset
6 This file is part of Octave.
8e134d3b21c9 [project @ 1994-07-21 22:40:04 by jwe]
jwe
parents:
diff changeset
7
8e134d3b21c9 [project @ 1994-07-21 22:40:04 by jwe]
jwe
parents:
diff changeset
8 Octave is free software; you can redistribute it and/or modify it
8e134d3b21c9 [project @ 1994-07-21 22:40:04 by jwe]
jwe
parents:
diff changeset
9 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5307
diff changeset
10 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5307
diff changeset
11 option) any later version.
538
8e134d3b21c9 [project @ 1994-07-21 22:40:04 by jwe]
jwe
parents:
diff changeset
12
8e134d3b21c9 [project @ 1994-07-21 22:40:04 by jwe]
jwe
parents:
diff changeset
13 Octave is distributed in the hope that it will be useful, but WITHOUT
8e134d3b21c9 [project @ 1994-07-21 22:40:04 by jwe]
jwe
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8e134d3b21c9 [project @ 1994-07-21 22:40:04 by jwe]
jwe
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
8e134d3b21c9 [project @ 1994-07-21 22:40:04 by jwe]
jwe
parents:
diff changeset
16 for more details.
8e134d3b21c9 [project @ 1994-07-21 22:40:04 by jwe]
jwe
parents:
diff changeset
17
8e134d3b21c9 [project @ 1994-07-21 22:40:04 by jwe]
jwe
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5307
diff changeset
19 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5307
diff changeset
20 <http://www.gnu.org/licenses/>.
538
8e134d3b21c9 [project @ 1994-07-21 22:40:04 by jwe]
jwe
parents:
diff changeset
21
8e134d3b21c9 [project @ 1994-07-21 22:40:04 by jwe]
jwe
parents:
diff changeset
22 */
8e134d3b21c9 [project @ 1994-07-21 22:40:04 by jwe]
jwe
parents:
diff changeset
23
8e134d3b21c9 [project @ 1994-07-21 22:40:04 by jwe]
jwe
parents:
diff changeset
24 #ifdef HAVE_CONFIG_H
1192
b6360f2d4fa6 [project @ 1995-03-30 21:38:35 by jwe]
jwe
parents: 1011
diff changeset
25 #include <config.h>
538
8e134d3b21c9 [project @ 1994-07-21 22:40:04 by jwe]
jwe
parents:
diff changeset
26 #endif
8e134d3b21c9 [project @ 1994-07-21 22:40:04 by jwe]
jwe
parents:
diff changeset
27
1367
9f9131a8d706 [project @ 1995-09-06 00:07:03 by jwe]
jwe
parents: 1360
diff changeset
28 #include <cassert>
538
8e134d3b21c9 [project @ 1994-07-21 22:40:04 by jwe]
jwe
parents:
diff changeset
29
8e134d3b21c9 [project @ 1994-07-21 22:40:04 by jwe]
jwe
parents:
diff changeset
30 #include "dbleQRP.h"
1847
2ffe49eb95a5 [project @ 1996-02-03 12:47:55 by jwe]
jwe
parents: 1367
diff changeset
31 #include "f77-fcn.h"
538
8e134d3b21c9 [project @ 1994-07-21 22:40:04 by jwe]
jwe
parents:
diff changeset
32 #include "lo-error.h"
8e134d3b21c9 [project @ 1994-07-21 22:40:04 by jwe]
jwe
parents:
diff changeset
33
8e134d3b21c9 [project @ 1994-07-21 22:40:04 by jwe]
jwe
parents:
diff changeset
34 extern "C"
8e134d3b21c9 [project @ 1994-07-21 22:40:04 by jwe]
jwe
parents:
diff changeset
35 {
4552
6f3382e08a52 [project @ 2003-10-27 20:38:02 by jwe]
jwe
parents: 4192
diff changeset
36 F77_RET_T
8368
c72c1c9bccdc call blocked permuted qr factorization routines from LAPACK
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
37 F77_FUNC (dgeqp3, DGEQP3) (const octave_idx_type&, const octave_idx_type&, double*,
c72c1c9bccdc call blocked permuted qr factorization routines from LAPACK
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
38 const octave_idx_type&, octave_idx_type*, double*, double*,
c72c1c9bccdc call blocked permuted qr factorization routines from LAPACK
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
39 const octave_idx_type&, octave_idx_type&);
567
01e026888dfb [project @ 1994-07-26 03:35:32 by jwe]
jwe
parents: 538
diff changeset
40
4552
6f3382e08a52 [project @ 2003-10-27 20:38:02 by jwe]
jwe
parents: 4192
diff changeset
41 F77_RET_T
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
42 F77_FUNC (dorgqr, DORGQR) (const octave_idx_type&, const octave_idx_type&, const octave_idx_type&,
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
43 double*, const octave_idx_type&, double*, double*,
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
44 const octave_idx_type&, octave_idx_type&);
538
8e134d3b21c9 [project @ 1994-07-21 22:40:04 by jwe]
jwe
parents:
diff changeset
45 }
8e134d3b21c9 [project @ 1994-07-21 22:40:04 by jwe]
jwe
parents:
diff changeset
46
8e134d3b21c9 [project @ 1994-07-21 22:40:04 by jwe]
jwe
parents:
diff changeset
47 // It would be best to share some of this code with QR class...
8e134d3b21c9 [project @ 1994-07-21 22:40:04 by jwe]
jwe
parents:
diff changeset
48
8e134d3b21c9 [project @ 1994-07-21 22:40:04 by jwe]
jwe
parents:
diff changeset
49 QRP::QRP (const Matrix& a, QR::type qr_type)
2763
d9d00d7e271e [project @ 1997-03-01 02:14:33 by jwe]
jwe
parents: 2468
diff changeset
50 : QR (), p ()
d9d00d7e271e [project @ 1997-03-01 02:14:33 by jwe]
jwe
parents: 2468
diff changeset
51 {
d9d00d7e271e [project @ 1997-03-01 02:14:33 by jwe]
jwe
parents: 2468
diff changeset
52 init (a, qr_type);
d9d00d7e271e [project @ 1997-03-01 02:14:33 by jwe]
jwe
parents: 2468
diff changeset
53 }
d9d00d7e271e [project @ 1997-03-01 02:14:33 by jwe]
jwe
parents: 2468
diff changeset
54
d9d00d7e271e [project @ 1997-03-01 02:14:33 by jwe]
jwe
parents: 2468
diff changeset
55 void
d9d00d7e271e [project @ 1997-03-01 02:14:33 by jwe]
jwe
parents: 2468
diff changeset
56 QRP::init (const Matrix& a, QR::type qr_type)
538
8e134d3b21c9 [project @ 1994-07-21 22:40:04 by jwe]
jwe
parents:
diff changeset
57 {
8e134d3b21c9 [project @ 1994-07-21 22:40:04 by jwe]
jwe
parents:
diff changeset
58 assert (qr_type != QR::raw);
8e134d3b21c9 [project @ 1994-07-21 22:40:04 by jwe]
jwe
parents:
diff changeset
59
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
60 octave_idx_type m = a.rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
61 octave_idx_type n = a.cols ();
538
8e134d3b21c9 [project @ 1994-07-21 22:40:04 by jwe]
jwe
parents:
diff changeset
62
8e134d3b21c9 [project @ 1994-07-21 22:40:04 by jwe]
jwe
parents:
diff changeset
63 if (m == 0 || n == 0)
8e134d3b21c9 [project @ 1994-07-21 22:40:04 by jwe]
jwe
parents:
diff changeset
64 {
8e134d3b21c9 [project @ 1994-07-21 22:40:04 by jwe]
jwe
parents:
diff changeset
65 (*current_liboctave_error_handler) ("QR must have non-empty matrix");
8e134d3b21c9 [project @ 1994-07-21 22:40:04 by jwe]
jwe
parents:
diff changeset
66 return;
8e134d3b21c9 [project @ 1994-07-21 22:40:04 by jwe]
jwe
parents:
diff changeset
67 }
8e134d3b21c9 [project @ 1994-07-21 22:40:04 by jwe]
jwe
parents:
diff changeset
68
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
69 octave_idx_type min_mn = m < n ? m : n;
3883
69b6bd271277 [project @ 2002-04-02 21:05:10 by jwe]
jwe
parents: 2847
diff changeset
70 Array<double> tau (min_mn);
1928
20353fa5f83d [project @ 1996-02-11 21:51:54 by jwe]
jwe
parents: 1922
diff changeset
71 double *ptau = tau.fortran_vec ();
1922
8a57554f3142 [project @ 1996-02-11 02:53:20 by jwe]
jwe
parents: 1882
diff changeset
72
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
73 octave_idx_type info = 0;
538
8e134d3b21c9 [project @ 1994-07-21 22:40:04 by jwe]
jwe
parents:
diff changeset
74
2763
d9d00d7e271e [project @ 1997-03-01 02:14:33 by jwe]
jwe
parents: 2468
diff changeset
75 Matrix A_fact = a;
3883
69b6bd271277 [project @ 2002-04-02 21:05:10 by jwe]
jwe
parents: 2847
diff changeset
76 if (m > n && qr_type != QR::economy)
2763
d9d00d7e271e [project @ 1997-03-01 02:14:33 by jwe]
jwe
parents: 2468
diff changeset
77 A_fact.resize (m, m, 0.0);
538
8e134d3b21c9 [project @ 1994-07-21 22:40:04 by jwe]
jwe
parents:
diff changeset
78
1928
20353fa5f83d [project @ 1996-02-11 21:51:54 by jwe]
jwe
parents: 1922
diff changeset
79 double *tmp_data = A_fact.fortran_vec ();
538
8e134d3b21c9 [project @ 1994-07-21 22:40:04 by jwe]
jwe
parents:
diff changeset
80
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
81 MArray<octave_idx_type> jpvt (n, 0);
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
82 octave_idx_type *pjpvt = jpvt.fortran_vec ();
538
8e134d3b21c9 [project @ 1994-07-21 22:40:04 by jwe]
jwe
parents:
diff changeset
83
8368
c72c1c9bccdc call blocked permuted qr factorization routines from LAPACK
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
84 double rlwork = 0;
c72c1c9bccdc call blocked permuted qr factorization routines from LAPACK
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
85 // Workspace query...
c72c1c9bccdc call blocked permuted qr factorization routines from LAPACK
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
86 F77_XFCN (dgeqp3, DGEQP3, (m, n, tmp_data, m, pjpvt, ptau, &rlwork, -1, info));
c72c1c9bccdc call blocked permuted qr factorization routines from LAPACK
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
87
c72c1c9bccdc call blocked permuted qr factorization routines from LAPACK
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
88 octave_idx_type lwork = rlwork;
c72c1c9bccdc call blocked permuted qr factorization routines from LAPACK
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
89 Array<double> work (lwork);
c72c1c9bccdc call blocked permuted qr factorization routines from LAPACK
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
90 double *pwork = work.fortran_vec ();
c72c1c9bccdc call blocked permuted qr factorization routines from LAPACK
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
91
1928
20353fa5f83d [project @ 1996-02-11 21:51:54 by jwe]
jwe
parents: 1922
diff changeset
92 // Code to enforce a certain permutation could go here...
538
8e134d3b21c9 [project @ 1994-07-21 22:40:04 by jwe]
jwe
parents:
diff changeset
93
8368
c72c1c9bccdc call blocked permuted qr factorization routines from LAPACK
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
94 F77_XFCN (dgeqp3, DGEQP3, (m, n, tmp_data, m, pjpvt, ptau, pwork, lwork, info));
1922
8a57554f3142 [project @ 1996-02-11 02:53:20 by jwe]
jwe
parents: 1882
diff changeset
95
7482
29980c6b8604 don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
96 // Form Permutation matrix (if economy is requested, return the
29980c6b8604 don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
97 // indices only!)
29980c6b8604 don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
98
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
99 jpvt -= 1;
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
100 p = PermMatrix (jpvt, true);
1922
8a57554f3142 [project @ 1996-02-11 02:53:20 by jwe]
jwe
parents: 1882
diff changeset
101
7482
29980c6b8604 don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
102 octave_idx_type n2 = (qr_type == QR::economy) ? min_mn : m;
1922
8a57554f3142 [project @ 1996-02-11 02:53:20 by jwe]
jwe
parents: 1882
diff changeset
103
7482
29980c6b8604 don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
104 if (qr_type == QR::economy && m > n)
29980c6b8604 don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
105 r.resize (n, n, 0.0);
29980c6b8604 don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
106 else
29980c6b8604 don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
107 r.resize (m, n, 0.0);
3883
69b6bd271277 [project @ 2002-04-02 21:05:10 by jwe]
jwe
parents: 2847
diff changeset
108
7482
29980c6b8604 don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
109 for (octave_idx_type j = 0; j < n; j++)
29980c6b8604 don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
110 {
29980c6b8604 don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
111 octave_idx_type limit = j < min_mn-1 ? j : min_mn-1;
29980c6b8604 don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
112 for (octave_idx_type i = 0; i <= limit; i++)
29980c6b8604 don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
113 r.elem (i, j) = A_fact.elem (i, j);
29980c6b8604 don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
114 }
1922
8a57554f3142 [project @ 1996-02-11 02:53:20 by jwe]
jwe
parents: 1882
diff changeset
115
7482
29980c6b8604 don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
116 F77_XFCN (dorgqr, DORGQR, (m, n2, min_mn, tmp_data, m, ptau,
29980c6b8604 don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
117 pwork, lwork, info));
1922
8a57554f3142 [project @ 1996-02-11 02:53:20 by jwe]
jwe
parents: 1882
diff changeset
118
7482
29980c6b8604 don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
119 q = A_fact;
29980c6b8604 don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
120 q.resize (m, n2);
538
8e134d3b21c9 [project @ 1994-07-21 22:40:04 by jwe]
jwe
parents:
diff changeset
121 }
8e134d3b21c9 [project @ 1994-07-21 22:40:04 by jwe]
jwe
parents:
diff changeset
122
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
123 ColumnVector
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
124 QRP::Pvec (void) const
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
125 {
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
126 Array<double> pa (p);
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
127 ColumnVector pv (MArray<double> (pa) + 1.0);
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
128 return pv;
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
129 }
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
130
538
8e134d3b21c9 [project @ 1994-07-21 22:40:04 by jwe]
jwe
parents:
diff changeset
131 /*
8e134d3b21c9 [project @ 1994-07-21 22:40:04 by jwe]
jwe
parents:
diff changeset
132 ;;; Local Variables: ***
8e134d3b21c9 [project @ 1994-07-21 22:40:04 by jwe]
jwe
parents:
diff changeset
133 ;;; mode: C++ ***
8e134d3b21c9 [project @ 1994-07-21 22:40:04 by jwe]
jwe
parents:
diff changeset
134 ;;; End: ***
8e134d3b21c9 [project @ 1994-07-21 22:40:04 by jwe]
jwe
parents:
diff changeset
135 */