diff libinterp/dldfcn/chol.cc @ 20939:b17fda023ca6

maint: Use new C++ archetype in more files. Place input validation first in files. Move declaration of retval down in function to be closer to point of usage. Eliminate else clause after if () error. Use "return ovl()" where it makes sense. * find.cc, gammainc.cc, gcd.cc, getgrent.cc, getpwent.cc, givens.cc, graphics.cc, help.cc, hess.cc, hex2num.cc, input.cc, kron.cc, load-path.cc, load-save.cc, lookup.cc, mappers.cc, matrix_type.cc, mgorth.cc, nproc.cc, ordschur.cc, pager.cc, pinv.cc, pr-output.cc, profiler.cc, psi.cc, quad.cc, rcond.cc, regexp.cc, schur.cc, sighandlers.cc, sparse.cc, str2double.cc, strfind.cc, strfns.cc, sub2ind.cc, svd.cc, sylvester.cc, symtab.cc, syscalls.cc, sysdep.cc, time.cc, toplev.cc, tril.cc, tsearch.cc, typecast.cc, urlwrite.cc, utils.cc, variables.cc, __delaunayn__.cc, __eigs__.cc, __glpk__.cc, __magick_read__.cc, __osmesa_print__.cc, __voronoi__.cc, amd.cc, audiodevinfo.cc, audioread.cc, chol.cc, colamd.cc, dmperm.cc, fftw.cc, qr.cc, symbfact.cc, symrcm.cc, ov-bool-mat.cc, ov-cell.cc, ov-class.cc, ov-classdef.cc, ov-fcn-handle.cc, ov-fcn-inline.cc, ov-flt-re-mat.cc, ov-java.cc, ov-null-mat.cc, ov-oncleanup.cc, ov-re-mat.cc, ov-struct.cc, ov-typeinfo.cc, ov-usr-fcn.cc, ov.cc, octave.cc: Use new C++ archetype in more files.
author Rik <rik@octave.org>
date Fri, 18 Dec 2015 15:37:22 -0800
parents 8da80da1ac37
children 48b2ad5ee801
line wrap: on
line diff
--- a/libinterp/dldfcn/chol.cc	Fri Dec 18 16:22:53 2015 -0500
+++ b/libinterp/dldfcn/chol.cc	Fri Dec 18 15:37:22 2015 -0800
@@ -337,11 +337,10 @@
 @seealso{chol, chol2inv, inv}\n\
 @end deftypefn")
 {
-  octave_value retval;
-
   if (args.length () != 1)
     print_usage ();
 
+  octave_value retval;
   octave_value arg = args(0);
 
   octave_idx_type nr = arg.rows ();
@@ -466,11 +465,11 @@
 @seealso{chol, cholinv, inv}\n\
 @end deftypefn")
 {
-  octave_value retval;
-
   if (args.length () != 1)
     print_usage ();
 
+  octave_value retval;
+
   octave_value arg = args(0);
 
   octave_idx_type nr = arg.rows ();
@@ -612,7 +611,7 @@
           else
             fact.update (u);
 
-          retval(0) = get_chol_r (fact);
+          retval = ovl (get_chol_r (fact));
         }
       else
         {
@@ -629,7 +628,7 @@
           else
             fact.update (u);
 
-          retval(0) = get_chol_r (fact);
+          retval = ovl (get_chol_r (fact));
         }
     }
   else
@@ -648,7 +647,7 @@
           else
             fact.update (u);
 
-          retval(0) = get_chol_r (fact);
+          retval = ovl (get_chol_r (fact));
         }
       else
         {
@@ -664,7 +663,7 @@
           else
             fact.update (u);
 
-          retval(0) = get_chol_r (fact);
+          retval = ovl (get_chol_r (fact));
         }
     }
 
@@ -775,8 +774,6 @@
       || ! argj.is_real_scalar ())
     print_usage ();
 
-  octave_value_list retval (nargout == 2 ? 2 : 1);
-
   octave_idx_type n = argr.rows ();
   octave_idx_type j = argj.scalar_value ();
 
