diff liboctave/CmplxQRP.cc @ 8367:445d27d79f4e

support permutation matrix objects
author Jaroslav Hajek <highegg@gmail.com>
date Thu, 04 Dec 2008 08:31:56 +0100
parents 29980c6b8604
children c72c1c9bccdc
line wrap: on
line diff
--- a/liboctave/CmplxQRP.cc	Wed Dec 03 13:32:57 2008 +0100
+++ b/liboctave/CmplxQRP.cc	Thu Dec 04 08:31:56 2008 +0100
@@ -86,7 +86,7 @@
   Array<double> rwork (2*n);
   double *prwork = rwork.fortran_vec ();
 
-  Array<octave_idx_type> jpvt (n, 0);
+  MArray<octave_idx_type> jpvt (n, 0);
   octave_idx_type *pjpvt = jpvt.fortran_vec ();
 
   // Code to enforce a certain permutation could go here...
@@ -97,18 +97,8 @@
   // Form Permutation matrix (if economy is requested, return the
   // indices only!)
 
-  if (qr_type == QR::economy)
-    {
-      p.resize (1, n, 0.0);
-      for (octave_idx_type j = 0; j < n; j++)
-	p.elem (0, j) = jpvt.elem (j);
-    }
-  else
-    {
-      p.resize (n, n, 0.0);
-      for (octave_idx_type j = 0; j < n; j++)
-	p.elem (jpvt.elem (j) - 1, j) = 1.0;
-    }
+  jpvt -= 1;
+  p = PermMatrix (jpvt, true);
 
   octave_idx_type n2 = (qr_type == QR::economy) ? min_mn : m;
 
@@ -131,6 +121,14 @@
   q.resize (m, n2);
 }
 
+ColumnVector
+ComplexQRP::Pvec (void) const
+{
+  Array<double> pa (p);
+  ColumnVector pv (MArray<double> (pa) + 1.0);
+  return pv;
+}
+
 /*
 ;;; Local Variables: ***
 ;;; mode: C++ ***