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 "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
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
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
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
00091
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 }