fCmplxQRP.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 "fCmplxQRP.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 (cgeqp3, CGEQP3) (const octave_idx_type&, const octave_idx_type&,
00039                              FloatComplex*, const octave_idx_type&,
00040                              octave_idx_type*, FloatComplex*, FloatComplex*,
00041                              const octave_idx_type&, float*, octave_idx_type&);
00042 }
00043 
00044 // It would be best to share some of this code with FloatComplexQR class...
00045 
00046 FloatComplexQRP::FloatComplexQRP (const FloatComplexMatrix& a, qr_type_t qr_type)
00047   : FloatComplexQR (), p ()
00048 {
00049   init (a, qr_type);
00050 }
00051 
00052 void
00053 FloatComplexQRP::init (const FloatComplexMatrix& 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 (FloatComplex, tau, min_mn);
00062 
00063   octave_idx_type info = 0;
00064 
00065   FloatComplexMatrix 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       OCTAVE_LOCAL_BUFFER (float, rwork, 2*n);
00074 
00075       // workspace query.
00076       FloatComplex clwork;
00077       F77_XFCN (cgeqp3, CGEQP3, (m, n, afact.fortran_vec (), m, jpvt.fortran_vec (),
00078                                  tau, &clwork, -1, rwork, info));
00079 
00080       // allocate buffer and do the job.
00081       octave_idx_type lwork = clwork.real ();
00082       lwork = std::max (lwork, static_cast<octave_idx_type> (1));
00083       OCTAVE_LOCAL_BUFFER (FloatComplex, work, lwork);
00084       F77_XFCN (cgeqp3, CGEQP3, (m, n, afact.fortran_vec (), m, jpvt.fortran_vec (),
00085                                  tau, work, lwork, rwork, info));
00086     }
00087   else
00088     for (octave_idx_type i = 0; i < n; i++) jpvt(i) = i+1;
00089 
00090   // Form Permutation matrix (if economy is requested, return the
00091   // indices only!)
00092 
00093   jpvt -= static_cast<octave_idx_type> (1);
00094   p = PermMatrix (jpvt, true);
00095 
00096 
00097   form (n, afact, tau, qr_type);
00098 }
00099 
00100 FloatRowVector
00101 FloatComplexQRP::Pvec (void) const
00102 {
00103   Array<float> pa (p.pvec ());
00104   FloatRowVector pv (MArray<float> (pa) + 1.0f);
00105   return pv;
00106 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines