diff liboctave/CmplxSCHUR.cc @ 457:3d4b4f0fa5ba

[project @ 1994-06-06 00:33:33 by jwe] Initial revision
author jwe
date Mon, 06 Jun 1994 00:33:51 +0000
parents
children 2ca256b77602
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/liboctave/CmplxSCHUR.cc	Mon Jun 06 00:33:51 1994 +0000
@@ -0,0 +1,135 @@
+//                                        -*- C++ -*-
+/*
+
+Copyright (C) 1992, 1993, 1994 John W. Eaton
+
+This file is part of Octave.
+
+Octave is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 2, or (at your option) any
+later version.
+
+Octave is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with Octave; see the file COPYING.  If not, write to the Free
+Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#if defined (__GNUG__)
+#pragma implementation
+#endif
+
+#include "CmplxSCHUR.h"
+#include "mx-inlines.cc"
+#include "lo-error.h"
+#include "f77-uscore.h"
+
+extern "C"
+{
+  int F77_FCN (zgeesx) (const char*, const char*, int (*)(Complex*),
+			const char*, const int*, Complex*, const int*,
+			int*, Complex*, Complex*, const int*, double*,
+			double*, Complex*, const int*, double*, int*,
+			int*, long, long);
+}
+
+static int
+complex_select_ana (Complex *a)
+{
+  return a->real () < 0.0;
+}
+
+static int
+complex_select_dig (Complex *a)
+{
+  return (abs (*a) < 1.0);
+}
+
+int
+ComplexSCHUR::init (const ComplexMatrix& a, const char *ord)
+{
+  int a_nr = a.rows ();
+  int a_nc = a.cols ();
+  if (a_nr != a_nc)
+    {
+      (*current_liboctave_error_handler)
+	("ComplexSCHUR requires square matrix");
+      return -1;
+    }
+
+  char jobvs = 'V';
+  char sort;
+  if (*ord == 'A' || *ord == 'D' || *ord == 'a' || *ord == 'd')
+     sort = 'S';
+   else
+     sort = 'N';
+
+  char sense = 'N';
+
+  int n = a_nc;
+  int lwork = 8 * n;
+  int info;
+  int sdim;
+  double rconde;
+  double rcondv;
+
+  double *rwork = new double [n];
+
+// bwork is not referenced for non-ordered Schur.
+
+  int *bwork = (int *) NULL;
+  if (*ord == 'A' || *ord == 'D' || *ord == 'a' || *ord == 'd')
+    bwork = new int [n];
+
+  Complex *s = dup (a.data (), a.length ());
+
+  Complex *work = new Complex [lwork];
+  Complex *q = new Complex [n*n];
+  Complex *w = new Complex [n];
+
+  if (*ord == 'A' || *ord == 'a')
+    {
+      F77_FCN (zgeesx) (&jobvs, &sort, complex_select_ana, &sense,
+			&n, s, &n, &sdim, w, q, &n, &rconde, &rcondv,
+			work, &lwork, rwork, bwork, &info, 1L, 1L);
+    }
+  else if (*ord == 'D' || *ord == 'd')
+    {
+      F77_FCN (zgeesx) (&jobvs, &sort, complex_select_dig, &sense,
+			&n, s, &n, &sdim, w, q, &n, &rconde, &rcondv,
+			work, &lwork, rwork, bwork, &info, 1L, 1L);
+    }
+  else
+    {
+      F77_FCN (zgeesx) (&jobvs, &sort, (void *) 0, &sense, &n, s,
+			&n, &sdim, w, q, &n, &rconde, &rcondv, work,
+			&lwork, rwork, bwork, &info, 1L, 1L);
+    }
+
+  schur_mat = ComplexMatrix (s,n,n);
+  unitary_mat = ComplexMatrix (q,n,n);
+
+  delete [] w;
+  delete [] work;
+  delete [] rwork;
+  delete [] bwork;
+
+  return info;
+}
+
+/*
+;;; Local Variables: ***
+;;; mode: C++ ***
+;;; page-delimiter: "^/\\*" ***
+;;; End: ***
+*/