Mercurial > octave
changeset 22372:0c0de2205d38
utils.h: deprecated out of date arg_is_empty function.
* libinterp/corefcn/utils.h, libinterp/corefcn/utils.cc: this function
"documentation" no longer matches its behaviour. It's still used in Octave
by checking a returned int, but the function now returns a bool and does
the same as octave_value.is_empty (). Deprecate in favout of it.
* det.cc, hess.cc, inv.cc, lu.cc, pinv.cc, sylvester.cc, chol.cc,
qz.cc: replace use of empty_arg with octave_value::is_empty.
* qr.cc: different becase it was only checking '< 0' which was always
false. Simply remove check and go through the normal code path, even if
it was empty. Add tests.
author | Carnë Draug <carandraug@octave.org> |
---|---|
date | Sun, 14 Aug 2016 13:09:46 +0100 |
parents | f7ff29ff2763 |
children | 59d66abc27d0 |
files | libinterp/corefcn/det.cc libinterp/corefcn/hess.cc libinterp/corefcn/inv.cc libinterp/corefcn/lu.cc libinterp/corefcn/pinv.cc libinterp/corefcn/qz.cc libinterp/corefcn/sylvester.cc libinterp/corefcn/utils.cc libinterp/corefcn/utils.h libinterp/dldfcn/chol.cc libinterp/dldfcn/qr.cc |
diffstat | 11 files changed, 24 insertions(+), 85 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/det.cc Tue Aug 23 20:36:48 2016 -0700 +++ b/libinterp/corefcn/det.cc Sun Aug 14 13:09:46 2016 +0100 @@ -30,7 +30,6 @@ #include "error.h" #include "errwarn.h" #include "ovl.h" -#include "utils.h" #include "ops.h" #include "ov-re-mat.h" @@ -70,19 +69,10 @@ octave_value arg = args(0); - octave_idx_type nr = arg.rows (); - octave_idx_type nc = arg.columns (); - - if (nr == 0 && nc == 0) + if (arg.is_empty ()) return ovl (1.0); - int arg_is_empty = empty_arg ("det", nr, nc); - if (arg_is_empty < 0) - return ovl (); - if (arg_is_empty > 0) - return ovl (1.0); - - if (nr != nc) + if (arg.rows () != arg.columns ()) err_square_matrix_required ("det", "A"); octave_value_list retval (2);
--- a/libinterp/corefcn/hess.cc Tue Aug 23 20:36:48 2016 -0700 +++ b/libinterp/corefcn/hess.cc Sun Aug 14 13:09:46 2016 +0100 @@ -30,7 +30,6 @@ #include "error.h" #include "errwarn.h" #include "ovl.h" -#include "utils.h" DEFUN (hess, args, nargout, doc: /* -*- texinfo -*- @@ -66,17 +65,10 @@ octave_value arg = args(0); - octave_idx_type nr = arg.rows (); - octave_idx_type nc = arg.columns (); - - int arg_is_empty = empty_arg ("hess", nr, nc); - - if (arg_is_empty < 0) - return ovl (); - else if (arg_is_empty > 0) + if (arg.is_empty ()) return octave_value_list (2, Matrix ()); - if (nr != nc) + if (arg.rows () != arg.columns ()) err_square_matrix_required ("hess", "A"); octave_value_list retval;
--- a/libinterp/corefcn/inv.cc Tue Aug 23 20:36:48 2016 -0700 +++ b/libinterp/corefcn/inv.cc Sun Aug 14 13:09:46 2016 +0100 @@ -34,7 +34,6 @@ #include "ov-flt-re-diag.h" #include "ov-flt-cx-diag.h" #include "ov-perm.h" -#include "utils.h" DEFUN (inv, args, nargout, doc: /* -*- texinfo -*- @@ -63,17 +62,10 @@ octave_value arg = args(0); - octave_idx_type nr = arg.rows (); - octave_idx_type nc = arg.columns (); - - int arg_is_empty = empty_arg ("inverse", nr, nc); - - if (arg_is_empty < 0) - return ovl (); - else if (arg_is_empty > 0) + if (arg.is_empty ()) return ovl (Matrix ()); - if (nr != nc) + if (arg.rows () != arg.columns ()) err_square_matrix_required ("inverse", "A"); octave_value result;
--- a/libinterp/corefcn/lu.cc Tue Aug 23 20:36:48 2016 -0700 +++ b/libinterp/corefcn/lu.cc Sun Aug 14 13:09:46 2016 +0100 @@ -31,7 +31,6 @@ #include "error.h" #include "errwarn.h" #include "ovl.h" -#include "utils.h" #include "ov-re-sparse.h" #include "ov-cx-sparse.h" @@ -186,13 +185,9 @@ octave_idx_type nr = arg.rows (); octave_idx_type nc = arg.columns (); - int arg_is_empty = empty_arg ("lu", nr, nc); - if (issparse) { - if (arg_is_empty < 0) - return ovl (); - else if (arg_is_empty > 0) + if (arg.is_empty ()) return octave_value_list (5, SparseMatrix ()); if (arg.is_real_type ()) @@ -330,9 +325,7 @@ } else { - if (arg_is_empty < 0) - return ovl (); - else if (arg_is_empty > 0) + if (arg.is_empty ()) return octave_value_list (3, Matrix ()); if (arg.is_real_type ())
--- a/libinterp/corefcn/pinv.cc Tue Aug 23 20:36:48 2016 -0700 +++ b/libinterp/corefcn/pinv.cc Sun Aug 14 13:09:46 2016 +0100 @@ -28,7 +28,6 @@ #include "error.h" #include "errwarn.h" #include "ovl.h" -#include "utils.h" #include "ops.h" #include "ov-re-diag.h" #include "ov-cx-diag.h" @@ -61,11 +60,7 @@ octave_value arg = args(0); - int arg_is_empty = empty_arg ("pinv", arg.rows (), arg.columns ()); - - if (arg_is_empty < 0) - return ovl (); - else if (arg_is_empty > 0) + if (arg.is_empty ()) return ovl (Matrix ()); octave_value retval;
--- a/libinterp/corefcn/qz.cc Tue Aug 23 20:36:48 2016 -0700 +++ b/libinterp/corefcn/qz.cc Sun Aug 14 13:09:46 2016 +0100 @@ -297,14 +297,7 @@ octave_value_list retval; - int arg_is_empty = empty_arg ("qz", nn, args(0).columns ()); - - if (arg_is_empty < 0) - { - warn_empty_arg ("qz: parameter 1"); - return retval; - } - else if (arg_is_empty > 0) + if (args(0).is_empty ()) { warn_empty_arg ("qz: parameter 1; continuing"); return octave_value_list (2, Matrix ());
--- a/libinterp/corefcn/sylvester.cc Tue Aug 23 20:36:48 2016 -0700 +++ b/libinterp/corefcn/sylvester.cc Sun Aug 14 13:09:46 2016 +0100 @@ -30,7 +30,6 @@ #include "error.h" #include "errwarn.h" #include "ovl.h" -#include "utils.h" DEFUN (sylvester, args, , doc: /* -*- texinfo -*- @@ -78,21 +77,17 @@ octave_idx_type c_nr = arg_c.rows (); octave_idx_type c_nc = arg_c.columns (); - int arg_a_is_empty = empty_arg ("sylvester", a_nr, a_nc); - int arg_b_is_empty = empty_arg ("sylvester", b_nr, b_nc); - int arg_c_is_empty = empty_arg ("sylvester", c_nr, c_nc); - bool isfloat = arg_a.is_single_type () || arg_b.is_single_type () || arg_c.is_single_type (); - if (arg_a_is_empty > 0 && arg_b_is_empty > 0 && arg_c_is_empty > 0) - if (isfloat) - return ovl (FloatMatrix ()); - else - return ovl (Matrix ()); - else if (arg_a_is_empty || arg_b_is_empty || arg_c_is_empty) - return retval; + if (arg_a.is_empty () || arg_b.is_empty () || arg_c.is_empty ()) + { + if (isfloat) + return ovl (FloatMatrix ()); + else + return ovl (Matrix ()); + } // Arguments are not empty, so check for correct dimensions.
--- a/libinterp/corefcn/utils.cc Tue Aug 23 20:36:48 2016 -0700 +++ b/libinterp/corefcn/utils.cc Sun Aug 14 13:09:46 2016 +0100 @@ -235,9 +235,6 @@ return status; } -// Return nonzero if either NR or NC is zero. -// Return -1 if this should be considered fatal; return 1 if this is ok. - int empty_arg (const char * /* name */, octave_idx_type nr, octave_idx_type nc) {
--- a/libinterp/corefcn/utils.h Tue Aug 23 20:36:48 2016 -0700 +++ b/libinterp/corefcn/utils.h Sun Aug 14 13:09:46 2016 +0100 @@ -54,6 +54,7 @@ const std::string& s, int min_toks_to_match, int max_toks); +OCTAVE_DEPRECATED ("use 'octave_value::is_empty' instead") extern OCTINTERP_API int empty_arg (const char *name, octave_idx_type nr, octave_idx_type nc);
--- a/libinterp/dldfcn/chol.cc Tue Aug 23 20:36:48 2016 -0700 +++ b/libinterp/dldfcn/chol.cc Sun Aug 14 13:09:46 2016 +0100 @@ -39,7 +39,6 @@ #include "error.h" #include "errwarn.h" #include "ovl.h" -#include "utils.h" #include "oct-string.h" @@ -179,14 +178,7 @@ octave_value_list retval; octave_value arg = args(0); - octave_idx_type nr = arg.rows (); - octave_idx_type nc = arg.columns (); - - int arg_is_empty = empty_arg ("chol", nr, nc); - - if (arg_is_empty < 0) - return ovl (); - if (arg_is_empty > 0) + if (arg.is_empty ()) return ovl (Matrix ()); if (arg.is_sparse_type ())
--- a/libinterp/dldfcn/qr.cc Tue Aug 23 20:36:48 2016 -0700 +++ b/libinterp/dldfcn/qr.cc Sun Aug 14 13:09:46 2016 +0100 @@ -34,7 +34,6 @@ #include "error.h" #include "errwarn.h" #include "ovl.h" -#include "utils.h" template <typename MT> static octave_value @@ -225,11 +224,6 @@ octave_value arg = args(0); - int arg_is_empty = empty_arg ("qr", arg.rows (), arg.columns ()); - - if (arg_is_empty < 0) - return retval; - bool economy = false; bool is_cmplx = false; bool have_b = 0; @@ -573,6 +567,11 @@ %! assert (r, re, sqrt (eps)); %! assert (q'*b, c, sqrt (eps)); +%!test +%! assert (qr (zeros (0, 0)), zeros (0, 0)) +%! assert (qr (zeros (1, 0)), zeros (1, 0)) +%! assert (qr (zeros (0, 1)), zeros (0, 1)) + %!error qr () %!error qr ([1, 2; 3, 4], 0, 2)