diff liboctave/dbleQR.cc @ 9713:7918eb15040c

refactor the QR classes onto a templated base
author Jaroslav Hajek <highegg@gmail.com>
date Mon, 12 Oct 2009 10:42:49 +0200
parents b03953732530
children 1a9508872af0
line wrap: on
line diff
--- a/liboctave/dbleQR.cc	Sun Oct 11 15:27:51 2009 -0700
+++ b/liboctave/dbleQR.cc	Mon Oct 12 10:42:49 2009 +0200
@@ -34,6 +34,10 @@
 #include "idx-vector.h"
 #include "oct-locbuf.h"
 
+#include "base-qr.cc"
+
+template class base_qr<Matrix>;
+
 extern "C"
 {
   F77_RET_T
@@ -80,14 +84,13 @@
 #endif
 }
 
-QR::QR (const Matrix& a, QR::type qr_type)
-  : q (), r ()
+QR::QR (const Matrix& a, qr_type_t qr_type)
 {
   init (a, qr_type);
 }
 
 void
-QR::init (const Matrix& a, QR::type qr_type)
+QR::init (const Matrix& a, qr_type_t qr_type)
 {
   octave_idx_type m = a.rows ();
   octave_idx_type n = a.cols ();
@@ -98,7 +101,7 @@
   octave_idx_type info = 0;
 
   Matrix afact = a;
-  if (m > n && qr_type == QR::std)
+  if (m > n && qr_type == qr_type_std)
     afact.resize (m, m);
 
   if (m > 0)
@@ -118,12 +121,12 @@
 }
 
 void QR::form (octave_idx_type n, Matrix& afact, 
-               double *tau, QR::type qr_type)
+               double *tau, qr_type_t qr_type)
 {
   octave_idx_type m = afact.rows (), min_mn = std::min (m, n);
   octave_idx_type info;
 
-  if (qr_type == QR::raw)
+  if (qr_type == qr_type_raw)
     {
       for (octave_idx_type j = 0; j < min_mn; j++)
 	{
@@ -141,7 +144,7 @@
         {
           // afact will become q.
           q = afact;
-          octave_idx_type k = qr_type == QR::economy ? n : m;
+          octave_idx_type k = qr_type == qr_type_economy ? n : m;
           r = Matrix (k, n);
           for (octave_idx_type j = 0; j < n; j++)
             {
@@ -185,32 +188,6 @@
     }
 }
 
-QR::QR (const Matrix& q_arg, const Matrix& r_arg)
-{
-  octave_idx_type qr = q_arg.rows (), qc = q_arg.columns ();
-  octave_idx_type rr = r_arg.rows (), rc = r_arg.columns ();
-  if (qc == rr && (qr == qc || (qr > qc && rr == rc)))
-    {
-      q = q_arg;
-      r = r_arg;
-    }
-  else
-    (*current_liboctave_error_handler) ("QR dimensions mismatch");
-}
-
-QR::type
-QR::get_type (void) const
-{
-  QR::type retval;
-  if (!q.is_empty () && q.is_square ())
-    retval = QR::std;
-  else if (q.rows () > q.columns () && r.is_square ())
-    retval = QR::economy;
-  else
-    retval = QR::raw;
-  return retval;
-}
-
 #ifdef HAVE_QRUPDATE
 
 void