00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifdef HAVE_CONFIG_H
00025 #include <config.h>
00026 #endif
00027
00028 #include <cassert>
00029
00030 #include "dbleQRP.h"
00031 #include "f77-fcn.h"
00032 #include "lo-error.h"
00033 #include "oct-locbuf.h"
00034
00035 extern "C"
00036 {
00037 F77_RET_T
00038 F77_FUNC (dgeqp3, DGEQP3) (const octave_idx_type&, const octave_idx_type&,
00039 double*, const octave_idx_type&,
00040 octave_idx_type*, double*, double*,
00041 const octave_idx_type&, octave_idx_type&);
00042 }
00043
00044
00045
00046 QRP::QRP (const Matrix& a, qr_type_t qr_type)
00047 : QR (), p ()
00048 {
00049 init (a, qr_type);
00050 }
00051
00052 void
00053 QRP::init (const Matrix& a, qr_type_t qr_type)
00054 {
00055 assert (qr_type != qr_type_raw);
00056
00057 octave_idx_type m = a.rows ();
00058 octave_idx_type n = a.cols ();
00059
00060 octave_idx_type min_mn = m < n ? m : n;
00061 OCTAVE_LOCAL_BUFFER (double, tau, min_mn);
00062
00063 octave_idx_type info = 0;
00064
00065 Matrix afact = a;
00066 if (m > n && qr_type == qr_type_std)
00067 afact.resize (m, m);
00068
00069 MArray<octave_idx_type> jpvt (dim_vector (n, 1), 0);
00070
00071 if (m > 0)
00072 {
00073
00074 double rlwork;
00075 F77_XFCN (dgeqp3, DGEQP3, (m, n, afact.fortran_vec (), m, jpvt.fortran_vec (),
00076 tau, &rlwork, -1, info));
00077
00078
00079 octave_idx_type lwork = rlwork;
00080 lwork = std::max (lwork, static_cast<octave_idx_type> (1));
00081 OCTAVE_LOCAL_BUFFER (double, work, lwork);
00082 F77_XFCN (dgeqp3, DGEQP3, (m, n, afact.fortran_vec (), m, jpvt.fortran_vec (),
00083 tau, work, lwork, info));
00084 }
00085 else
00086 for (octave_idx_type i = 0; i < n; i++) jpvt(i) = i+1;
00087
00088
00089
00090
00091 jpvt -= static_cast<octave_idx_type> (1);
00092 p = PermMatrix (jpvt, true);
00093
00094
00095 form (n, afact, tau, qr_type);
00096 }
00097
00098 RowVector
00099 QRP::Pvec (void) const
00100 {
00101 Array<double> pa (p.pvec ());
00102 RowVector pv (MArray<double> (pa) + 1.0);
00103 return pv;
00104 }