diff libinterp/corefcn/bsxfun.cc @ 20802:8bb38ba1bad6

eliminate return statements after calls to print_usage * __contourc__.cc, __dispatch__.cc, __dsearchn__.cc, __ichol__.cc, __lin_interpn__.cc, __qp__.cc, balance.cc, betainc.cc, bsxfun.cc, colloc.cc, daspk.cc, dasrt.cc, dassl.cc, defaults.cc, det.cc, dlmread.cc, dot.cc, eig.cc, ellipj.cc, fft.cc, fft2.cc, fftn.cc, filter.cc, find.cc, gcd.cc, givens.cc, hex2num.cc, inv.cc, lookup.cc, lu.cc, max.cc, mgorth.cc, ordschur.cc, pinv.cc, profiler.cc, quad.cc, qz.cc, rcond.cc, schur.cc, str2double.cc: Eliminate return statements after calls to print_usage.
author John W. Eaton <jwe@octave.org>
date Fri, 04 Dec 2015 12:03:44 -0500
parents f90c8372b7ba
children f428cbe7576f
line wrap: on
line diff
--- a/libinterp/corefcn/bsxfun.cc	Thu Dec 03 19:22:54 2015 -0500
+++ b/libinterp/corefcn/bsxfun.cc	Fri Dec 04 12:03:44 2015 -0500
@@ -135,8 +135,10 @@
 
 #define REGISTER_OP_HANDLER(OP, BTYP, NDA, FUNOP) \
   bsxfun_handler_table[OP][BTYP] = bsxfun_forward_op<NDA, FUNOP>
+
 #define REGISTER_REL_HANDLER(REL, BTYP, NDA, FUNREL) \
   bsxfun_handler_table[REL][BTYP] = bsxfun_forward_rel<NDA, FUNREL>
+
 #define REGISTER_STD_HANDLERS(BTYP, NDA) \
   REGISTER_OP_HANDLER (bsxfun_builtin_plus, BTYP, NDA, bsxfun_add); \
   REGISTER_OP_HANDLER (bsxfun_builtin_minus, BTYP, NDA, bsxfun_sub); \
@@ -338,132 +340,131 @@
 
   if (nargin != 3)
     print_usage ();
