dbleQRP.cc

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 1994-2012 John W. Eaton
00004 Copyright (C) 2009 VZLU Prague
00005 
00006 This file is part of Octave.
00007 
00008 Octave is free software; you can redistribute it and/or modify it
00009 under the terms of the GNU General Public License as published by the
00010 Free Software Foundation; either version 3 of the License, or (at your
00011 option) any later version.
00012 
00013 Octave is distributed in the hope that it will be useful, but WITHOUT
00014 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00015 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00016 for more details.
00017 
00018 You should have received a copy of the GNU General Public License
00019 along with Octave; see the file COPYING.  If not, see
00020 <http://www.gnu.org/licenses/>.
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 // It would be best to share some of this code with QR class...
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       // workspace query.
00074       double rlwork;
00075       F77_XFCN (dgeqp3, DGEQP3, (m, n, afact.fortran_vec (), m, jpvt.fortran_vec (),
00076                                  tau, &rlwork, -1, info));
00077 
00078       // allocate buffer and do the job.
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   // Form Permutation matrix (if economy is requested, return the
00089   // indices only!)
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 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines