diff src/chol.cc @ 636:fae2bd91c027

[project @ 1994-08-23 18:39:50 by jwe]
author jwe
date Tue, 23 Aug 1994 18:39:50 +0000
parents 8e4e7e5f307e
children 0a81458ef677
line wrap: on
line diff
--- a/src/chol.cc	Tue Aug 23 17:57:20 1994 +0000
+++ b/src/chol.cc	Tue Aug 23 18:39:50 1994 +0000
@@ -32,6 +32,7 @@
 #include "user-prefs.h"
 #include "gripes.h"
 #include "error.h"
+#include "utils.h"
 #include "help.h"
 #include "defun-dld.h"
 
@@ -40,68 +41,51 @@
 {
   Octave_object retval;
 
-  int nargin = args.length ();
-
-  if (nargin != 2 || nargout > 1)
+  if (args.length () != 2 || nargout > 1)
     {
       print_usage ("chol");
       return retval;
     }
 
-  tree_constant tmp = args(1).make_numeric ();
+  tree_constant arg = args(1);
     
-  int nr = tmp.rows ();
-  int nc = tmp.columns ();
+  int nr = arg.rows ();
+  int nc = arg.columns ();
 
-  if (nr == 0 || nc == 0)
-    {
-      int flag = user_pref.propagate_empty_matrices;
-      if (flag != 0)
-	{
-	  if (flag < 0)
-	    gripe_empty_arg ("chol", 0);
+  if (empty_arg ("chol", nr, nc) < 0)
+    return retval;
 
-	  retval.resize (1, Matrix ());
-	}
-      else
-	gripe_empty_arg ("chol", 1);
-
-      return retval;
-    }
-
-  if (tmp.is_real_matrix ())
+  if (arg.is_real_type ())
     {
-      Matrix m = tmp.matrix_value ();
-      int info;
-      CHOL fact (m, info);
-      if (info != 0)
-	error ("chol: matrix not positive definite");
-      else
-	retval = fact.chol_matrix ();
+      Matrix m = arg.matrix_value ();
+
+      if (! error_state)
+	{
+	  int info;
+	  CHOL fact (m, info);
+	  if (info != 0)
+	    error ("chol: matrix not positive definite");
+	  else
+	    retval = fact.chol_matrix ();
+	}
     }
-  else if (tmp.is_complex_matrix ())
+  else if (arg.is_complex_type ())
     {
-      ComplexMatrix m = tmp.complex_matrix_value ();
-      int info;
-      ComplexCHOL fact (m, info);
-      if (info != 0)
-	error ("chol: matrix not positive definite");
-      else
-	retval = fact.chol_matrix ();
-    }
-  else if (tmp.is_real_scalar ())
-    {
-      double d = tmp.double_value ();
-      retval = d;
-    }
-  else if (tmp.is_complex_scalar ())
-    {
-      Complex c = tmp.complex_value ();
-      retval = c;
+      ComplexMatrix m = arg.complex_matrix_value ();
+
+      if (! error_state)
+	{
+	  int info;
+	  ComplexCHOL fact (m, info);
+	  if (info != 0)
+	    error ("chol: matrix not positive definite");
+	  else
+	    retval = fact.chol_matrix ();
+	}
     }
   else
     {
-      gripe_wrong_type_arg ("chol", tmp);
+      gripe_wrong_type_arg ("chol", arg);
     }
 
   return retval;