-  else
-    {
-      octave_value func = args(0);
+
+  octave_value func = args(0);
 
-      if (func.is_string ())
-        {
-          std::string name = func.string_value ();
-          func = symbol_table::find_function (name);
-          if (func.is_undefined ())
-            error ("bsxfun: invalid function name: %s", name.c_str ());
-        }
-      else if (! (args(0).is_function_handle ()
-               || args(0).is_inline_function ()))
-        error ("bsxfun: F must be a string or function handle");
+  if (func.is_string ())
+    {
+      std::string name = func.string_value ();
+      func = symbol_table::find_function (name);
+      if (func.is_undefined ())
+        error ("bsxfun: invalid function name: %s", name.c_str ());
+    }
+  else if (! (args(0).is_function_handle ()
+              || args(0).is_inline_function ()))
+    error ("bsxfun: F must be a string or function handle");
+
+  const octave_value A = args(1);
+  const octave_value B = args(2);
 
-      const octave_value A = args(1);
-      const octave_value B = args(2);
-
-      if (func.is_builtin_function ()
-          || (func.is_function_handle ()
-              && ! A.is_object () && ! B.is_object ()))
+  if (func.is_builtin_function ()
+      || (func.is_function_handle ()
+          && ! A.is_object () && ! B.is_object ()))
+    {
+      // This may break if the default behavior is overridden.  But if you
+      // override arithmetic operators for builtin classes, you should
+      // expect mayhem anyway (constant folding etc).  Querying
+      // is_overloaded() may not be exactly what we need here.
+      octave_function *fcn_val = func.function_value ();
+      if (fcn_val)
         {
-          // This may break if the default behavior is overridden.  But if you
-          // override arithmetic operators for builtin classes, you should
-          // expect mayhem anyway (constant folding etc).  Querying
-          // is_overloaded() may not be exactly what we need here.
-          octave_function *fcn_val = func.function_value ();
-          if (fcn_val)
-            {
-              octave_value tmp = maybe_optimized_builtin (fcn_val->name (),
-                                                          A, B);
-              if (tmp.is_defined ())
-                retval(0) = tmp;
-            }
+          octave_value tmp = maybe_optimized_builtin (fcn_val->name (),
+                                                      A, B);
+          if (tmp.is_defined ())
+            retval(0) = tmp;
+        }
+    }
+
+  if (retval.empty ())
+    {
+      dim_vector dva = A.dims ();
+      octave_idx_type nda = dva.length ();
+      dim_vector dvb = B.dims ();
+      octave_idx_type ndb = dvb.length ();
+      octave_idx_type nd = nda;
+
+      if (nda > ndb)
+        dvb.resize (nda, 1);
+      else if (nda < ndb)
+        {
+          dva.resize (ndb, 1);
+          nd = ndb;
         }
 
-      if (retval.empty ())
-        {
-          dim_vector dva = A.dims ();
-          octave_idx_type nda = dva.length ();
-          dim_vector dvb = B.dims ();
-          octave_idx_type ndb = dvb.length ();
-          octave_idx_type nd = nda;
+      for (octave_idx_type i = 0; i < nd; i++)
+        if (dva(i) != dvb(i) && dva(i) != 1 && dvb(i) != 1)
+          {
+            error ("bsxfun: dimensions of A and B must match");
+            break;
+          }
 
-          if (nda > ndb)
-            dvb.resize (nda, 1);
-          else if (nda < ndb)
-            {
-              dva.resize (ndb, 1);
-              nd = ndb;
-            }
+      // Find the size of the output
+      dim_vector dvc;
+      dvc.resize (nd);
 
-          for (octave_idx_type i = 0; i < nd; i++)
-            if (dva(i) != dvb(i) && dva(i) != 1 && dvb(i) != 1)
-              {
-                error ("bsxfun: dimensions of A and B must match");
-                break;
-              }
+      for (octave_idx_type i = 0; i < nd; i++)
+        dvc(i) = (dva(i) < 1 ? dva(i)
+                  : (dvb(i) < 1 ? dvb(i)
+                     : (dva(i) > dvb(i)
+                        ? dva(i) : dvb(i))));
 
-          // Find the size of the output
-          dim_vector dvc;
-          dvc.resize (nd);
-
-          for (octave_idx_type i = 0; i < nd; i++)
-            dvc(i) = (dva(i) < 1 ? dva(i)
-                                 : (dvb(i) < 1 ? dvb(i)
-                                               : (dva(i) > dvb(i)
-                                                   ? dva(i) : dvb(i))));
-
-          if (dva == dvb || dva.numel () == 1 || dvb.numel () == 1)
-            {
-              octave_value_list inputs;
-              inputs (0) = A;
-              inputs (1) = B;
-              retval = func.do_multi_index_op (1, inputs);
-            }
-          else if (dvc.numel () < 1)
-            {
-              octave_value_list inputs;
-              inputs (0) = A.resize (dvc);
-              inputs (1) = B.resize (dvc);
-              retval = func.do_multi_index_op (1, inputs);
-            }
-          else
-            {
-              octave_idx_type ncount = 1;
-              for (octave_idx_type i = 1; i < nd; i++)
-                ncount *= dvc(i);
+      if (dva == dvb || dva.numel () == 1 || dvb.numel () == 1)
+        {
+          octave_value_list inputs;
+          inputs (0) = A;
+          inputs (1) = B;
+          retval = func.do_multi_index_op (1, inputs);
+        }
+      else if (dvc.numel () < 1)
+        {
+          octave_value_list inputs;
+          inputs (0) = A.resize (dvc);
+          inputs (1) = B.resize (dvc);
+          retval = func.do_multi_index_op (1, inputs);
+        }
+      else
+        {
+          octave_idx_type ncount = 1;
+          for (octave_idx_type i = 1; i < nd; i++)
+            ncount *= dvc(i);
 
 #define BSXDEF(T) \
-              T result_ ## T; \
-              bool have_ ## T = false;
+  T result_ ## T; \
+  bool have_ ## T = false;
 
-              BSXDEF(NDArray);
-              BSXDEF(ComplexNDArray);
-              BSXDEF(FloatNDArray);
-              BSXDEF(FloatComplexNDArray);
-              BSXDEF(boolNDArray);
-              BSXDEF(int8NDArray);
-              BSXDEF(int16NDArray);
-              BSXDEF(int32NDArray);
-              BSXDEF(int64NDArray);
-              BSXDEF(uint8NDArray);
-              BSXDEF(uint16NDArray);
-              BSXDEF(uint32NDArray);
-              BSXDEF(uint64NDArray);
+          BSXDEF(NDArray);
+          BSXDEF(ComplexNDArray);
+          BSXDEF(FloatNDArray);
+          BSXDEF(FloatComplexNDArray);
+          BSXDEF(boolNDArray);
+          BSXDEF(int8NDArray);
+          BSXDEF(int16NDArray);
+          BSXDEF(int32NDArray);
+          BSXDEF(int64NDArray);
+          BSXDEF(uint8NDArray);
+          BSXDEF(uint16NDArray);
+          BSXDEF(uint32NDArray);
+          BSXDEF(uint64NDArray);
 
-              octave_value Ac ;
-              octave_value_list idxA;
-              octave_value Bc;
-              octave_value_list idxB;
-              octave_value C;
-              octave_value_list inputs;
-              Array<int> ra_idx (dim_vector (dvc.length (), 1), 0);
+          octave_value Ac ;
+          octave_value_list idxA;
+          octave_value Bc;
+          octave_value_list idxB;
+          octave_value C;
+          octave_value_list inputs;
+          Array<int> ra_idx (dim_vector (dvc.length (), 1), 0);
 
 
-              for (octave_idx_type i = 0; i < ncount; i++)
-                {
-                  if (maybe_update_column (Ac, A, dva, dvc, i, idxA))
-                    inputs (0) = Ac;
+          for (octave_idx_type i = 0; i < ncount; i++)
+            {
+              if (maybe_update_column (Ac, A, dva, dvc, i, idxA))
+                inputs (0) = Ac;
 
-                  if (maybe_update_column (Bc, B, dvb, dvc, i, idxB))
-                    inputs (1) = Bc;
+              if (maybe_update_column (Bc, B, dvb, dvc, i, idxB))
+                inputs (1) = Bc;
 
-                  octave_value_list tmp = func.do_multi_index_op (1,
-                                                                  inputs);
+              octave_value_list tmp = func.do_multi_index_op (1,
+                                                              inputs);
 
 #define BSXINIT(T, CLS, EXTRACTOR) \
   (result_type == CLS) \
@@ -473,138 +474,138 @@
       result_ ## T .resize (dvc); \
     }
 
-                  if (i == 0)
+              if (i == 0)
+                {
+                  if (! tmp(0).is_sparse_type ())
                     {
-                      if (! tmp(0).is_sparse_type ())
+                      std::string result_type = tmp(0).class_name ();
+                      if (result_type == "double")
                         {
-                          std::string result_type = tmp(0).class_name ();
-                          if (result_type == "double")
+                          if (tmp(0).is_real_type ())
                             {
-                              if (tmp(0).is_real_type ())
-                                {
-                                  have_NDArray = true;
-                                  result_NDArray = tmp(0).array_value ();
-                                  result_NDArray.resize (dvc);
-                                }
-                              else
-                                {
-                                  have_ComplexNDArray = true;
-                                  result_ComplexNDArray =
-                                    tmp(0).complex_array_value ();
-                                  result_ComplexNDArray.resize (dvc);
-                                }
+                              have_NDArray = true;
+                              result_NDArray = tmp(0).array_value ();
+                              result_NDArray.resize (dvc);
                             }
-                          else if (result_type == "single")
+                          else
                             {
-                              if (tmp(0).is_real_type ())
-                                {
-                                  have_FloatNDArray = true;
-                                  result_FloatNDArray
-                                    = tmp(0).float_array_value ();
-                                  result_FloatNDArray.resize (dvc);
-                                }
-                              else
-                                {
-                                  have_ComplexNDArray = true;
-                                  result_ComplexNDArray =
-                                    tmp(0).complex_array_value ();
-                                  result_ComplexNDArray.resize (dvc);
-                                }
+                              have_ComplexNDArray = true;
+                              result_ComplexNDArray =
+                                tmp(0).complex_array_value ();
+                              result_ComplexNDArray.resize (dvc);
                             }
-                          else if BSXINIT(boolNDArray, "logical", bool)
-                          else if BSXINIT(int8NDArray, "int8", int8)
-                          else if BSXINIT(int16NDArray, "int16", int16)
-                          else if BSXINIT(int32NDArray, "int32", int32)
-                          else if BSXINIT(int64NDArray, "int64", int64)
-                          else if BSXINIT(uint8NDArray, "uint8", uint8)
-                          else if BSXINIT(uint16NDArray, "uint16", uint16)
-                          else if BSXINIT(uint32NDArray, "uint32", uint32)
-                          else if BSXINIT(uint64NDArray, "uint64", uint64)
+                        }
+                      else if (result_type == "single")
+                        {
+                          if (tmp(0).is_real_type ())
+                            {
+                              have_FloatNDArray = true;
+                              result_FloatNDArray
+                                = tmp(0).float_array_value ();
+                              result_FloatNDArray.resize (dvc);
+                            }
                           else
                             {
-                              C = tmp (0);
-                              C = C.resize (dvc);
+                              have_ComplexNDArray = true;
+                              result_ComplexNDArray =
+                                tmp(0).complex_array_value ();
+                              result_ComplexNDArray.resize (dvc);
+                            }
+                        }
+                      else if BSXINIT(boolNDArray, "logical", bool)
+                        else if BSXINIT(int8NDArray, "int8", int8)
+                          else if BSXINIT(int16NDArray, "int16", int16)
+                            else if BSXINIT(int32NDArray, "int32", int32)
+                              else if BSXINIT(int64NDArray, "int64", int64)
+                                else if BSXINIT(uint8NDArray, "uint8", uint8)
+                                  else if BSXINIT(uint16NDArray, "uint16", uint16)
+                                    else if BSXINIT(uint32NDArray, "uint32", uint32)
+                                      else if BSXINIT(uint64NDArray, "uint64", uint64)
+                                        else
+                                          {
+                                            C = tmp (0);
+                                            C = C.resize (dvc);
+                                          }
+                    }
+                }
+              else
+                {
+                  update_index (ra_idx, dvc, i);
+
+                  if (have_FloatNDArray
+                      || have_FloatComplexNDArray)
+                    {
+                      if (! tmp(0).is_float_type ())
+                        {
+                          if (have_FloatNDArray)
+                            {
+                              have_FloatNDArray = false;
+                              C = result_FloatNDArray;
                             }
+                          else
+                            {
+                              have_FloatComplexNDArray = false;
+                              C = result_FloatComplexNDArray;
+                            }
+                          C = do_cat_op (C, tmp(0), ra_idx);
+                        }
+                      else if (tmp(0).is_double_type ())
+                        {
+                          if (tmp(0).is_complex_type ()
+                              && have_FloatNDArray)
+                            {
+                              result_ComplexNDArray =
+                                ComplexNDArray (result_FloatNDArray);
+                              result_ComplexNDArray.insert
+                                (tmp(0).complex_array_value (), ra_idx);
+                              have_FloatComplexNDArray = false;
+                              have_ComplexNDArray = true;
+                            }
+                          else
+                            {
+                              result_NDArray =
+                                NDArray (result_FloatNDArray);
+                              result_NDArray.insert
+                                (tmp(0).array_value (), ra_idx);
+                              have_FloatNDArray = false;
+                              have_NDArray = true;
+                            }
+                        }
+                      else if (tmp(0).is_real_type ())
+                        result_FloatNDArray.insert
+                          (tmp(0).float_array_value (), ra_idx);
+                      else
+                        {
+                          result_FloatComplexNDArray =
+                            FloatComplexNDArray (result_FloatNDArray);
+                          result_FloatComplexNDArray.insert
+                            (tmp(0).float_complex_array_value (),
+                             ra_idx);
+                          have_FloatNDArray = false;
+                          have_FloatComplexNDArray = true;
                         }
                     }
-                  else
+                  else if (have_NDArray)
                     {
-                      update_index (ra_idx, dvc, i);
-
-                      if (have_FloatNDArray
-                          || have_FloatComplexNDArray)
+                      if (! tmp(0).is_float_type ())
                         {
-                          if (! tmp(0).is_float_type ())
-                            {
-                              if (have_FloatNDArray)
-                                {
-                                  have_FloatNDArray = false;
-                                  C = result_FloatNDArray;
-                                }
-                              else
-                                {
-                                  have_FloatComplexNDArray = false;
-                                  C = result_FloatComplexNDArray;
-                                }
-                              C = do_cat_op (C, tmp(0), ra_idx);
-                            }
-                          else if (tmp(0).is_double_type ())
-                            {
-                              if (tmp(0).is_complex_type ()
-                                  && have_FloatNDArray)
-                                {
-                                  result_ComplexNDArray =
-                                    ComplexNDArray (result_FloatNDArray);
-                                  result_ComplexNDArray.insert
-                                    (tmp(0).complex_array_value (), ra_idx);
-                                  have_FloatComplexNDArray = false;
-                                  have_ComplexNDArray = true;
-                                }
-                              else
-                                {
-                                  result_NDArray =
-                                    NDArray (result_FloatNDArray);
-                                  result_NDArray.insert
-                                    (tmp(0).array_value (), ra_idx);
-                                  have_FloatNDArray = false;
-                                  have_NDArray = true;
-                                }
-                            }
-                          else if (tmp(0).is_real_type ())
-                            result_FloatNDArray.insert
-                              (tmp(0).float_array_value (), ra_idx);
-                          else
-                            {
-                              result_FloatComplexNDArray =
-                                FloatComplexNDArray (result_FloatNDArray);
-                              result_FloatComplexNDArray.insert
-                                (tmp(0).float_complex_array_value (),
-                                 ra_idx);
-                              have_FloatNDArray = false;
-                              have_FloatComplexNDArray = true;
-                            }
+                          have_NDArray = false;
+                          C = result_NDArray;
+                          C = do_cat_op (C, tmp(0), ra_idx);
                         }
-                      else if (have_NDArray)
+                      else if (tmp(0).is_real_type ())
+                        result_NDArray.insert (tmp(0).array_value (),
+                                               ra_idx);
+                      else
                         {
-                          if (! tmp(0).is_float_type ())
-                            {
-                              have_NDArray = false;
-                              C = result_NDArray;
-                              C = do_cat_op (C, tmp(0), ra_idx);
-                            }
-                          else if (tmp(0).is_real_type ())
-                            result_NDArray.insert (tmp(0).array_value (),
-                                                   ra_idx);
-                          else
-                            {
-                              result_ComplexNDArray =
-                                ComplexNDArray (result_NDArray);
-                              result_ComplexNDArray.insert
-                                (tmp(0).complex_array_value (), ra_idx);
-                              have_NDArray = false;
-                              have_ComplexNDArray = true;
-                            }
+                          result_ComplexNDArray =
+                            ComplexNDArray (result_NDArray);
+                          result_ComplexNDArray.insert
+                            (tmp(0).complex_array_value (), ra_idx);
+                          have_NDArray = false;
+                          have_ComplexNDArray = true;
                         }
+                    }
 
 #define BSXLOOP(T, CLS, EXTRACTOR) \
   (have_ ## T) \
@@ -619,41 +620,40 @@
         result_ ## T .insert (tmp(0). EXTRACTOR ## _array_value (), ra_idx); \
     }
 
-                      else if BSXLOOP(ComplexNDArray, "double", complex)
-                      else if BSXLOOP(boolNDArray, "logical", bool)
-                      else if BSXLOOP(int8NDArray, "int8", int8)
-                      else if BSXLOOP(int16NDArray, "int16", int16)
-                      else if BSXLOOP(int32NDArray, "int32", int32)
-                      else if BSXLOOP(int64NDArray, "int64", int64)
-                      else if BSXLOOP(uint8NDArray, "uint8", uint8)
-                      else if BSXLOOP(uint16NDArray, "uint16", uint16)
-                      else if BSXLOOP(uint32NDArray, "uint32", uint32)
-                      else if BSXLOOP(uint64NDArray, "uint64", uint64)
-                      else
-                        C = do_cat_op (C, tmp(0), ra_idx);
-                    }
+                  else if BSXLOOP(ComplexNDArray, "double", complex)
+                  else if BSXLOOP(boolNDArray, "logical", bool)
+                  else if BSXLOOP(int8NDArray, "int8", int8)
+                  else if BSXLOOP(int16NDArray, "int16", int16)
+                  else if BSXLOOP(int32NDArray, "int32", int32)
+                  else if BSXLOOP(int64NDArray, "int64", int64)
+                  else if BSXLOOP(uint8NDArray, "uint8", uint8)
+                  else if BSXLOOP(uint16NDArray, "uint16", uint16)
+                  else if BSXLOOP(uint32NDArray, "uint32", uint32)
+                  else if BSXLOOP(uint64NDArray, "uint64", uint64)
+                  else
+                    C = do_cat_op (C, tmp(0), ra_idx);
                 }
+            }
 
 #define BSXEND(T) \
   (have_ ## T) \
     retval(0) = result_ ## T;
 
-              if BSXEND(NDArray)
-              else if BSXEND(ComplexNDArray)
-              else if BSXEND(FloatNDArray)
-              else if BSXEND(FloatComplexNDArray)
-              else if BSXEND(boolNDArray)
-              else if BSXEND(int8NDArray)
-              else if BSXEND(int16NDArray)
-              else if BSXEND(int32NDArray)
-              else if BSXEND(int64NDArray)
-              else if BSXEND(uint8NDArray)
-              else if BSXEND(uint16NDArray)
-              else if BSXEND(uint32NDArray)
-              else if BSXEND(uint64NDArray)
-              else
-                retval(0) = C;
-            }
+          if BSXEND(NDArray)
+          else if BSXEND(ComplexNDArray)
+          else if BSXEND(FloatNDArray)
+          else if BSXEND(FloatComplexNDArray)
+          else if BSXEND(boolNDArray)
+          else if BSXEND(int8NDArray)
+          else if BSXEND(int16NDArray)
+          else if BSXEND(int32NDArray)
+          else if BSXEND(int64NDArray)
+          else if BSXEND(uint8NDArray)
+          else if BSXEND(uint16NDArray)
+          else if BSXEND(uint32NDArray)
+          else if BSXEND(uint64NDArray)
+          else
+            retval(0) = C;
         }
     }