@@ -786,6 +783,8 @@
   if (j < 1 || j > n+1)
     error ("cholinsert: index J out of range");
 
+  octave_value_list retval (nargout == 2 ? 2 : 1);
+
   int err = 0;
   if (argr.is_single_type () || argu.is_single_type ())
     {
@@ -799,7 +798,7 @@
           fact.set (R);
           err = fact.insert_sym (u, j-1);
 
-          retval(0) = get_chol_r (fact);
+          retval = ovl (get_chol_r (fact));
         }
       else
         {
@@ -812,7 +811,7 @@
           fact.set (R);
           err = fact.insert_sym (u, j-1);
 
-          retval(0) = get_chol_r (fact);
+          retval = ovl (get_chol_r (fact));
         }
     }
   else
@@ -827,7 +826,7 @@
           fact.set (R);
           err = fact.insert_sym (u, j-1);
 
-          retval(0) = get_chol_r (fact);
+          retval = ovl (get_chol_r (fact));
         }
       else
         {
@@ -840,7 +839,7 @@
           fact.set (R);
           err = fact.insert_sym (u, j-1);
 
-          retval(0) = get_chol_r (fact);
+          retval = ovl (get_chol_r (fact));
         }
     }
 
@@ -1003,8 +1002,6 @@
 @seealso{chol, cholupdate, cholinsert, cholshift}\n\
 @end deftypefn")
 {
-  octave_value_list retval;
-
   if (args.length () != 2)
     print_usage ();
 
@@ -1017,66 +1014,64 @@
   octave_idx_type n = argr.rows ();
   octave_idx_type j = argj.scalar_value ();
 
-  if (argr.columns () == n)
-    {
-      if (j > 0 && j <= n)
-        {
-          if (argr.is_single_type ())
-            {
-              if (argr.is_real_type ())
-                {
-                  // real case
-                  FloatMatrix R = argr.float_matrix_value ();
+  if (argr.columns () != n)
+    error ("choldelete: matrix R must be square");
 
-                  FloatCHOL fact;
-                  fact.set (R);
-                  fact.delete_sym (j-1);
+  if (j < 0 && j > n)
+    error ("choldelete: index J out of range");
 
-                  retval(0) = get_chol_r (fact);
-                }
-              else
-                {
-                  // complex case
-                  FloatComplexMatrix R = argr.float_complex_matrix_value ();
-
-                  FloatComplexCHOL fact;
-                  fact.set (R);
-                  fact.delete_sym (j-1);
+  octave_value_list retval;
 
-                  retval(0) = get_chol_r (fact);
-                }
-            }
-          else
-            {
-              if (argr.is_real_type ())
-                {
-                  // real case
-                  Matrix R = argr.matrix_value ();
-
-                  CHOL fact;
-                  fact.set (R);
-                  fact.delete_sym (j-1);
+  if (argr.is_single_type ())
+    {
+      if (argr.is_real_type ())
+        {
+          // real case
+          FloatMatrix R = argr.float_matrix_value ();
 
-                  retval(0) = get_chol_r (fact);
-                }
-              else
-                {
-                  // complex case
-                  ComplexMatrix R = argr.complex_matrix_value ();
+          FloatCHOL fact;
+          fact.set (R);
+          fact.delete_sym (j-1);
 
-                  ComplexCHOL fact;
-                  fact.set (R);
-                  fact.delete_sym (j-1);
-
-                  retval(0) = get_chol_r (fact);
-                }
-            }
+          retval = ovl (get_chol_r (fact));
         }
       else
-        error ("choldelete: index J out of range");
+        {
+          // complex case
+          FloatComplexMatrix R = argr.float_complex_matrix_value ();
+
+          FloatComplexCHOL fact;
+          fact.set (R);
+          fact.delete_sym (j-1);
+
+          retval = ovl (get_chol_r (fact));
+        }
     }
   else
-    error ("choldelete: matrix R must be square");
+    {
+      if (argr.is_real_type ())
+        {
+          // real case
+          Matrix R = argr.matrix_value ();
+
+          CHOL fact;
+          fact.set (R);
+          fact.delete_sym (j-1);
+
+          retval = ovl (get_chol_r (fact));
+        }
+      else
+        {
+          // complex case
+          ComplexMatrix R = argr.complex_matrix_value ();
+
+          ComplexCHOL fact;
+          fact.set (R);
+          fact.delete_sym (j-1);
+
+          retval = ovl (get_chol_r (fact));
+        }
+    }
 
   return retval;
 }
@@ -1133,8 +1128,6 @@
 @seealso{chol, cholupdate, cholinsert, choldelete}\n\
 @end deftypefn")
 {
-  octave_value_list retval;
-
   if (args.length () != 3)
     print_usage ();
 
@@ -1150,68 +1143,65 @@
   octave_idx_type i = argi.scalar_value ();
   octave_idx_type j = argj.scalar_value ();
 
-  if (argr.columns () == n)
-    {
-      if (j > 0 && j <= n+1 && i > 0 && i <= n+1)
-        {
-
-          if (argr.is_single_type () && argi.is_single_type ()
-              && argj.is_single_type ())
-            {
-              if (argr.is_real_type ())
-                {
-                  // real case
-                  FloatMatrix R = argr.float_matrix_value ();
+  if (argr.columns () != n)
+    error ("cholshift: R must be a square matrix");
 
-                  FloatCHOL fact;
-                  fact.set (R);
-                  fact.shift_sym (i-1, j-1);
+  if (j < 0 || j > n+1 || i < 0 || i > n+1)
+    error ("cholshift: index I or J is out of range");
 
-                  retval(0) = get_chol_r (fact);
-                }
-              else
-                {
-                  // complex case
-                  FloatComplexMatrix R = argr.float_complex_matrix_value ();
-
-                  FloatComplexCHOL fact;
-                  fact.set (R);
-                  fact.shift_sym (i-1, j-1);
+  octave_value_list retval;
 
-                  retval(0) = get_chol_r (fact);
-                }
-            }
-          else
-            {
-              if (argr.is_real_type ())
-                {
-                  // real case
-                  Matrix R = argr.matrix_value ();
-
-                  CHOL fact;
-                  fact.set (R);
-                  fact.shift_sym (i-1, j-1);
+  if (argr.is_single_type () && argi.is_single_type ()
+      && argj.is_single_type ())
+    {
+      if (argr.is_real_type ())
+        {
+          // real case
+          FloatMatrix R = argr.float_matrix_value ();
 
-                  retval(0) = get_chol_r (fact);
-                }
-              else
-                {
-                  // complex case
-                  ComplexMatrix R = argr.complex_matrix_value ();
+          FloatCHOL fact;
+          fact.set (R);
+          fact.shift_sym (i-1, j-1);
 
-                  ComplexCHOL fact;
-                  fact.set (R);
-                  fact.shift_sym (i-1, j-1);
-
-                  retval(0) = get_chol_r (fact);
-                }
-            }
+          retval = ovl (get_chol_r (fact));
         }
       else
-        error ("cholshift: index I or J is out of range");
+        {
+          // complex case
+          FloatComplexMatrix R = argr.float_complex_matrix_value ();
+
+          FloatComplexCHOL fact;
+          fact.set (R);
+          fact.shift_sym (i-1, j-1);
+
+          retval = ovl (get_chol_r (fact));
+        }
     }
   else
-    error ("cholshift: R must be a square matrix");
+    {
+      if (argr.is_real_type ())
+        {
+          // real case
+          Matrix R = argr.matrix_value ();
+
+          CHOL fact;
+          fact.set (R);
+          fact.shift_sym (i-1, j-1);
+
+          retval = ovl (get_chol_r (fact));
+        }
+      else
+        {
+          // complex case
+          ComplexMatrix R = argr.complex_matrix_value ();
+
+          ComplexCHOL fact;
+          fact.set (R);
+          fact.shift_sym (i-1, j-1);
+
+          retval = ovl (get_chol_r (fact));
+        }
+    }
 
   return retval;
 }