# HG changeset patch # User Rik # Date 1453334910 28800 # Node ID 3ac9f47fb04b06a080bb060427f7d6eb64a48cf3 # Parent c1df363732725928e9ebb79d1571bb663678cf07 Invert pattern if/code/else/err_XXX to if !/err_XXX/code. * daspk.cc, dasrt.cc, dassl.cc, data.cc, debug.cc, load-save.cc, lsode.cc, quad.cc, xnorm.cc, xpow.cc, ov-base-diag.cc, ov-base-mat.cc, ov-base-scalar.cc, ov-base.cc, ov-bool-mat.cc, ov-bool-sparse.cc, ov-cell.cc, ov-ch-mat.cc, ov-class.cc, ov-cx-mat.cc, ov-cx-sparse.cc, ov-float.cc, ov-flt-cx-mat.cc, ov-flt-re-mat.cc, ov-intx.h, ov-perm.cc, ov-range.cc, ov-re-mat.cc, ov-re-sparse.cc, ov-scalar.cc, ov-struct.cc, ov.cc, pt-idx.cc, Array-util.cc, Array.cc, Sparse.cc, lo-specfun.cc, mx-inlines.cc, oct-binmap.h: Invert pattern if/code/else/err_XXX to if !/err_XXX/code. diff -r c1df36373272 -r 3ac9f47fb04b libinterp/corefcn/daspk.cc --- a/libinterp/corefcn/daspk.cc Wed Jan 20 15:45:58 2016 -0800 +++ b/libinterp/corefcn/daspk.cc Wed Jan 20 16:08:30 2016 -0800 @@ -85,23 +85,21 @@ } int tlen = tmp.length (); - if (tlen > 0 && tmp(0).is_defined ()) - { - if (! warned_fcn_imaginary && tmp(0).is_complex_type ()) - { - warning ("daspk: ignoring imaginary part returned from user-supplied function"); - warned_fcn_imaginary = true; - } + if (tlen == 0 || ! tmp(0).is_defined ()) + err_user_supplied_eval ("daspk"); - retval = tmp(0).vector_value (); - - if (tlen > 1) - ires = tmp(1).idx_type_value (); + if (! warned_fcn_imaginary && tmp(0).is_complex_type ()) + { + warning ("daspk: ignoring imaginary part returned from user-supplied function"); + warned_fcn_imaginary = true; + } - if (retval.is_empty ()) - err_user_supplied_eval ("daspk"); - } - else + retval = tmp(0).vector_value (); + + if (tlen > 1) + ires = tmp(1).idx_type_value (); + + if (retval.is_empty ()) err_user_supplied_eval ("daspk"); } @@ -137,20 +135,18 @@ } int tlen = tmp.length (); - if (tlen > 0 && tmp(0).is_defined ()) + if (tlen == 0 || ! tmp(0).is_defined ()) + err_user_supplied_eval ("daspk"); + + if (! warned_jac_imaginary && tmp(0).is_complex_type ()) { - if (! warned_jac_imaginary && tmp(0).is_complex_type ()) - { - warning ("daspk: ignoring imaginary part returned from user-supplied jacobian function"); - warned_jac_imaginary = true; - } + warning ("daspk: ignoring imaginary part returned from user-supplied jacobian function"); + warned_jac_imaginary = true; + } - retval = tmp(0).matrix_value (); + retval = tmp(0).matrix_value (); - if (retval.is_empty ()) - err_user_supplied_eval ("daspk"); - } - else + if (retval.is_empty ()) err_user_supplied_eval ("daspk"); } diff -r c1df36373272 -r 3ac9f47fb04b libinterp/corefcn/dasrt.cc --- a/libinterp/corefcn/dasrt.cc Wed Jan 20 15:45:58 2016 -0800 +++ b/libinterp/corefcn/dasrt.cc Wed Jan 20 16:08:30 2016 -0800 @@ -84,20 +84,18 @@ err_user_supplied_eval (e, "dasrt"); } - if (tmp.length () > 0 && tmp(0).is_defined ()) + if (tmp.length () < 1 || ! tmp(0).is_defined ()) + err_user_supplied_eval ("dasrt"); + + if (! warned_fcn_imaginary && tmp(0).is_complex_type ()) { - if (! warned_fcn_imaginary && tmp(0).is_complex_type ()) - { - warning ("dasrt: ignoring imaginary part returned from user-supplied function"); - warned_fcn_imaginary = true; - } + warning ("dasrt: ignoring imaginary part returned from user-supplied function"); + warned_fcn_imaginary = true; + } - retval = tmp(0).vector_value (); + retval = tmp(0).vector_value (); - if (retval.is_empty ()) - err_user_supplied_eval ("dasrt"); - } - else + if (retval.is_empty ()) err_user_supplied_eval ("dasrt"); } @@ -127,20 +125,18 @@ err_user_supplied_eval (e, "dasrt"); } - if (tmp.length () > 0 && tmp(0).is_defined ()) + if (tmp.length () == 0 || ! tmp(0).is_defined ()) + err_user_supplied_eval ("dasrt"); + + if (! warned_cf_imaginary && tmp(0).is_complex_type ()) { - if (! warned_cf_imaginary && tmp(0).is_complex_type ()) - { - warning ("dasrt: ignoring imaginary part returned from user-supplied constraint function"); - warned_cf_imaginary = true; - } + warning ("dasrt: ignoring imaginary part returned from user-supplied constraint function"); + warned_cf_imaginary = true; + } - retval = tmp(0).vector_value (); + retval = tmp(0).vector_value (); - if (retval.is_empty ()) - err_user_supplied_eval ("dasrt"); - } - else + if (retval.is_empty ()) err_user_supplied_eval ("dasrt"); } @@ -176,20 +172,18 @@ } int tlen = tmp.length (); - if (tlen > 0 && tmp(0).is_defined ()) + if (tlen == 0 || ! tmp(0).is_defined ()) + err_user_supplied_eval ("dasrt"); + + if (! warned_jac_imaginary && tmp(0).is_complex_type ()) { - if (! warned_jac_imaginary && tmp(0).is_complex_type ()) - { - warning ("dasrt: ignoring imaginary part returned from user-supplied jacobian function"); - warned_jac_imaginary = true; - } + warning ("dasrt: ignoring imaginary part returned from user-supplied jacobian function"); + warned_jac_imaginary = true; + } - retval = tmp(0).matrix_value (); + retval = tmp(0).matrix_value (); - if (retval.is_empty ()) - err_user_supplied_eval ("dasrt"); - } - else + if (retval.is_empty ()) err_user_supplied_eval ("dasrt"); } diff -r c1df36373272 -r 3ac9f47fb04b libinterp/corefcn/dassl.cc --- a/libinterp/corefcn/dassl.cc Wed Jan 20 15:45:58 2016 -0800 +++ b/libinterp/corefcn/dassl.cc Wed Jan 20 16:08:30 2016 -0800 @@ -85,23 +85,21 @@ } int tlen = tmp.length (); - if (tlen > 0 && tmp(0).is_defined ()) - { - if (! warned_fcn_imaginary && tmp(0).is_complex_type ()) - { - warning ("dassl: ignoring imaginary part returned from user-supplied function"); - warned_fcn_imaginary = true; - } + if (tlen == 0 || ! tmp(0).is_defined ()) + err_user_supplied_eval ("dassl"); - retval = tmp(0).vector_value (); - - if (tlen > 1) - ires = tmp(1).int_value (); + if (! warned_fcn_imaginary && tmp(0).is_complex_type ()) + { + warning ("dassl: ignoring imaginary part returned from user-supplied function"); + warned_fcn_imaginary = true; + } - if (retval.is_empty ()) - err_user_supplied_eval ("dassl"); - } - else + retval = tmp(0).vector_value (); + + if (tlen > 1) + ires = tmp(1).int_value (); + + if (retval.is_empty ()) err_user_supplied_eval ("dassl"); } @@ -137,20 +135,18 @@ } int tlen = tmp.length (); - if (tlen > 0 && tmp(0).is_defined ()) + if (tlen == 0 || ! tmp(0).is_defined ()) + err_user_supplied_eval ("dassl"); + + if (! warned_jac_imaginary && tmp(0).is_complex_type ()) { - if (! warned_jac_imaginary && tmp(0).is_complex_type ()) - { - warning ("dassl: ignoring imaginary part returned from user-supplied jacobian function"); - warned_jac_imaginary = true; - } + warning ("dassl: ignoring imaginary part returned from user-supplied jacobian function"); + warned_jac_imaginary = true; + } - retval = tmp(0).matrix_value (); + retval = tmp(0).matrix_value (); - if (retval.is_empty ()) - err_user_supplied_eval ("dassl"); - } - else + if (retval.is_empty ()) err_user_supplied_eval ("dassl"); } diff -r c1df36373272 -r 3ac9f47fb04b libinterp/corefcn/data.cc --- a/libinterp/corefcn/data.cc Wed Jan 20 15:45:58 2016 -0800 +++ b/libinterp/corefcn/data.cc Wed Jan 20 16:08:30 2016 -0800 @@ -340,42 +340,40 @@ octave_value arg1 = y; if (! arg0.is_numeric_type ()) err_wrong_type_arg ("hypot", arg0); - else if (! arg1.is_numeric_type ()) + if (! arg1.is_numeric_type ()) err_wrong_type_arg ("hypot", arg1); + + if (arg0.is_complex_type ()) + arg0 = arg0.abs (); + if (arg1.is_complex_type ()) + arg1 = arg1.abs (); + + if (arg0.is_single_type () || arg1.is_single_type ()) + { + if (arg0.is_scalar_type () && arg1.is_scalar_type ()) + retval = hypotf (arg0.float_value (), arg1.float_value ()); + else + { + FloatNDArray a0 = arg0.float_array_value (); + FloatNDArray a1 = arg1.float_array_value (); + retval = binmap (a0, a1, ::hypotf, "hypot"); + } + } else { - if (arg0.is_complex_type ()) - arg0 = arg0.abs (); - if (arg1.is_complex_type ()) - arg1 = arg1.abs (); - - if (arg0.is_single_type () || arg1.is_single_type ()) + if (arg0.is_scalar_type () && arg1.is_scalar_type ()) + retval = hypot (arg0.scalar_value (), arg1.scalar_value ()); + else if (arg0.is_sparse_type () || arg1.is_sparse_type ()) { - if (arg0.is_scalar_type () && arg1.is_scalar_type ()) - retval = hypotf (arg0.float_value (), arg1.float_value ()); - else - { - FloatNDArray a0 = arg0.float_array_value (); - FloatNDArray a1 = arg1.float_array_value (); - retval = binmap (a0, a1, ::hypotf, "hypot"); - } + SparseMatrix m0 = arg0.sparse_matrix_value (); + SparseMatrix m1 = arg1.sparse_matrix_value (); + retval = binmap (m0, m1, ::hypot, "hypot"); } else { - if (arg0.is_scalar_type () && arg1.is_scalar_type ()) - retval = hypot (arg0.scalar_value (), arg1.scalar_value ()); - else if (arg0.is_sparse_type () || arg1.is_sparse_type ()) - { - SparseMatrix m0 = arg0.sparse_matrix_value (); - SparseMatrix m1 = arg1.sparse_matrix_value (); - retval = binmap (m0, m1, ::hypot, "hypot"); - } - else - { - NDArray a0 = arg0.array_value (); - NDArray a1 = arg1.array_value (); - retval = binmap (a0, a1, ::hypot, "hypot"); - } + NDArray a0 = arg0.array_value (); + NDArray a1 = arg1.array_value (); + retval = binmap (a0, a1, ::hypot, "hypot"); } } diff -r c1df36373272 -r 3ac9f47fb04b libinterp/corefcn/debug.cc --- a/libinterp/corefcn/debug.cc Wed Jan 20 15:45:58 2016 -0800 +++ b/libinterp/corefcn/debug.cc Wed Jan 20 16:08:30 2016 -0800 @@ -723,14 +723,12 @@ if (nargin == 1) { - if (args(0).is_string ()) - { - symbol_name = args(0).string_value (); - fcn_list(0) = symbol_name; - bp_list = bp_table::get_breakpoint_list (fcn_list); - } - else + if (! args(0).is_string ()) err_wrong_type_arg ("dbstatus", args(0)); + + symbol_name = args(0).string_value (); + fcn_list(0) = symbol_name; + bp_list = bp_table::get_breakpoint_list (fcn_list); } else { diff -r c1df36373272 -r 3ac9f47fb04b libinterp/corefcn/load-save.cc --- a/libinterp/corefcn/load-save.cc Wed Jan 20 15:45:58 2016 -0800 +++ b/libinterp/corefcn/load-save.cc Wed Jan 20 16:08:30 2016 -0800 @@ -765,16 +765,14 @@ hdf5_ifstream hdf5_file (fname.c_str ()); - if (hdf5_file.file_id >= 0) - { - retval = do_load (hdf5_file, orig_fname, format, - flt_fmt, list_only, swap, verbose, - argv, i, argc, nargout); + if (hdf5_file.file_id < 0) + err_file_open ("load", orig_fname); - hdf5_file.close (); - } - else - err_file_open ("load", orig_fname); + retval = do_load (hdf5_file, orig_fname, format, + flt_fmt, list_only, swap, verbose, + argv, i, argc, nargout); + + hdf5_file.close (); } else #endif @@ -793,35 +791,33 @@ { gzifstream file (fname.c_str (), mode); - if (file) + if (! file) + err_file_open ("load", orig_fname); + + if (format == LS_BINARY) { - if (format == LS_BINARY) - { - if (read_binary_file_header (file, swap, flt_fmt) < 0) - { - if (file) file.close (); - return retval; - } - } - else if (format == LS_MAT5_BINARY - || format == LS_MAT7_BINARY) + if (read_binary_file_header (file, swap, flt_fmt) < 0) { - if (read_mat5_binary_file_header (file, swap, false, - orig_fname) < 0) - { - if (file) file.close (); - return retval; - } + if (file) file.close (); + return retval; } + } + else if (format == LS_MAT5_BINARY + || format == LS_MAT7_BINARY) + { + if (read_mat5_binary_file_header (file, swap, false, + orig_fname) < 0) + { + if (file) file.close (); + return retval; + } + } - retval = do_load (file, orig_fname, format, - flt_fmt, list_only, swap, verbose, - argv, i, argc, nargout); + retval = do_load (file, orig_fname, format, + flt_fmt, list_only, swap, verbose, + argv, i, argc, nargout); - file.close (); - } - else - err_file_open ("load", orig_fname); + file.close (); } else #endif @@ -1666,15 +1662,13 @@ hdf5_ofstream hdf5_file (fname.c_str (), mode); - if (hdf5_file.file_id != -1) - { - save_vars (argv, i, argc, hdf5_file, format, - save_as_floats, write_header_info); + if (hdf5_file.file_id == -1) + err_file_open ("save", fname); - hdf5_file.close (); - } - else - err_file_open ("save", fname); + save_vars (argv, i, argc, hdf5_file, format, + save_as_floats, write_header_info); + + hdf5_file.close (); } else #endif @@ -1686,34 +1680,30 @@ { gzofstream file (fname.c_str (), mode); - if (file) - { - bool write_header_info = ! file.tellp (); + if (! file) + err_file_open ("save", fname); + + bool write_header_info = ! file.tellp (); - save_vars (argv, i, argc, file, format, - save_as_floats, write_header_info); + save_vars (argv, i, argc, file, format, + save_as_floats, write_header_info); - file.close (); - } - else - err_file_open ("save", fname); + file.close (); } else #endif { std::ofstream file (fname.c_str (), mode); - if (file) - { - bool write_header_info = ! file.tellp (); + if (! file) + err_file_open ("save", fname); + + bool write_header_info = ! file.tellp (); - save_vars (argv, i, argc, file, format, - save_as_floats, write_header_info); + save_vars (argv, i, argc, file, format, + save_as_floats, write_header_info); - file.close (); - } - else - err_file_open ("save", fname); + file.close (); } } } diff -r c1df36373272 -r 3ac9f47fb04b libinterp/corefcn/lsode.cc --- a/libinterp/corefcn/lsode.cc Wed Jan 20 15:45:58 2016 -0800 +++ b/libinterp/corefcn/lsode.cc Wed Jan 20 16:08:30 2016 -0800 @@ -81,20 +81,18 @@ err_user_supplied_eval (e, "lsode"); } - if (tmp.length () > 0 && tmp(0).is_defined ()) + if (tmp.length () == 0 || ! tmp(0).is_defined ()) + err_user_supplied_eval ("lsode"); + + if (! warned_fcn_imaginary && tmp(0).is_complex_type ()) { - if (! warned_fcn_imaginary && tmp(0).is_complex_type ()) - { - warning ("lsode: ignoring imaginary part returned from user-supplied function"); - warned_fcn_imaginary = true; - } + warning ("lsode: ignoring imaginary part returned from user-supplied function"); + warned_fcn_imaginary = true; + } - retval = tmp(0).xvector_value ("lsode: expecting user supplied function to return numeric vector"); + retval = tmp(0).xvector_value ("lsode: expecting user supplied function to return numeric vector"); - if (retval.is_empty ()) - err_user_supplied_eval ("lsode"); - } - else + if (retval.is_empty ()) err_user_supplied_eval ("lsode"); } @@ -123,20 +121,18 @@ err_user_supplied_eval (e, "lsode"); } - if (tmp.length () > 0 && tmp(0).is_defined ()) + if (tmp.length () == 0 || ! tmp(0).is_defined ()) + err_user_supplied_eval ("lsode"); + + if (! warned_jac_imaginary && tmp(0).is_complex_type ()) { - if (! warned_jac_imaginary && tmp(0).is_complex_type ()) - { - warning ("lsode: ignoring imaginary part returned from user-supplied jacobian function"); - warned_jac_imaginary = true; - } + warning ("lsode: ignoring imaginary part returned from user-supplied jacobian function"); + warned_jac_imaginary = true; + } - retval = tmp(0).xmatrix_value ("lsode: expecting user supplied jacobian function to return numeric array"); + retval = tmp(0).xmatrix_value ("lsode: expecting user supplied jacobian function to return numeric array"); - if (retval.is_empty ()) - err_user_supplied_eval ("lsode"); - } - else + if (retval.is_empty ()) err_user_supplied_eval ("lsode"); } diff -r c1df36373272 -r 3ac9f47fb04b libinterp/corefcn/quad.cc --- a/libinterp/corefcn/quad.cc Wed Jan 20 15:45:58 2016 -0800 +++ b/libinterp/corefcn/quad.cc Wed Jan 20 16:08:30 2016 -0800 @@ -78,18 +78,16 @@ err_user_supplied_eval (e, "quad"); } - if (tmp.length () && tmp(0).is_defined ()) + if (! tmp.length () || ! tmp(0).is_defined ()) + err_user_supplied_eval ("quad"); + + if (! warned_imaginary && tmp(0).is_complex_type ()) { - if (! warned_imaginary && tmp(0).is_complex_type ()) - { - warning ("quad: ignoring imaginary part returned from user-supplied function"); - warned_imaginary = true; - } + warning ("quad: ignoring imaginary part returned from user-supplied function"); + warned_imaginary = true; + } - retval = tmp(0).xdouble_value ("quad: expecting user supplied function to return numeric value"); - } - else - err_user_supplied_eval ("quad"); + retval = tmp(0).xdouble_value ("quad: expecting user supplied function to return numeric value"); } return retval; @@ -116,19 +114,16 @@ err_user_supplied_eval (e, "quad"); } - if (tmp.length () && tmp(0).is_defined ()) + if (! tmp.length () || ! tmp(0).is_defined ()) + err_user_supplied_eval ("quad"); + + if (! warned_imaginary && tmp(0).is_complex_type ()) { - if (! warned_imaginary && tmp(0).is_complex_type ()) - { - warning ("quad: ignoring imaginary part returned from user-supplied function"); - warned_imaginary = true; - } + warning ("quad: ignoring imaginary part returned from user-supplied function"); + warned_imaginary = true; + } - retval = tmp(0).xfloat_value ("quad: expecting user supplied function to return numeric value"); - - } - else - err_user_supplied_eval ("quad"); + retval = tmp(0).xfloat_value ("quad: expecting user supplied function to return numeric value"); } return retval; diff -r c1df36373272 -r 3ac9f47fb04b libinterp/corefcn/xnorm.cc --- a/libinterp/corefcn/xnorm.cc Wed Jan 20 15:45:58 2016 -0800 +++ b/libinterp/corefcn/xnorm.cc Wed Jan 20 16:08:30 2016 -0800 @@ -46,52 +46,50 @@ bool issparse = x.is_sparse_type (); bool isfloat = x.is_single_type (); - if (isfloat || x.is_double_type ()) + if (! isfloat && ! x.is_double_type ()) + err_wrong_type_arg ("xnorm", x); + + if (x.is_empty ()) + retval = octave_value (0); + else if (isvector) { - if (x.is_empty ()) - retval = octave_value (0); - else if (isvector) - { - if (isfloat & iscomplex) - retval = xnorm (x.float_complex_column_vector_value (), - p.float_value ()); - else if (isfloat) - retval = xnorm (x.float_column_vector_value (), - p.float_value ()); - else if (iscomplex) - retval = xnorm (x.complex_column_vector_value (), - p.double_value ()); - else - retval = xnorm (x.column_vector_value (), - p.double_value ()); - } - else if (issparse) - { - if (iscomplex) - retval = xnorm (x.sparse_complex_matrix_value (), - p.double_value ()); - else - retval = xnorm (x.sparse_matrix_value (), - p.double_value ()); - } + if (isfloat & iscomplex) + retval = xnorm (x.float_complex_column_vector_value (), + p.float_value ()); + else if (isfloat) + retval = xnorm (x.float_column_vector_value (), + p.float_value ()); + else if (iscomplex) + retval = xnorm (x.complex_column_vector_value (), + p.double_value ()); else - { - if (isfloat & iscomplex) - retval = xnorm (x.float_complex_matrix_value (), - p.float_value ()); - else if (isfloat) - retval = xnorm (x.float_matrix_value (), - p.float_value ()); - else if (iscomplex) - retval = xnorm (x.complex_matrix_value (), - p.double_value ()); - else - retval = xnorm (x.matrix_value (), - p.double_value ()); - } + retval = xnorm (x.column_vector_value (), + p.double_value ()); + } + else if (issparse) + { + if (iscomplex) + retval = xnorm (x.sparse_complex_matrix_value (), + p.double_value ()); + else + retval = xnorm (x.sparse_matrix_value (), + p.double_value ()); } else - err_wrong_type_arg ("xnorm", x); + { + if (isfloat & iscomplex) + retval = xnorm (x.float_complex_matrix_value (), + p.float_value ()); + else if (isfloat) + retval = xnorm (x.float_matrix_value (), + p.float_value ()); + else if (iscomplex) + retval = xnorm (x.complex_matrix_value (), + p.double_value ()); + else + retval = xnorm (x.matrix_value (), + p.double_value ()); + } return retval; } @@ -104,35 +102,33 @@ bool issparse = x.is_sparse_type (); bool isfloat = x.is_single_type (); - if (isfloat || x.is_double_type ()) + if (! isfloat && ! x.is_double_type ()) + err_wrong_type_arg ("xcolnorms", x); + + if (issparse) { - if (issparse) - { - if (iscomplex) - retval = xcolnorms (x.sparse_complex_matrix_value (), - p.double_value ()); - else - retval = xcolnorms (x.sparse_matrix_value (), - p.double_value ()); - } + if (iscomplex) + retval = xcolnorms (x.sparse_complex_matrix_value (), + p.double_value ()); else - { - if (isfloat & iscomplex) - retval = xcolnorms (x.float_complex_matrix_value (), - p.float_value ()); - else if (isfloat) - retval = xcolnorms (x.float_matrix_value (), - p.float_value ()); - else if (iscomplex) - retval = xcolnorms (x.complex_matrix_value (), - p.double_value ()); - else - retval = xcolnorms (x.matrix_value (), - p.double_value ()); - } + retval = xcolnorms (x.sparse_matrix_value (), + p.double_value ()); } else - err_wrong_type_arg ("xcolnorms", x); + { + if (isfloat & iscomplex) + retval = xcolnorms (x.float_complex_matrix_value (), + p.float_value ()); + else if (isfloat) + retval = xcolnorms (x.float_matrix_value (), + p.float_value ()); + else if (iscomplex) + retval = xcolnorms (x.complex_matrix_value (), + p.double_value ()); + else + retval = xcolnorms (x.matrix_value (), + p.double_value ()); + } return retval; } @@ -145,35 +141,33 @@ bool issparse = x.is_sparse_type (); bool isfloat = x.is_single_type (); - if (isfloat || x.is_double_type ()) + if (! isfloat && ! x.is_double_type ()) + err_wrong_type_arg ("xrownorms", x); + + if (issparse) { - if (issparse) - { - if (iscomplex) - retval = xrownorms (x.sparse_complex_matrix_value (), - p.double_value ()); - else - retval = xrownorms (x.sparse_matrix_value (), - p.double_value ()); - } + if (iscomplex) + retval = xrownorms (x.sparse_complex_matrix_value (), + p.double_value ()); else - { - if (isfloat & iscomplex) - retval = xrownorms (x.float_complex_matrix_value (), - p.float_value ()); - else if (isfloat) - retval = xrownorms (x.float_matrix_value (), - p.float_value ()); - else if (iscomplex) - retval = xrownorms (x.complex_matrix_value (), - p.double_value ()); - else - retval = xrownorms (x.matrix_value (), - p.double_value ()); - } + retval = xrownorms (x.sparse_matrix_value (), + p.double_value ()); } else - err_wrong_type_arg ("xrownorms", x); + { + if (isfloat & iscomplex) + retval = xrownorms (x.float_complex_matrix_value (), + p.float_value ()); + else if (isfloat) + retval = xrownorms (x.float_matrix_value (), + p.float_value ()); + else if (iscomplex) + retval = xrownorms (x.complex_matrix_value (), + p.double_value ()); + else + retval = xrownorms (x.matrix_value (), + p.double_value ()); + } return retval; } @@ -186,29 +180,27 @@ bool issparse = x.is_sparse_type (); bool isfloat = x.is_single_type (); - if (isfloat || x.is_double_type ()) + if (! isfloat && ! x.is_double_type ()) + err_wrong_type_arg ("xfrobnorm", x); + + if (issparse) { - if (issparse) - { - if (iscomplex) - retval = xfrobnorm (x.sparse_complex_matrix_value ()); - else - retval = xfrobnorm (x.sparse_matrix_value ()); - } + if (iscomplex) + retval = xfrobnorm (x.sparse_complex_matrix_value ()); else - { - if (isfloat & iscomplex) - retval = xfrobnorm (x.float_complex_matrix_value ()); - else if (isfloat) - retval = xfrobnorm (x.float_matrix_value ()); - else if (iscomplex) - retval = xfrobnorm (x.complex_matrix_value ()); - else - retval = xfrobnorm (x.matrix_value ()); - } + retval = xfrobnorm (x.sparse_matrix_value ()); } else - err_wrong_type_arg ("xfrobnorm", x); + { + if (isfloat & iscomplex) + retval = xfrobnorm (x.float_complex_matrix_value ()); + else if (isfloat) + retval = xfrobnorm (x.float_matrix_value ()); + else if (iscomplex) + retval = xfrobnorm (x.complex_matrix_value ()); + else + retval = xfrobnorm (x.matrix_value ()); + } return retval; } diff -r c1df36373272 -r 3ac9f47fb04b libinterp/corefcn/xpow.cc --- a/libinterp/corefcn/xpow.cc Wed Jan 20 15:45:58 2016 -0800 +++ b/libinterp/corefcn/xpow.cc Wed Jan 20 16:08:30 2016 -0800 @@ -1231,18 +1231,16 @@ if (a_dims != b_dims) { - if (is_valid_bsxfun ("operator .^", a_dims, b_dims)) - { - //Potentially complex results - NDArray xa = octave_value_extract (a); - NDArray xb = octave_value_extract (b); - if (! xb.all_integers () && xa.any_element_is_negative ()) - return octave_value (bsxfun_pow (ComplexNDArray (xa), xb)); - else - return octave_value (bsxfun_pow (xa, xb)); - } + if (! is_valid_bsxfun ("operator .^", a_dims, b_dims)) + err_nonconformant ("operator .^", a_dims, b_dims); + + //Potentially complex results + NDArray xa = octave_value_extract (a); + NDArray xb = octave_value_extract (b); + if (! xb.all_integers () && xa.any_element_is_negative ()) + return octave_value (bsxfun_pow (ComplexNDArray (xa), xb)); else - err_nonconformant ("operator .^", a_dims, b_dims); + return octave_value (bsxfun_pow (xa, xb)); } int len = a.numel (); @@ -1316,12 +1314,10 @@ if (a_dims != b_dims) { - if (is_valid_bsxfun ("operator .^", a_dims, b_dims)) - { - return bsxfun_pow (a, b); - } - else + if (! is_valid_bsxfun ("operator .^", a_dims, b_dims)) err_nonconformant ("operator .^", a_dims, b_dims); + + return bsxfun_pow (a, b); } ComplexNDArray result (a_dims); @@ -1412,12 +1408,10 @@ if (a_dims != b_dims) { - if (is_valid_bsxfun ("operator .^", a_dims, b_dims)) - { - return bsxfun_pow (a, b); - } - else + if (! is_valid_bsxfun ("operator .^", a_dims, b_dims)) err_nonconformant ("operator .^", a_dims, b_dims); + + return bsxfun_pow (a, b); } ComplexNDArray result (a_dims); @@ -1459,12 +1453,10 @@ if (a_dims != b_dims) { - if (is_valid_bsxfun ("operator .^", a_dims, b_dims)) - { - return bsxfun_pow (a, b); - } - else + if (! is_valid_bsxfun ("operator .^", a_dims, b_dims)) err_nonconformant ("operator .^", a_dims, b_dims); + + return bsxfun_pow (a, b); } ComplexNDArray result (a_dims); @@ -2553,18 +2545,16 @@ if (a_dims != b_dims) { - if (is_valid_bsxfun ("operator .^", a_dims, b_dims)) - { - //Potentially complex results - FloatNDArray xa = octave_value_extract (a); - FloatNDArray xb = octave_value_extract (b); - if (! xb.all_integers () && xa.any_element_is_negative ()) - return octave_value (bsxfun_pow (FloatComplexNDArray (xa), xb)); - else - return octave_value (bsxfun_pow (xa, xb)); - } + if (! is_valid_bsxfun ("operator .^", a_dims, b_dims)) + err_nonconformant ("operator .^", a_dims, b_dims); + + //Potentially complex results + FloatNDArray xa = octave_value_extract (a); + FloatNDArray xb = octave_value_extract (b); + if (! xb.all_integers () && xa.any_element_is_negative ()) + return octave_value (bsxfun_pow (FloatComplexNDArray (xa), xb)); else - err_nonconformant ("operator .^", a_dims, b_dims); + return octave_value (bsxfun_pow (xa, xb)); } int len = a.numel (); @@ -2638,12 +2628,10 @@ if (a_dims != b_dims) { - if (is_valid_bsxfun ("operator .^", a_dims, b_dims)) - { - return bsxfun_pow (a, b); - } - else + if (! is_valid_bsxfun ("operator .^", a_dims, b_dims)) err_nonconformant ("operator .^", a_dims, b_dims); + + return bsxfun_pow (a, b); } FloatComplexNDArray result (a_dims); @@ -2734,12 +2722,10 @@ if (a_dims != b_dims) { - if (is_valid_bsxfun ("operator .^", a_dims, b_dims)) - { - return bsxfun_pow (a, b); - } - else + if (! is_valid_bsxfun ("operator .^", a_dims, b_dims)) err_nonconformant ("operator .^", a_dims, b_dims); + + return bsxfun_pow (a, b); } FloatComplexNDArray result (a_dims); @@ -2781,12 +2767,10 @@ if (a_dims != b_dims) { - if (is_valid_bsxfun ("operator .^", a_dims, b_dims)) - { - return bsxfun_pow (a, b); - } - else + if (! is_valid_bsxfun ("operator .^", a_dims, b_dims)) err_nonconformant ("operator .^", a_dims, b_dims); + + return bsxfun_pow (a, b); } FloatComplexNDArray result (a_dims); diff -r c1df36373272 -r 3ac9f47fb04b libinterp/octave-value/ov-base-diag.cc --- a/libinterp/octave-value/ov-base-diag.cc Wed Jan 20 15:45:58 2016 -0800 +++ b/libinterp/octave-value/ov-base-diag.cc Wed Jan 20 16:08:30 2016 -0800 @@ -300,15 +300,13 @@ warn_implicit_conversion ("Octave:imag-to-real", "complex matrix", "real scalar"); - if (numel () > 0) - { - warn_implicit_conversion ("Octave:array-to-scalar", - type_name (), "real scalar"); + if (numel () == 0) + err_invalid_conversion (type_name (), "real scalar"); - retval = helper_getreal (el_type (matrix (0, 0))); - } - else - err_invalid_conversion (type_name (), "real scalar"); + warn_implicit_conversion ("Octave:array-to-scalar", + type_name (), "real scalar"); + + retval = helper_getreal (el_type (matrix (0, 0))); return retval; } @@ -345,15 +343,13 @@ Complex retval (tmp, tmp); - if (rows () > 0 && columns () > 0) - { - warn_implicit_conversion ("Octave:array-to-scalar", - type_name (), "complex scalar"); + if (rows () == 0 || columns () == 0) + err_invalid_conversion (type_name (), "complex scalar"); - retval = matrix (0, 0); - } - else - err_invalid_conversion (type_name (), "complex scalar"); + warn_implicit_conversion ("Octave:array-to-scalar", + type_name (), "complex scalar"); + + retval = matrix (0, 0); return retval; } @@ -366,15 +362,13 @@ FloatComplex retval (tmp, tmp); - if (rows () > 0 && columns () > 0) - { - warn_implicit_conversion ("Octave:array-to-scalar", - type_name (), "complex scalar"); + if (rows () == 0 || columns () == 0) + err_invalid_conversion (type_name (), "complex scalar"); - retval = matrix (0, 0); - } - else - err_invalid_conversion (type_name (), "complex scalar"); + warn_implicit_conversion ("Octave:array-to-scalar", + type_name (), "complex scalar"); + + retval = matrix (0, 0); return retval; } diff -r c1df36373272 -r 3ac9f47fb04b libinterp/octave-value/ov-base-mat.cc --- a/libinterp/octave-value/ov-base-mat.cc Wed Jan 20 15:45:58 2016 -0800 +++ b/libinterp/octave-value/ov-base-mat.cc Wed Jan 20 16:08:30 2016 -0800 @@ -415,12 +415,10 @@ if (t1.any_element_is_nan ()) err_nan_to_logical_conversion (); - else - { - boolNDArray t2 = t1.all (); - retval = t2(0); - } + boolNDArray t2 = t1.all (); + + retval = t2(0); } return retval; diff -r c1df36373272 -r 3ac9f47fb04b libinterp/octave-value/ov-base-scalar.cc --- a/libinterp/octave-value/ov-base-scalar.cc Wed Jan 20 15:45:58 2016 -0800 +++ b/libinterp/octave-value/ov-base-scalar.cc Wed Jan 20 16:08:30 2016 -0800 @@ -131,14 +131,10 @@ bool octave_base_scalar::is_true (void) const { - bool retval = false; - if (xisnan (scalar)) err_nan_to_logical_conversion (); - else - retval = (scalar != ST ()); - return retval; + return (scalar != ST ()); } template diff -r c1df36373272 -r 3ac9f47fb04b libinterp/octave-value/ov-base.cc --- a/libinterp/octave-value/ov-base.cc Wed Jan 20 15:45:58 2016 -0800 +++ b/libinterp/octave-value/ov-base.cc Wed Jan 20 16:08:30 2016 -0800 @@ -1363,24 +1363,19 @@ octave_base_value::type_conv_fcn cf = octave_value_typeinfo::lookup_widening_op (t_lhs, t_result); - if (cf) - { - octave_base_value *tmp = cf (*this); + if (! cf) + err_indexed_assignment (type_name (), rhs.type_name ()); - if (tmp) - { - octave_value val (tmp); + octave_base_value *tmp = cf (*this); - retval = val.subsasgn (type, idx, rhs); + if (! tmp) + err_assign_conversion_failed (type_name (), rhs.type_name ()); - done = true; - } - else - err_assign_conversion_failed (type_name (), - rhs.type_name ()); - } - else - err_indexed_assignment (type_name (), rhs.type_name ()); + octave_value val (tmp); + + retval = val.subsasgn (type, idx, rhs); + + done = true; } if (! done) @@ -1412,11 +1407,10 @@ { octave_base_value *tmp = cf_rhs (rhs.get_rep ()); - if (tmp) - tmp_rhs = octave_value (tmp); - else - err_assign_conversion_failed (type_name (), - rhs.type_name ()); + if (! tmp) + err_assign_conversion_failed (type_name (), rhs.type_name ()); + + tmp_rhs = octave_value (tmp); } else tmp_rhs = rhs; @@ -1428,23 +1422,20 @@ { octave_base_value *tmp = cf_this (*this); - if (tmp) - tmp_lhs = octave_value (tmp); - else - err_assign_conversion_failed (type_name (), - rhs.type_name ()); + if (! tmp) + err_assign_conversion_failed (type_name (), rhs.type_name ()); + + tmp_lhs = octave_value (tmp); } - if (cf_this || cf_rhs) - { - retval = tmp_lhs.subsasgn (type, idx, tmp_rhs); - - done = true; - } - else + if (! cf_this && ! cf_rhs) err_no_conversion (octave_value::assign_op_as_string (octave_value::op_asn_eq), type_name (), rhs.type_name ()); + + retval = tmp_lhs.subsasgn (type, idx, tmp_rhs); + + done = true; } } diff -r c1df36373272 -r 3ac9f47fb04b libinterp/octave-value/ov-bool-mat.cc --- a/libinterp/octave-value/ov-bool-mat.cc Wed Jan 20 15:45:58 2016 -0800 +++ b/libinterp/octave-value/ov-bool-mat.cc Wed Jan 20 16:08:30 2016 -0800 @@ -96,15 +96,13 @@ { double retval = lo_ieee_nan_value (); - if (rows () > 0 && columns () > 0) - { - warn_implicit_conversion ("Octave:array-to-scalar", - "bool matrix", "real scalar"); + if (rows () == 0 || columns () == 0) + err_invalid_conversion ("bool matrix", "real scalar"); - retval = matrix (0, 0); - } - else - err_invalid_conversion ("bool matrix", "real scalar"); + warn_implicit_conversion ("Octave:array-to-scalar", + "bool matrix", "real scalar"); + + retval = matrix(0, 0); return retval; } @@ -114,15 +112,13 @@ { float retval = lo_ieee_float_nan_value (); - if (rows () > 0 && columns () > 0) - { - warn_implicit_conversion ("Octave:array-to-scalar", - "bool matrix", "real scalar"); + if (rows () == 0 || columns () == 0) + err_invalid_conversion ("bool matrix", "real scalar"); - retval = matrix (0, 0); - } - else - err_invalid_conversion ("bool matrix", "real scalar"); + warn_implicit_conversion ("Octave:array-to-scalar", + "bool matrix", "real scalar"); + + retval = matrix(0, 0); return retval; } @@ -134,15 +130,13 @@ Complex retval (tmp, tmp); - if (rows () > 0 && columns () > 0) - { - warn_implicit_conversion ("Octave:array-to-scalar", - "bool matrix", "complex scalar"); + if (rows () == 0 || columns () == 0) + err_invalid_conversion ("bool matrix", "complex scalar"); - retval = matrix (0, 0); - } - else - err_invalid_conversion ("bool matrix", "complex scalar"); + warn_implicit_conversion ("Octave:array-to-scalar", + "bool matrix", "complex scalar"); + + retval = matrix(0, 0); return retval; } @@ -154,15 +148,13 @@ FloatComplex retval (tmp, tmp); - if (rows () > 0 && columns () > 0) - { - warn_implicit_conversion ("Octave:array-to-scalar", - "bool matrix", "complex scalar"); + if (rows () == 0 || columns () == 0) + err_invalid_conversion ("bool matrix", "complex scalar"); - retval = matrix (0, 0); - } - else - err_invalid_conversion ("bool matrix", "complex scalar"); + warn_implicit_conversion ("Octave:array-to-scalar", + "bool matrix", "complex scalar"); + + retval = matrix(0, 0); return retval; } diff -r c1df36373272 -r 3ac9f47fb04b libinterp/octave-value/ov-bool-sparse.cc --- a/libinterp/octave-value/ov-bool-sparse.cc Wed Jan 20 15:45:58 2016 -0800 +++ b/libinterp/octave-value/ov-bool-sparse.cc Wed Jan 20 16:08:30 2016 -0800 @@ -102,16 +102,14 @@ { double retval = lo_ieee_nan_value (); - if (numel () > 0) - { - if (numel () > 1) - warn_implicit_conversion ("Octave:array-to-scalar", - "bool sparse matrix", "real scalar"); + if (numel () == 0) + err_invalid_conversion ("bool sparse matrix", "real scalar"); - retval = matrix (0, 0); - } - else - err_invalid_conversion ("bool sparse matrix", "real scalar"); + if (numel () > 1) + warn_implicit_conversion ("Octave:array-to-scalar", + "bool sparse matrix", "real scalar"); + + retval = matrix(0, 0); return retval; } @@ -123,16 +121,14 @@ Complex retval (tmp, tmp); - if (rows () > 0 && columns () > 0) - { - if (numel () > 1) - warn_implicit_conversion ("Octave:array-to-scalar", - "bool sparse matrix", "complex scalar"); + if (rows () == 0 || columns () == 0) + err_invalid_conversion ("bool sparse matrix", "complex scalar"); - retval = matrix (0, 0); - } - else - err_invalid_conversion ("bool sparse matrix", "complex scalar"); + if (numel () > 1) + warn_implicit_conversion ("Octave:array-to-scalar", + "bool sparse matrix", "complex scalar"); + + retval = matrix(0, 0); return retval; } diff -r c1df36373272 -r 3ac9f47fb04b libinterp/octave-value/ov-cell.cc --- a/libinterp/octave-value/ov-cell.cc Wed Jan 20 15:45:58 2016 -0800 +++ b/libinterp/octave-value/ov-cell.cc Wed Jan 20 16:08:30 2016 -0800 @@ -287,24 +287,22 @@ std::string next_type = type.substr (1); - if (tmpc.numel () == 1) - { - octave_value tmp = tmpc(0); - tmpc = Cell (); + if (tmpc.numel () != 1) + err_indexed_cs_list (); - if (! tmp.is_defined () || tmp.is_zero_by_zero ()) - { - tmp = octave_value::empty_conv (type.substr (1), rhs); - tmp.make_unique (); // probably a no-op. - } - else - // optimization: ignore copy still stored inside array. - tmp.make_unique (1); + octave_value tmp = tmpc(0); + tmpc = Cell (); - t_rhs = tmp.subsasgn (next_type, next_idx, rhs); + if (! tmp.is_defined () || tmp.is_zero_by_zero ()) + { + tmp = octave_value::empty_conv (type.substr (1), rhs); + tmp.make_unique (); // probably a no-op. } else - err_indexed_cs_list (); + // optimization: ignore copy still stored inside array. + tmp.make_unique (1); + + t_rhs = tmp.subsasgn (next_type, next_idx, rhs); } break; diff -r c1df36373272 -r 3ac9f47fb04b libinterp/octave-value/ov-ch-mat.cc --- a/libinterp/octave-value/ov-ch-mat.cc Wed Jan 20 15:45:58 2016 -0800 +++ b/libinterp/octave-value/ov-ch-mat.cc Wed Jan 20 16:08:30 2016 -0800 @@ -56,15 +56,13 @@ { double retval = lo_ieee_nan_value (); - if (rows () > 0 && columns () > 0) - { - warn_implicit_conversion ("Octave:array-to-scalar", - "character matrix", "real scalar"); + if (rows () == 0 || columns () == 0) + err_invalid_conversion ("character matrix", "real scalar"); - retval = static_cast (matrix (0, 0)); - } - else - err_invalid_conversion ("character matrix", "real scalar"); + warn_implicit_conversion ("Octave:array-to-scalar", + "character matrix", "real scalar"); + + retval = static_cast (matrix(0, 0)); return retval; } @@ -74,15 +72,13 @@ { float retval = lo_ieee_float_nan_value (); - if (rows () > 0 && columns () > 0) - { - warn_implicit_conversion ("Octave:array-to-scalar", - "character matrix", "real scalar"); + if (rows () == 0 && columns () == 0) + err_invalid_conversion ("character matrix", "real scalar"); - retval = static_cast (matrix (0, 0)); - } - else - err_invalid_conversion ("character matrix", "real scalar"); + warn_implicit_conversion ("Octave:array-to-scalar", + "character matrix", "real scalar"); + + retval = static_cast (matrix(0, 0)); return retval; } @@ -92,15 +88,13 @@ { octave_int64 retval = 0; - if (rows () > 0 && columns () > 0) - { - warn_implicit_conversion ("Octave:array-to-scalar", - "character matrix", "int64 scalar"); + if (rows () == 0 || columns () == 0) + err_invalid_conversion ("character matrix", "int64 scalar"); - retval = octave_int64 (matrix (0, 0)); - } - else - err_invalid_conversion ("character matrix", "int64 scalar"); + warn_implicit_conversion ("Octave:array-to-scalar", + "character matrix", "int64 scalar"); + + retval = octave_int64 (matrix(0, 0)); return retval; } @@ -110,15 +104,13 @@ { octave_uint64 retval = 0; - if (rows () > 0 && columns () > 0) - { - warn_implicit_conversion ("Octave:array-to-scalar", - "character matrix", "uint64 scalar"); + if (rows () == 0 || columns () == 0) + err_invalid_conversion ("character matrix", "uint64 scalar"); - retval = octave_uint64 (matrix (0, 0)); - } - else - err_invalid_conversion ("character matrix", "uint64 scalar"); + warn_implicit_conversion ("Octave:array-to-scalar", + "character matrix", "uint64 scalar"); + + retval = octave_uint64 (matrix(0, 0)); return retval; } @@ -130,15 +122,13 @@ Complex retval (tmp, tmp); - if (rows () > 0 && columns () > 0) - { - warn_implicit_conversion ("Octave:array-to-scalar", - "character matrix", "complex scalar"); + if (rows () == 0 && columns () == 0) + err_invalid_conversion ("character matrix", "complex scalar"); - retval = static_cast (matrix (0, 0)); - } - else - err_invalid_conversion ("character matrix", "complex scalar"); + warn_implicit_conversion ("Octave:array-to-scalar", + "character matrix", "complex scalar"); + + retval = static_cast (matrix(0, 0)); return retval; } @@ -150,15 +140,13 @@ FloatComplex retval (tmp, tmp); - if (rows () > 0 && columns () > 0) - { - warn_implicit_conversion ("Octave:array-to-scalar", - "character matrix", "complex scalar"); + if (rows () == 0 || columns () == 0) + err_invalid_conversion ("character matrix", "complex scalar"); - retval = static_cast (matrix (0, 0)); - } - else - err_invalid_conversion ("character matrix", "complex scalar"); + warn_implicit_conversion ("Octave:array-to-scalar", + "character matrix", "complex scalar"); + + retval = static_cast (matrix(0, 0)); return retval; } diff -r c1df36373272 -r 3ac9f47fb04b libinterp/octave-value/ov-class.cc --- a/libinterp/octave-value/ov-class.cc Wed Jan 20 15:45:58 2016 -0800 +++ b/libinterp/octave-value/ov-class.cc Wed Jan 20 16:08:30 2016 -0800 @@ -481,15 +481,13 @@ { octave_value retval; - if (val.numel () == 1) - { - retval = val(0); + if (val.numel () != 1) + err_invalid_index_for_assignment (); - if (type.length () > 0 && type[0] == '.' && ! retval.is_map ()) - retval = octave_map (); - } - else - err_invalid_index_for_assignment (); + retval = val(0); + + if (type.length () > 0 && type[0] == '.' && ! retval.is_map ()) + retval = octave_map (); return retval; } @@ -683,23 +681,21 @@ } // FIXME: better code reuse? - if (tmpc.numel () == 1) - { - octave_value& tmp = tmpc(0); + if (tmpc.numel () != 1) + err_indexed_cs_list (); + + octave_value& tmp = tmpc(0); - if (! tmp.is_defined () || tmp.is_zero_by_zero ()) - { - tmp = octave_value::empty_conv (next_type, rhs); - tmp.make_unique (); // probably a no-op. - } - else - // optimization: ignore copy still stored inside our map. - tmp.make_unique (1); - - t_rhs = tmp.subsasgn (next_type, next_idx, rhs); + if (! tmp.is_defined () || tmp.is_zero_by_zero ()) + { + tmp = octave_value::empty_conv (next_type, rhs); + tmp.make_unique (); // probably a no-op. } else - err_indexed_cs_list (); + // optimization: ignore copy still stored inside our map. + tmp.make_unique (1); + + t_rhs = tmp.subsasgn (next_type, next_idx, rhs); } break; diff -r c1df36373272 -r 3ac9f47fb04b libinterp/octave-value/ov-cx-mat.cc --- a/libinterp/octave-value/ov-cx-mat.cc Wed Jan 20 15:45:58 2016 -0800 +++ b/libinterp/octave-value/ov-cx-mat.cc Wed Jan 20 16:08:30 2016 -0800 @@ -108,15 +108,13 @@ warn_implicit_conversion ("Octave:imag-to-real", "complex matrix", "real scalar"); - if (rows () > 0 && columns () > 0) - { - warn_implicit_conversion ("Octave:array-to-scalar", - "complex matrix", "real scalar"); + if (rows () == 0 || columns () == 0) + err_invalid_conversion ("complex matrix", "real scalar"); - retval = std::real (matrix (0, 0)); - } - else - err_invalid_conversion ("complex matrix", "real scalar"); + warn_implicit_conversion ("Octave:array-to-scalar", + "complex matrix", "real scalar"); + + retval = std::real (matrix(0, 0)); return retval; } @@ -130,15 +128,13 @@ warn_implicit_conversion ("Octave:imag-to-real", "complex matrix", "real scalar"); - if (rows () > 0 && columns () > 0) - { - warn_implicit_conversion ("Octave:array-to-scalar", - "complex matrix", "real scalar"); + if (rows () == 0 || columns () == 0) + err_invalid_conversion ("complex matrix", "real scalar"); - retval = std::real (matrix (0, 0)); - } - else - err_invalid_conversion ("complex matrix", "real scalar"); + warn_implicit_conversion ("Octave:array-to-scalar", + "complex matrix", "real scalar"); + + retval = std::real (matrix(0, 0)); return retval; } @@ -192,15 +188,13 @@ Complex retval (tmp, tmp); - if (rows () > 0 && columns () > 0) - { - warn_implicit_conversion ("Octave:array-to-scalar", - "complex matrix", "complex scalar"); + if (rows () == 0 || columns () == 0) + err_invalid_conversion ("complex matrix", "complex scalar"); - retval = matrix (0, 0); - } - else - err_invalid_conversion ("complex matrix", "complex scalar"); + warn_implicit_conversion ("Octave:array-to-scalar", + "complex matrix", "complex scalar"); + + retval = matrix(0, 0); return retval; } @@ -212,15 +206,13 @@ FloatComplex retval (tmp, tmp); - if (rows () > 0 && columns () > 0) - { - warn_implicit_conversion ("Octave:array-to-scalar", - "complex matrix", "complex scalar"); + if (rows () == 0 || columns () == 0) + err_invalid_conversion ("complex matrix", "complex scalar"); - retval = matrix (0, 0); - } - else - err_invalid_conversion ("complex matrix", "complex scalar"); + warn_implicit_conversion ("Octave:array-to-scalar", + "complex matrix", "complex scalar"); + + retval = matrix(0, 0); return retval; } diff -r c1df36373272 -r 3ac9f47fb04b libinterp/octave-value/ov-cx-sparse.cc --- a/libinterp/octave-value/ov-cx-sparse.cc Wed Jan 20 15:45:58 2016 -0800 +++ b/libinterp/octave-value/ov-cx-sparse.cc Wed Jan 20 16:08:30 2016 -0800 @@ -113,16 +113,14 @@ "complex sparse matrix", "real scalar"); // FIXME: maybe this should be a function, valid_as_scalar() - if (numel () > 0) - { - if (numel () > 1) - warn_implicit_conversion ("Octave:array-to-scalar", - "complex sparse matrix", "real scalar"); + if (numel () == 0) + err_invalid_conversion ("complex sparse matrix", "real scalar"); - retval = std::real (matrix (0, 0)); - } - else - err_invalid_conversion ("complex sparse matrix", "real scalar"); + if (numel () > 1) + warn_implicit_conversion ("Octave:array-to-scalar", + "complex sparse matrix", "real scalar"); + + retval = std::real (matrix(0, 0)); return retval; } @@ -149,16 +147,14 @@ Complex retval (tmp, tmp); // FIXME: maybe this should be a function, valid_as_scalar() - if (numel () > 0) - { - if (numel () > 1) - warn_implicit_conversion ("Octave:array-to-scalar", - "complex sparse matrix", "real scalar"); + if (numel () == 0) + err_invalid_conversion ("complex sparse matrix", "real scalar"); - retval = matrix (0, 0); - } - else - err_invalid_conversion ("complex sparse matrix", "real scalar"); + if (numel () > 1) + warn_implicit_conversion ("Octave:array-to-scalar", + "complex sparse matrix", "real scalar"); + + retval = matrix(0, 0); return retval; } diff -r c1df36373272 -r 3ac9f47fb04b libinterp/octave-value/ov-float.cc --- a/libinterp/octave-value/ov-float.cc Wed Jan 20 15:45:58 2016 -0800 +++ b/libinterp/octave-value/ov-float.cc Wed Jan 20 16:08:30 2016 -0800 @@ -112,21 +112,19 @@ if (xisnan (scalar)) err_nan_to_character_conversion (); - else - { - int ival = NINT (scalar); + + int ival = NINT (scalar); - if (ival < 0 || ival > std::numeric_limits::max ()) - { - // FIXME: is there something better we could do? + if (ival < 0 || ival > std::numeric_limits::max ()) + { + // FIXME: is there something better we could do? - ival = 0; + ival = 0; - ::warning ("range error for conversion to character value"); - } + ::warning ("range error for conversion to character value"); + } - retval = octave_value (std::string (1, static_cast (ival)), type); - } + retval = octave_value (std::string (1, static_cast (ival)), type); return retval; } diff -r c1df36373272 -r 3ac9f47fb04b libinterp/octave-value/ov-flt-cx-mat.cc --- a/libinterp/octave-value/ov-flt-cx-mat.cc Wed Jan 20 15:45:58 2016 -0800 +++ b/libinterp/octave-value/ov-flt-cx-mat.cc Wed Jan 20 16:08:30 2016 -0800 @@ -96,15 +96,13 @@ warn_implicit_conversion ("Octave:imag-to-real", "complex matrix", "real scalar"); - if (rows () > 0 && columns () > 0) - { - warn_implicit_conversion ("Octave:array-to-scalar", - "complex matrix", "real scalar"); + if (rows () == 0 || columns () == 0) + err_invalid_conversion ("complex matrix", "real scalar"); - retval = std::real (matrix (0, 0)); - } - else - err_invalid_conversion ("complex matrix", "real scalar"); + warn_implicit_conversion ("Octave:array-to-scalar", + "complex matrix", "real scalar"); + + retval = std::real (matrix(0, 0)); return retval; } @@ -118,15 +116,13 @@ warn_implicit_conversion ("Octave:imag-to-real", "complex matrix", "real scalar"); - if (rows () > 0 && columns () > 0) - { - warn_implicit_conversion ("Octave:array-to-scalar", - "complex matrix", "real scalar"); + if (rows () == 0 || columns () == 0) + err_invalid_conversion ("complex matrix", "real scalar"); - retval = std::real (matrix (0, 0)); - } - else - err_invalid_conversion ("complex matrix", "real scalar"); + warn_implicit_conversion ("Octave:array-to-scalar", + "complex matrix", "real scalar"); + + retval = std::real (matrix(0, 0)); return retval; } @@ -166,15 +162,13 @@ Complex retval (tmp, tmp); - if (rows () > 0 && columns () > 0) - { - warn_implicit_conversion ("Octave:array-to-scalar", - "complex matrix", "complex scalar"); + if (rows () == 0 || columns () == 0) + err_invalid_conversion ("complex matrix", "complex scalar"); - retval = matrix (0, 0); - } - else - err_invalid_conversion ("complex matrix", "complex scalar"); + warn_implicit_conversion ("Octave:array-to-scalar", + "complex matrix", "complex scalar"); + + retval = matrix(0, 0); return retval; } @@ -186,15 +180,13 @@ FloatComplex retval (tmp, tmp); - if (rows () > 0 && columns () > 0) - { - warn_implicit_conversion ("Octave:array-to-scalar", - "complex matrix", "complex scalar"); + if (rows () == 0 || columns () == 0) + err_invalid_conversion ("complex matrix", "complex scalar"); - retval = matrix (0, 0); - } - else - err_invalid_conversion ("complex matrix", "complex scalar"); + warn_implicit_conversion ("Octave:array-to-scalar", + "complex matrix", "complex scalar"); + + retval = matrix(0, 0); return retval; } diff -r c1df36373272 -r 3ac9f47fb04b libinterp/octave-value/ov-flt-re-mat.cc --- a/libinterp/octave-value/ov-flt-re-mat.cc Wed Jan 20 15:45:58 2016 -0800 +++ b/libinterp/octave-value/ov-flt-re-mat.cc Wed Jan 20 16:08:30 2016 -0800 @@ -91,15 +91,13 @@ { double retval = lo_ieee_nan_value (); - if (numel () > 0) - { - warn_implicit_conversion ("Octave:array-to-scalar", - "real matrix", "real scalar"); + if (numel () == 0) + err_invalid_conversion ("real matrix", "real scalar"); - retval = matrix (0, 0); - } - else - err_invalid_conversion ("real matrix", "real scalar"); + warn_implicit_conversion ("Octave:array-to-scalar", + "real matrix", "real scalar"); + + retval = matrix(0, 0); return retval; } @@ -109,15 +107,13 @@ { float retval = lo_ieee_float_nan_value (); - if (numel () > 0) - { - warn_implicit_conversion ("Octave:array-to-scalar", - "real matrix", "real scalar"); + if (numel () == 0) + err_invalid_conversion ("real matrix", "real scalar"); - retval = matrix (0, 0); - } - else - err_invalid_conversion ("real matrix", "real scalar"); + warn_implicit_conversion ("Octave:array-to-scalar", + "real matrix", "real scalar"); + + retval = matrix(0, 0); return retval; } @@ -143,15 +139,13 @@ Complex retval (tmp, tmp); - if (rows () > 0 && columns () > 0) - { - warn_implicit_conversion ("Octave:array-to-scalar", - "real matrix", "complex scalar"); + if (rows () == 0 || columns () == 0) + err_invalid_conversion ("real matrix", "complex scalar"); - retval = matrix (0, 0); - } - else - err_invalid_conversion ("real matrix", "complex scalar"); + warn_implicit_conversion ("Octave:array-to-scalar", + "real matrix", "complex scalar"); + + retval = matrix(0, 0); return retval; } @@ -163,15 +157,13 @@ FloatComplex retval (tmp, tmp); - if (rows () > 0 && columns () > 0) - { - warn_implicit_conversion ("Octave:array-to-scalar", - "real matrix", "complex scalar"); + if (rows () == 0 || columns () == 0) + err_invalid_conversion ("real matrix", "complex scalar"); - retval = matrix (0, 0); - } - else - err_invalid_conversion ("real matrix", "complex scalar"); + warn_implicit_conversion ("Octave:array-to-scalar", + "real matrix", "complex scalar"); + + retval = matrix(0, 0); return retval; } @@ -287,29 +279,27 @@ { octave_quit (); - float d = matrix (i); + float d = matrix(i); if (xisnan (d)) err_nan_to_character_conversion (); - else - { - int ival = NINT (d); + + int ival = NINT (d); - if (ival < 0 || ival > std::numeric_limits::max ()) - { - // FIXME: is there something better we could do? + if (ival < 0 || ival > std::numeric_limits::max ()) + { + // FIXME: is there something better we could do? - ival = 0; + ival = 0; - if (! warned) - { - ::warning ("range error for conversion to character value"); - warned = true; - } + if (! warned) + { + ::warning ("range error for conversion to character value"); + warned = true; } + } - chm (i) = static_cast (ival); - } + chm(i) = static_cast (ival); } retval = octave_value (chm, type); diff -r c1df36373272 -r 3ac9f47fb04b libinterp/octave-value/ov-intx.h --- a/libinterp/octave-value/ov-intx.h Wed Jan 20 15:45:58 2016 -0800 +++ b/libinterp/octave-value/ov-intx.h Wed Jan 20 16:08:30 2016 -0800 @@ -102,18 +102,15 @@ { double retval = lo_ieee_nan_value (); - if (numel () > 0) - { - warn_implicit_conversion ("Octave:array-to-scalar", - type_name (), "real scalar"); - - retval = matrix(0).double_value (); - } - else + if (numel () == 0) err_invalid_conversion (type_name (), "real scalar"); + warn_implicit_conversion ("Octave:array-to-scalar", + type_name (), "real scalar"); + + retval = matrix(0).double_value (); + return retval; - } float @@ -121,18 +118,15 @@ { float retval = lo_ieee_float_nan_value (); - if (numel () > 0) - { - warn_implicit_conversion ("Octave:array-to-scalar", - type_name (), "real scalar"); - - retval = matrix(0).float_value (); - } - else + if (numel () == 0) err_invalid_conversion (type_name (), "real scalar"); + warn_implicit_conversion ("Octave:array-to-scalar", + type_name (), "real scalar"); + + retval = matrix(0).float_value (); + return retval; - } double scalar_value (bool = false) const { return double_value (); } diff -r c1df36373272 -r 3ac9f47fb04b libinterp/octave-value/ov-perm.cc --- a/libinterp/octave-value/ov-perm.cc Wed Jan 20 15:45:58 2016 -0800 +++ b/libinterp/octave-value/ov-perm.cc Wed Jan 20 16:08:30 2016 -0800 @@ -142,15 +142,13 @@ { double retval = lo_ieee_nan_value (); - if (numel () > 0) - { - warn_implicit_conversion ("Octave:array-to-scalar", - type_name (), "real scalar"); + if (numel () == 0) + err_invalid_conversion (type_name (), "real scalar"); - retval = matrix (0, 0); - } - else - err_invalid_conversion (type_name (), "real scalar"); + warn_implicit_conversion ("Octave:array-to-scalar", + type_name (), "real scalar"); + + retval = matrix(0, 0); return retval; } @@ -160,15 +158,13 @@ { float retval = lo_ieee_float_nan_value (); - if (numel () > 0) - { - warn_implicit_conversion ("Octave:array-to-scalar", - type_name (), "real scalar"); + if (numel () == 0) + err_invalid_conversion (type_name (), "real scalar"); - retval = matrix (0, 0); - } - else - err_invalid_conversion (type_name (), "real scalar"); + warn_implicit_conversion ("Octave:array-to-scalar", + type_name (), "real scalar"); + + retval = matrix(0, 0); return retval; } @@ -180,15 +176,13 @@ Complex retval (tmp, tmp); - if (rows () > 0 && columns () > 0) - { - warn_implicit_conversion ("Octave:array-to-scalar", - type_name (), "complex scalar"); + if (rows () == 0 || columns () == 0) + err_invalid_conversion (type_name (), "complex scalar"); - retval = matrix (0, 0); - } - else - err_invalid_conversion (type_name (), "complex scalar"); + warn_implicit_conversion ("Octave:array-to-scalar", + type_name (), "complex scalar"); + + retval = matrix(0, 0); return retval; } @@ -200,15 +194,13 @@ FloatComplex retval (tmp, tmp); - if (rows () > 0 && columns () > 0) - { - warn_implicit_conversion ("Octave:array-to-scalar", - type_name (), "complex scalar"); + if (rows () == 0 || columns () == 0) + err_invalid_conversion (type_name (), "complex scalar"); - retval = matrix (0, 0); - } - else - err_invalid_conversion (type_name (), "complex scalar"); + warn_implicit_conversion ("Octave:array-to-scalar", + type_name (), "complex scalar"); + + retval = matrix(0, 0); return retval; } diff -r c1df36373272 -r 3ac9f47fb04b libinterp/octave-value/ov-range.cc --- a/libinterp/octave-value/ov-range.cc Wed Jan 20 15:45:58 2016 -0800 +++ b/libinterp/octave-value/ov-range.cc Wed Jan 20 16:08:30 2016 -0800 @@ -184,15 +184,13 @@ octave_idx_type nel = range.numel (); - if (nel > 0) - { - warn_implicit_conversion ("Octave:array-to-scalar", - "range", "real scalar"); + if (nel == 0) + err_invalid_conversion ("range", "real scalar"); - retval = range.base (); - } - else - err_invalid_conversion ("range", "real scalar"); + warn_implicit_conversion ("Octave:array-to-scalar", + "range", "real scalar"); + + retval = range.base (); return retval; } @@ -204,15 +202,13 @@ octave_idx_type nel = range.numel (); - if (nel > 0) - { - warn_implicit_conversion ("Octave:array-to-scalar", - "range", "real scalar"); + if (nel == 0) + err_invalid_conversion ("range", "real scalar"); - retval = range.base (); - } - else - err_invalid_conversion ("range", "real scalar"); + warn_implicit_conversion ("Octave:array-to-scalar", + "range", "real scalar"); + + retval = range.base (); return retval; } @@ -294,15 +290,13 @@ octave_idx_type nel = range.numel (); - if (nel > 0) - { - warn_implicit_conversion ("Octave:array-to-scalar", - "range", "complex scalar"); + if (nel == 0) + err_invalid_conversion ("range", "complex scalar"); - retval = range.base (); - } - else - err_invalid_conversion ("range", "complex scalar"); + warn_implicit_conversion ("Octave:array-to-scalar", + "range", "complex scalar"); + + retval = range.base (); return retval; } @@ -316,15 +310,13 @@ octave_idx_type nel = range.numel (); - if (nel > 0) - { - warn_implicit_conversion ("Octave:array-to-scalar", - "range", "complex scalar"); + if (nel == 0) + err_invalid_conversion ("range", "complex scalar"); - retval = range.base (); - } - else - err_invalid_conversion ("range", "complex scalar"); + warn_implicit_conversion ("Octave:array-to-scalar", + "range", "complex scalar"); + + retval = range.base (); return retval; } diff -r c1df36373272 -r 3ac9f47fb04b libinterp/octave-value/ov-re-mat.cc --- a/libinterp/octave-value/ov-re-mat.cc Wed Jan 20 15:45:58 2016 -0800 +++ b/libinterp/octave-value/ov-re-mat.cc Wed Jan 20 16:08:30 2016 -0800 @@ -106,15 +106,13 @@ { double retval = lo_ieee_nan_value (); - if (numel () > 0) - { - warn_implicit_conversion ("Octave:array-to-scalar", - "real matrix", "real scalar"); + if (numel () == 0) + err_invalid_conversion ("real matrix", "real scalar"); - retval = matrix (0, 0); - } - else - err_invalid_conversion ("real matrix", "real scalar"); + warn_implicit_conversion ("Octave:array-to-scalar", + "real matrix", "real scalar"); + + retval = matrix(0, 0); return retval; } @@ -124,15 +122,13 @@ { float retval = lo_ieee_float_nan_value (); - if (numel () > 0) - { - warn_implicit_conversion ("Octave:array-to-scalar", - "real matrix", "real scalar"); + if (numel () == 0) + err_invalid_conversion ("real matrix", "real scalar"); - retval = matrix (0, 0); - } - else - err_invalid_conversion ("real matrix", "real scalar"); + warn_implicit_conversion ("Octave:array-to-scalar", + "real matrix", "real scalar"); + + retval = matrix(0, 0); return retval; } @@ -158,15 +154,13 @@ Complex retval (tmp, tmp); - if (rows () > 0 && columns () > 0) - { - warn_implicit_conversion ("Octave:array-to-scalar", - "real matrix", "complex scalar"); + if (rows () == 0 || columns () == 0) + err_invalid_conversion ("real matrix", "complex scalar"); - retval = matrix (0, 0); - } - else - err_invalid_conversion ("real matrix", "complex scalar"); + warn_implicit_conversion ("Octave:array-to-scalar", + "real matrix", "complex scalar"); + + retval = matrix(0, 0); return retval; } @@ -178,15 +172,13 @@ FloatComplex retval (tmp, tmp); - if (rows () > 0 && columns () > 0) - { - warn_implicit_conversion ("Octave:array-to-scalar", - "real matrix", "complex scalar"); + if (rows () == 0 || columns () == 0) + err_invalid_conversion ("real matrix", "complex scalar"); - retval = matrix (0, 0); - } - else - err_invalid_conversion ("real matrix", "complex scalar"); + warn_implicit_conversion ("Octave:array-to-scalar", + "real matrix", "complex scalar"); + + retval = matrix(0, 0); return retval; } @@ -389,29 +381,27 @@ { octave_quit (); - double d = matrix (i); + double d = matrix(i); if (xisnan (d)) err_nan_to_character_conversion (); - else - { - int ival = NINT (d); + + int ival = NINT (d); - if (ival < 0 || ival > std::numeric_limits::max ()) - { - // FIXME: is there something better we could do? + if (ival < 0 || ival > std::numeric_limits::max ()) + { + // FIXME: is there something better we could do? - ival = 0; + ival = 0; - if (! warned) - { - ::warning ("range error for conversion to character value"); - warned = true; - } + if (! warned) + { + ::warning ("range error for conversion to character value"); + warned = true; } + } - chm (i) = static_cast (ival); - } + chm(i) = static_cast (ival); } retval = octave_value (chm, type); diff -r c1df36373272 -r 3ac9f47fb04b libinterp/octave-value/ov-re-sparse.cc --- a/libinterp/octave-value/ov-re-sparse.cc Wed Jan 20 15:45:58 2016 -0800 +++ b/libinterp/octave-value/ov-re-sparse.cc Wed Jan 20 16:08:30 2016 -0800 @@ -97,16 +97,14 @@ { double retval = lo_ieee_nan_value (); - if (numel () > 0) - { - if (numel () > 1) - warn_implicit_conversion ("Octave:array-to-scalar", - "real sparse matrix", "real scalar"); + if (numel () == 0) + err_invalid_conversion ("real sparse matrix", "real scalar"); - retval = matrix (0, 0); - } - else - err_invalid_conversion ("real sparse matrix", "real scalar"); + if (numel () > 1) + warn_implicit_conversion ("Octave:array-to-scalar", + "real sparse matrix", "real scalar"); + + retval = matrix(0, 0); return retval; } @@ -119,16 +117,14 @@ Complex retval (tmp, tmp); // FIXME: maybe this should be a function, valid_as_scalar() - if (rows () > 0 && columns () > 0) - { - if (numel () > 1) - warn_implicit_conversion ("Octave:array-to-scalar", - "real sparse matrix", "complex scalar"); + if (rows () == 0 || columns () == 0) + err_invalid_conversion ("real sparse matrix", "complex scalar"); - retval = matrix (0, 0); - } - else - err_invalid_conversion ("real sparse matrix", "complex scalar"); + if (numel () > 1) + warn_implicit_conversion ("Octave:array-to-scalar", + "real sparse matrix", "complex scalar"); + + retval = matrix(0, 0); return retval; } @@ -225,27 +221,23 @@ if (xisnan (d)) err_nan_to_character_conversion (); - else - { - int ival = NINT (d); + + int ival = NINT (d); - if (ival < 0 - || ival > std::numeric_limits::max ()) - { - // FIXME: is there something better we could do? + if (ival < 0 || ival > std::numeric_limits::max ()) + { + // FIXME: is there something better we could do? - ival = 0; + ival = 0; - if (! warned) - { - ::warning ("range error for conversion to character value"); - warned = true; - } + if (! warned) + { + ::warning ("range error for conversion to character value"); + warned = true; } + } - chm (matrix.ridx (i) + j * nr) = - static_cast (ival); - } + chm(matrix.ridx (i) + j * nr) = static_cast (ival); } retval = octave_value (chm, type); diff -r c1df36373272 -r 3ac9f47fb04b libinterp/octave-value/ov-scalar.cc --- a/libinterp/octave-value/ov-scalar.cc Wed Jan 20 15:45:58 2016 -0800 +++ b/libinterp/octave-value/ov-scalar.cc Wed Jan 20 16:08:30 2016 -0800 @@ -127,21 +127,19 @@ if (xisnan (scalar)) err_nan_to_character_conversion (); - else - { - int ival = NINT (scalar); + + int ival = NINT (scalar); - if (ival < 0 || ival > std::numeric_limits::max ()) - { - // FIXME: is there something better we could do? + if (ival < 0 || ival > std::numeric_limits::max ()) + { + // FIXME: is there something better we could do? - ival = 0; + ival = 0; - ::warning ("range error for conversion to character value"); - } + ::warning ("range error for conversion to character value"); + } - retval = octave_value (std::string (1, static_cast (ival)), type); - } + retval = octave_value (std::string (1, static_cast (ival)), type); return retval; } diff -r c1df36373272 -r 3ac9f47fb04b libinterp/octave-value/ov-struct.cc --- a/libinterp/octave-value/ov-struct.cc Wed Jan 20 15:45:58 2016 -0800 +++ b/libinterp/octave-value/ov-struct.cc Wed Jan 20 16:08:30 2016 -0800 @@ -321,28 +321,26 @@ // FIXME: better code reuse? // cf. octave_cell::subsasgn and the case below. - if (tmpc.numel () == 1) + if (tmpc.numel () != 1) + err_indexed_cs_list (); + + octave_value& tmp = tmpc(0); + + bool orig_undefined = tmp.is_undefined (); + + if (orig_undefined || tmp.is_zero_by_zero ()) { - octave_value& tmp = tmpc(0); - - bool orig_undefined = tmp.is_undefined (); - - if (orig_undefined || tmp.is_zero_by_zero ()) - { - tmp = octave_value::empty_conv (next_type, rhs); - tmp.make_unique (); // probably a no-op. - } - else - // optimization: ignore the copy - // still stored inside our map. - tmp.make_unique (1); - - t_rhs =(orig_undefined - ? tmp.undef_subsasgn (next_type, next_idx, rhs) - : tmp.subsasgn (next_type, next_idx, rhs)); + tmp = octave_value::empty_conv (next_type, rhs); + tmp.make_unique (); // probably a no-op. } else - err_indexed_cs_list (); + // optimization: ignore the copy + // still stored inside our map. + tmp.make_unique (1); + + t_rhs =(orig_undefined + ? tmp.undef_subsasgn (next_type, next_idx, rhs) + : tmp.subsasgn (next_type, next_idx, rhs)); } else err_invalid_index_for_assignment (); diff -r c1df36373272 -r 3ac9f47fb04b libinterp/octave-value/ov.cc --- a/libinterp/octave-value/ov.cc Wed Jan 20 15:45:58 2016 -0800 +++ b/libinterp/octave-value/ov.cc Wed Jan 20 16:08:30 2016 -0800 @@ -2074,13 +2074,11 @@ octave_value_typeinfo::binary_class_op_fcn f = octave_value_typeinfo::lookup_binary_class_op (op); - if (f) - { - retval = f (v1, v2); - } - else + if (! f) err_binary_op (octave_value::binary_op_as_string (op), v1.class_name (), v2.class_name ()); + + retval = f (v1, v2); } else { @@ -2117,13 +2115,11 @@ { octave_base_value *tmp = cf1 (*v1.rep); - if (tmp) - { - tv1 = octave_value (tmp); - t1 = tv1.type_id (); - } - else + if (! tmp) err_binary_op_conv (octave_value::binary_op_as_string (op)); + + tv1 = octave_value (tmp); + t1 = tv1.type_id (); } else tv1 = v1; @@ -2132,13 +2128,11 @@ { octave_base_value *tmp = cf2 (*v2.rep); - if (tmp) - { - tv2 = octave_value (tmp); - t2 = tv2.type_id (); - } - else + if (! tmp) err_binary_op_conv (octave_value::binary_op_as_string (op)); + + tv2 = octave_value (tmp); + t2 = tv2.type_id (); } else tv2 = v2; @@ -2169,14 +2163,11 @@ { octave_base_value *tmp = cf1 (*tv1.rep); - if (tmp) - { - tv1 = octave_value (tmp); - t1 = tv1.type_id (); - } - else - err_binary_op_conv - (octave_value::binary_op_as_string (op)); + if (! tmp) + err_binary_op_conv (octave_value::binary_op_as_string (op)); + + tv1 = octave_value (tmp); + t1 = tv1.type_id (); } if (cf2) @@ -2193,19 +2184,17 @@ (octave_value::binary_op_as_string (op)); } - if (cf1 || cf2) - { - f = octave_value_typeinfo::lookup_binary_op (op, t1, t2); - - if (f) - retval = f (*tv1.rep, *tv2.rep); - else - err_binary_op (octave_value::binary_op_as_string (op), - v1.type_name (), v2.type_name ()); - } - else + if (! cf1 && ! cf2) err_binary_op (octave_value::binary_op_as_string (op), v1.type_name (), v2.type_name ()); + + f = octave_value_typeinfo::lookup_binary_op (op, t1, t2); + + if (! f) + err_binary_op (octave_value::binary_op_as_string (op), + v1.type_name (), v2.type_name ()); + + retval = f (*tv1.rep, *tv2.rep); } } } @@ -2365,13 +2354,11 @@ { octave_base_value *tmp = cf1 (*v1.rep); - if (tmp) - { - tv1 = octave_value (tmp); - t1 = tv1.type_id (); - } - else + if (! tmp) err_cat_op_conv (); + + tv1 = octave_value (tmp); + t1 = tv1.type_id (); } else tv1 = v1; @@ -2380,23 +2367,19 @@ { octave_base_value *tmp = cf2 (*v2.rep); - if (tmp) - { - tv2 = octave_value (tmp); - t2 = tv2.type_id (); - } - else + if (! tmp) err_cat_op_conv (); + + tv2 = octave_value (tmp); + t2 = tv2.type_id (); } else tv2 = v2; - if (cf1 || cf2) - { - retval = do_cat_op (tv1, tv2, ra_idx); - } - else + if (! cf1 && ! cf2) err_cat_op (v1.type_name (), v2.type_name ()); + + retval = do_cat_op (tv1, tv2, ra_idx); } return retval; @@ -2536,11 +2519,10 @@ octave_value_typeinfo::unary_class_op_fcn f = octave_value_typeinfo::lookup_unary_class_op (op); - if (f) - retval = f (v); - else - err_unary_op (octave_value::unary_op_as_string (op), - v.class_name ()); + if (! f) + err_unary_op (octave_value::unary_op_as_string (op), v.class_name ()); + + retval = f (v); } else { @@ -2558,21 +2540,17 @@ octave_base_value::type_conv_fcn cf = v.numeric_conversion_function (); - if (cf) - { - octave_base_value *tmp = cf (*v.rep); - - if (tmp) - { - tv = octave_value (tmp); - retval = do_unary_op (op, tv); - } - else - err_unary_op_conv (octave_value::unary_op_as_string (op)); - } - else + if (! cf) err_unary_op (octave_value::unary_op_as_string (op), v.type_name ()); + + octave_base_value *tmp = cf (*v.rep); + + if (! tmp) + err_unary_op_conv (octave_value::unary_op_as_string (op)); + + tv = octave_value (tmp); + retval = do_unary_op (op, tv); } } @@ -2619,47 +2597,42 @@ { octave_base_value::type_conv_fcn cf = numeric_conversion_function (); - if (cf) + if (! cf) + err_unary_op (octave_value::unary_op_as_string (op), type_name ()); + + octave_base_value *tmp = cf (*rep); + + if (! tmp) + err_unary_op_conversion_failed + (octave_value::unary_op_as_string (op), type_name ()); + + octave_base_value *old_rep = rep; + rep = tmp; + + t = type_id (); + + f = octave_value_typeinfo::lookup_non_const_unary_op (op, t); + + if (f) { - octave_base_value *tmp = cf (*rep); - - if (tmp) - { - octave_base_value *old_rep = rep; - rep = tmp; - - t = type_id (); - - f = octave_value_typeinfo::lookup_non_const_unary_op (op, t); - - if (f) - { - f (*rep); - - if (old_rep && --old_rep->count == 0) - delete old_rep; - } - else - { - if (old_rep) - { - if (--rep->count == 0) - delete rep; - - rep = old_rep; - } - - err_unary_op (octave_value::unary_op_as_string (op), - type_name ()); - } - } - else - err_unary_op_conversion_failed - (octave_value::unary_op_as_string (op), type_name ()); + f (*rep); + + if (old_rep && --old_rep->count == 0) + delete old_rep; } else - err_unary_op (octave_value::unary_op_as_string (op), - type_name ()); + { + if (old_rep) + { + if (--rep->count == 0) + delete rep; + + rep = old_rep; + } + + err_unary_op (octave_value::unary_op_as_string (op), + type_name ()); + } } } else diff -r c1df36373272 -r 3ac9f47fb04b libinterp/parse-tree/pt-idx.cc --- a/libinterp/parse-tree/pt-idx.cc Wed Jan 20 15:45:58 2016 -0800 +++ b/libinterp/parse-tree/pt-idx.cc Wed Jan 20 16:08:30 2016 -0800 @@ -182,8 +182,8 @@ { if (rvalue && object && args->has_magic_end () && object->is_undefined ()) err_invalid_inquiry_subscript (); - else - retval = args->convert_to_const_vector (object); + + retval = args->convert_to_const_vector (object); } octave_idx_type n = retval.length (); @@ -534,8 +534,8 @@ { if (tidx.has_magic_colon ()) err_invalid_inquiry_subscript (); - else - tmp = Cell (); + + tmp = Cell (); } else if (tmp.is_zero_by_zero () && (tmp.is_matrix_type () || tmp.is_string ())) @@ -569,8 +569,8 @@ { if (pidx.has_magic_colon ()) err_invalid_inquiry_subscript (); - else - tmp = octave_map (); + + tmp = octave_map (); } else if (autoconv) tmp = octave_map (); diff -r c1df36373272 -r 3ac9f47fb04b liboctave/array/Array-util.cc --- a/liboctave/array/Array-util.cc Wed Jan 20 15:45:58 2016 -0800 +++ b/liboctave/array/Array-util.cc Wed Jan 20 16:08:30 2016 -0800 @@ -190,7 +190,7 @@ { if (i < 0) err_invalid_index (i, 2, 1); - else if (j < 0) + if (j < 0) err_invalid_index (j, 2, 2); if (i >= dims(0)) err_index_out_of_range (2, 1, i+1, dims(0), dims); @@ -206,9 +206,9 @@ { if (i < 0) err_invalid_index (i, 3, 1); - else if (j < 0) + if (j < 0) err_invalid_index (j, 3, 2); - else if (k < 0) + if (k < 0) err_invalid_index (k, 3, 3); if (i >= dims(0)) err_index_out_of_range (3, 1, i+1, dims(0), dims); diff -r c1df36373272 -r 3ac9f47fb04b liboctave/array/Array.cc --- a/liboctave/array/Array.cc Wed Jan 20 15:45:58 2016 -0800 +++ b/liboctave/array/Array.cc Wed Jan 20 16:08:30 2016 -0800 @@ -912,120 +912,115 @@ void Array::resize1 (octave_idx_type n, const T& rfv) { - if (n >= 0 && ndims () == 2) + if (n < 0 || ndims () != 2) + err_invalid_resize (); + + dim_vector dv; + // This is driven by Matlab's behaviour of giving a *row* vector + // on some out-of-bounds assignments. Specifically, Matlab + // allows a(i) with out-of-bouds i when a is either of 0x0, 1x0, + // 1x1, 0xN, and gives a row vector in all cases (yes, even the + // last one, search me why). Giving a column vector would make + // much more sense (given the way trailing singleton dims are + // treated). + bool invalid = false; + if (rows () == 0 || rows () == 1) + dv = dim_vector (1, n); + else if (columns () == 1) + dv = dim_vector (n, 1); + else + invalid = true; + + if (invalid) + err_invalid_resize (); + else { - dim_vector dv; - // This is driven by Matlab's behaviour of giving a *row* vector - // on some out-of-bounds assignments. Specifically, Matlab - // allows a(i) with out-of-bouds i when a is either of 0x0, 1x0, - // 1x1, 0xN, and gives a row vector in all cases (yes, even the - // last one, search me why). Giving a column vector would make - // much more sense (given the way trailing singleton dims are - // treated). - bool invalid = false; - if (rows () == 0 || rows () == 1) - dv = dim_vector (1, n); - else if (columns () == 1) - dv = dim_vector (n, 1); - else - invalid = true; - - if (invalid) - err_invalid_resize (); - else + octave_idx_type nx = numel (); + if (n == nx - 1 && n > 0) { - octave_idx_type nx = numel (); - if (n == nx - 1 && n > 0) + // Stack "pop" operation. + if (rep->count == 1) + slice_data[slice_len-1] = T (); + slice_len--; + dimensions = dv; + } + else if (n == nx + 1 && nx > 0) + { + // Stack "push" operation. + if (rep->count == 1 + && slice_data + slice_len < rep->data + rep->len) { - // Stack "pop" operation. - if (rep->count == 1) - slice_data[slice_len-1] = T (); - slice_len--; + slice_data[slice_len++] = rfv; dimensions = dv; } - else if (n == nx + 1 && nx > 0) + else { - // Stack "push" operation. - if (rep->count == 1 - && slice_data + slice_len < rep->data + rep->len) - { - slice_data[slice_len++] = rfv; - dimensions = dv; - } - else - { - static const octave_idx_type max_stack_chunk = 1024; - octave_idx_type nn = n + std::min (nx, max_stack_chunk); - Array tmp (Array (dim_vector (nn, 1)), dv, 0, n); - T *dest = tmp.fortran_vec (); - - std::copy (data (), data () + nx, dest); - dest[nx] = rfv; - - *this = tmp; - } - } - else if (n != nx) - { - Array tmp = Array (dv); + static const octave_idx_type max_stack_chunk = 1024; + octave_idx_type nn = n + std::min (nx, max_stack_chunk); + Array tmp (Array (dim_vector (nn, 1)), dv, 0, n); T *dest = tmp.fortran_vec (); - octave_idx_type n0 = std::min (n, nx); - octave_idx_type n1 = n - n0; - std::copy (data (), data () + n0, dest); - std::fill_n (dest + n0, n1, rfv); + std::copy (data (), data () + nx, dest); + dest[nx] = rfv; *this = tmp; } } + else if (n != nx) + { + Array tmp = Array (dv); + T *dest = tmp.fortran_vec (); + + octave_idx_type n0 = std::min (n, nx); + octave_idx_type n1 = n - n0; + std::copy (data (), data () + n0, dest); + std::fill_n (dest + n0, n1, rfv); + + *this = tmp; + } } - else - err_invalid_resize (); } template void Array::resize2 (octave_idx_type r, octave_idx_type c, const T& rfv) { - if (r >= 0 && c >= 0 && ndims () == 2) + if (r < 0 || c < 0 || ndims () != 2) + err_invalid_resize (); + + octave_idx_type rx = rows (); + octave_idx_type cx = columns (); + if (r != rx || c != cx) { - octave_idx_type rx = rows (); - octave_idx_type cx = columns (); - if (r != rx || c != cx) + Array tmp = Array (dim_vector (r, c)); + T *dest = tmp.fortran_vec (); + + octave_idx_type r0 = std::min (r, rx); + octave_idx_type r1 = r - r0; + octave_idx_type c0 = std::min (c, cx); + octave_idx_type c1 = c - c0; + const T *src = data (); + if (r == rx) { - Array tmp = Array (dim_vector (r, c)); - T *dest = tmp.fortran_vec (); - - octave_idx_type r0 = std::min (r, rx); - octave_idx_type r1 = r - r0; - octave_idx_type c0 = std::min (c, cx); - octave_idx_type c1 = c - c0; - const T *src = data (); - if (r == rx) + std::copy (src, src + r * c0, dest); + dest += r * c0; + } + else + { + for (octave_idx_type k = 0; k < c0; k++) { - std::copy (src, src + r * c0, dest); - dest += r * c0; + std::copy (src, src + r0, dest); + src += rx; + dest += r0; + std::fill_n (dest, r1, rfv); + dest += r1; } - else - { - for (octave_idx_type k = 0; k < c0; k++) - { - std::copy (src, src + r0, dest); - src += rx; - dest += r0; - std::fill_n (dest, r1, rfv); - dest += r1; - } - } - - std::fill_n (dest, r * c1, rfv); - - *this = tmp; } + + std::fill_n (dest, r * c1, rfv); + + *this = tmp; } - else - err_invalid_resize (); - } template @@ -1037,18 +1032,16 @@ resize2 (dv(0), dv(1), rfv); else if (dimensions != dv) { - if (dimensions.length () <= dvl && ! dv.any_neg ()) - { - Array tmp (dv); - // Prepare for recursive resizing. - rec_resize_helper rh (dv, dimensions.redim (dvl)); - - // Do it. - rh.resize_fill (data (), tmp.fortran_vec (), rfv); - *this = tmp; - } - else + if (dimensions.length () > dvl || dv.any_neg ()) err_invalid_resize (); + + Array tmp (dv); + // Prepare for recursive resizing. + rec_resize_helper rh (dv, dimensions.redim (dvl)); + + // Do it. + rh.resize_fill (data (), tmp.fortran_vec (), rfv); + *this = tmp; } } @@ -1143,45 +1136,43 @@ octave_idx_type n = numel (); octave_idx_type rhl = rhs.numel (); - if (rhl == 1 || i.length (n) == rhl) + if (rhl != 1 && i.length (n) != rhl) + err_nonconformant ("=", dim_vector(i.length(n),1), rhs.dims()); + + octave_idx_type nx = i.extent (n); + bool colon = i.is_colon_equiv (nx); + // Try to resize first if necessary. + if (nx != n) { - octave_idx_type nx = i.extent (n); - bool colon = i.is_colon_equiv (nx); - // Try to resize first if necessary. - if (nx != n) - { - // Optimize case A = []; A(1:n) = X with A empty. - if (dimensions.zero_by_zero () && colon) - { - if (rhl == 1) - *this = Array (dim_vector (1, nx), rhs(0)); - else - *this = Array (rhs, dim_vector (1, nx)); - return; - } - - resize1 (nx, rfv); - n = numel (); - } - - if (colon) - { - // A(:) = X makes a full fill or a shallow copy. - if (rhl == 1) - fill (rhs(0)); - else - *this = rhs.reshape (dimensions); - } - else + // Optimize case A = []; A(1:n) = X with A empty. + if (dimensions.zero_by_zero () && colon) { if (rhl == 1) - i.fill (rhs(0), n, fortran_vec ()); + *this = Array (dim_vector (1, nx), rhs(0)); else - i.assign (rhs.data (), n, fortran_vec ()); + *this = Array (rhs, dim_vector (1, nx)); + return; } + + resize1 (nx, rfv); + n = numel (); + } + + if (colon) + { + // A(:) = X makes a full fill or a shallow copy. + if (rhl == 1) + fill (rhs(0)); + else + *this = rhs.reshape (dimensions); } else - err_nonconformant ("=", dim_vector(i.length(n),1), rhs.dims()); + { + if (rhl == 1) + i.fill (rhs(0), n, fortran_vec ()); + else + i.assign (rhs.data (), n, fortran_vec ()); + } } // Assignment to a 2-dimensional array diff -r c1df36373272 -r 3ac9f47fb04b liboctave/array/Sparse.cc --- a/liboctave/array/Sparse.cc Wed Jan 20 15:45:58 2016 -0800 +++ b/liboctave/array/Sparse.cc Wed Jan 20 16:08:30 2016 -0800 @@ -1422,16 +1422,14 @@ } else if (idx.extent (nel) > nel) { + if (! resize_ok) + err_index_out_of_range (1, 1, idx.extent (nel), nel, dims ()); + // resize_ok is completely handled here. - if (resize_ok) - { - octave_idx_type ext = idx.extent (nel); - Sparse tmp = *this; - tmp.resize1 (ext); - retval = tmp.index (idx); - } - else - err_index_out_of_range (1, 1, idx.extent (nel), nel, dims ()); + octave_idx_type ext = idx.extent (nel); + Sparse tmp = *this; + tmp.resize1 (ext); + retval = tmp.index (idx); } else if (nr == 1 && nc == 1) { diff -r c1df36373272 -r 3ac9f47fb04b liboctave/numeric/lo-specfun.cc --- a/liboctave/numeric/lo-specfun.cc Wed Jan 20 15:45:58 2016 -0800 +++ b/liboctave/numeric/lo-specfun.cc Wed Jan 20 16:08:30 2016 -0800 @@ -2332,20 +2332,18 @@ Array retval; dim_vector dv = a.dims (); - if (dv == b.dims ()) - { - octave_idx_type nel = dv.numel (); - - retval.resize (dv); - - double *pretval = retval.fortran_vec (); - - for (octave_idx_type i = 0; i < nel; i++) - *pretval++ = betainc (x, a(i), b(i)); - } - else + if (dv != b.dims ()) err_betainc_nonconformant (dim_vector (0, 0), dv, b.dims ()); + octave_idx_type nel = dv.numel (); + + retval.resize (dv); + + double *pretval = retval.fortran_vec (); + + for (octave_idx_type i = 0; i < nel; i++) + *pretval++ = betainc (x, a(i), b(i)); + return retval; } @@ -2371,20 +2369,18 @@ Array retval; dim_vector dv = x.dims (); - if (dv == b.dims ()) - { - octave_idx_type nel = dv.numel (); - - retval.resize (dv); - - double *pretval = retval.fortran_vec (); - - for (octave_idx_type i = 0; i < nel; i++) - *pretval++ = betainc (x(i), a, b(i)); - } - else + if (dv != b.dims ()) err_betainc_nonconformant (dv, dim_vector (0, 0), b.dims ()); + octave_idx_type nel = dv.numel (); + + retval.resize (dv); + + double *pretval = retval.fortran_vec (); + + for (octave_idx_type i = 0; i < nel; i++) + *pretval++ = betainc (x(i), a, b(i)); + return retval; } @@ -2394,20 +2390,18 @@ Array retval; dim_vector dv = x.dims (); - if (dv == a.dims ()) - { - octave_idx_type nel = dv.numel (); - - retval.resize (dv); - - double *pretval = retval.fortran_vec (); - - for (octave_idx_type i = 0; i < nel; i++) - *pretval++ = betainc (x(i), a(i), b); - } - else + if (dv != a.dims ()) err_betainc_nonconformant (dv, a.dims (), dim_vector (0, 0)); + octave_idx_type nel = dv.numel (); + + retval.resize (dv); + + double *pretval = retval.fortran_vec (); + + for (octave_idx_type i = 0; i < nel; i++) + *pretval++ = betainc (x(i), a(i), b); + return retval; } @@ -2417,20 +2411,18 @@ Array retval; dim_vector dv = x.dims (); - if (dv == a.dims () && dv == b.dims ()) - { - octave_idx_type nel = dv.numel (); - - retval.resize (dv); - - double *pretval = retval.fortran_vec (); - - for (octave_idx_type i = 0; i < nel; i++) - *pretval++ = betainc (x(i), a(i), b(i)); - } - else + if (dv != a.dims () || dv != b.dims ()) err_betainc_nonconformant (dv, a.dims (), b.dims ()); + octave_idx_type nel = dv.numel (); + + retval.resize (dv); + + double *pretval = retval.fortran_vec (); + + for (octave_idx_type i = 0; i < nel; i++) + *pretval++ = betainc (x(i), a(i), b(i)); + return retval; } @@ -2480,20 +2472,18 @@ Array retval; dim_vector dv = a.dims (); - if (dv == b.dims ()) - { - octave_idx_type nel = dv.numel (); - - retval.resize (dv); - - float *pretval = retval.fortran_vec (); - - for (octave_idx_type i = 0; i < nel; i++) - *pretval++ = betainc (x, a(i), b(i)); - } - else + if (dv != b.dims ()) err_betainc_nonconformant (dim_vector (0, 0), dv, b.dims ()); + octave_idx_type nel = dv.numel (); + + retval.resize (dv); + + float *pretval = retval.fortran_vec (); + + for (octave_idx_type i = 0; i < nel; i++) + *pretval++ = betainc (x, a(i), b(i)); + return retval; } @@ -2519,20 +2509,18 @@ Array retval; dim_vector dv = x.dims (); - if (dv == b.dims ()) - { - octave_idx_type nel = dv.numel (); - - retval.resize (dv); - - float *pretval = retval.fortran_vec (); - - for (octave_idx_type i = 0; i < nel; i++) - *pretval++ = betainc (x(i), a, b(i)); - } - else + if (dv != b.dims ()) err_betainc_nonconformant (dv, dim_vector (0, 0), b.dims ()); + octave_idx_type nel = dv.numel (); + + retval.resize (dv); + + float *pretval = retval.fortran_vec (); + + for (octave_idx_type i = 0; i < nel; i++) + *pretval++ = betainc (x(i), a, b(i)); + return retval; } @@ -2542,20 +2530,18 @@ Array retval; dim_vector dv = x.dims (); - if (dv == a.dims ()) - { - octave_idx_type nel = dv.numel (); - - retval.resize (dv); - - float *pretval = retval.fortran_vec (); - - for (octave_idx_type i = 0; i < nel; i++) - *pretval++ = betainc (x(i), a(i), b); - } - else + if (dv != a.dims ()) err_betainc_nonconformant (dv, a.dims (), dim_vector (0, 0)); + octave_idx_type nel = dv.numel (); + + retval.resize (dv); + + float *pretval = retval.fortran_vec (); + + for (octave_idx_type i = 0; i < nel; i++) + *pretval++ = betainc (x(i), a(i), b); + return retval; } @@ -2565,20 +2551,18 @@ Array retval; dim_vector dv = x.dims (); - if (dv == a.dims () && dv == b.dims ()) - { - octave_idx_type nel = dv.numel (); - - retval.resize (dv); - - float *pretval = retval.fortran_vec (); - - for (octave_idx_type i = 0; i < nel; i++) - *pretval++ = betainc (x(i), a(i), b(i)); - } - else + if (dv != a.dims () || dv != b.dims ()) err_betainc_nonconformant (dv, a.dims (), b.dims ()); + octave_idx_type nel = dv.numel (); + + retval.resize (dv); + + float *pretval = retval.fortran_vec (); + + for (octave_idx_type i = 0; i < nel; i++) + *pretval++ = betainc (x(i), a(i), b(i)); + return retval; } @@ -3539,20 +3523,18 @@ Array retval; dim_vector dv = a.dims (); - if (dv == b.dims ()) - { - octave_idx_type nel = dv.numel (); - - retval.resize (dv); - - double *pretval = retval.fortran_vec (); - - for (octave_idx_type i = 0; i < nel; i++) - *pretval++ = betaincinv (x, a(i), b(i)); - } - else + if (dv != b.dims ()) err_betaincinv_nonconformant (dim_vector (0, 0), dv, b.dims ()); + octave_idx_type nel = dv.numel (); + + retval.resize (dv); + + double *pretval = retval.fortran_vec (); + + for (octave_idx_type i = 0; i < nel; i++) + *pretval++ = betaincinv (x, a(i), b(i)); + return retval; } @@ -3578,20 +3560,18 @@ Array retval; dim_vector dv = x.dims (); - if (dv == b.dims ()) - { - octave_idx_type nel = dv.numel (); - - retval.resize (dv); - - double *pretval = retval.fortran_vec (); - - for (octave_idx_type i = 0; i < nel; i++) - *pretval++ = betaincinv (x(i), a, b(i)); - } - else + if (dv != b.dims ()) err_betaincinv_nonconformant (dv, dim_vector (0, 0), b.dims ()); + octave_idx_type nel = dv.numel (); + + retval.resize (dv); + + double *pretval = retval.fortran_vec (); + + for (octave_idx_type i = 0; i < nel; i++) + *pretval++ = betaincinv (x(i), a, b(i)); + return retval; } @@ -3601,20 +3581,18 @@ Array retval; dim_vector dv = x.dims (); - if (dv == a.dims ()) - { - octave_idx_type nel = dv.numel (); - - retval.resize (dv); - - double *pretval = retval.fortran_vec (); - - for (octave_idx_type i = 0; i < nel; i++) - *pretval++ = betaincinv (x(i), a(i), b); - } - else + if (dv != a.dims ()) err_betaincinv_nonconformant (dv, a.dims (), dim_vector (0, 0)); + octave_idx_type nel = dv.numel (); + + retval.resize (dv); + + double *pretval = retval.fortran_vec (); + + for (octave_idx_type i = 0; i < nel; i++) + *pretval++ = betaincinv (x(i), a(i), b); + return retval; } @@ -3625,20 +3603,18 @@ Array retval; dim_vector dv = x.dims (); - if (dv == a.dims () && dv == b.dims ()) - { - octave_idx_type nel = dv.numel (); - - retval.resize (dv); - - double *pretval = retval.fortran_vec (); - - for (octave_idx_type i = 0; i < nel; i++) - *pretval++ = betaincinv (x(i), a(i), b(i)); - } - else + if (dv != a.dims () && dv != b.dims ()) err_betaincinv_nonconformant (dv, a.dims (), b.dims ()); + octave_idx_type nel = dv.numel (); + + retval.resize (dv); + + double *pretval = retval.fortran_vec (); + + for (octave_idx_type i = 0; i < nel; i++) + *pretval++ = betaincinv (x(i), a(i), b(i)); + return retval; } diff -r c1df36373272 -r 3ac9f47fb04b liboctave/operators/mx-inlines.cc --- a/liboctave/operators/mx-inlines.cc Wed Jan 20 15:45:58 2016 -0800 +++ b/liboctave/operators/mx-inlines.cc Wed Jan 20 16:08:30 2016 -0800 @@ -415,15 +415,12 @@ dim_vector dr = r.dims (); dim_vector dx = x.dims (); if (dr == dx) - { - op (r.numel (), r.fortran_vec (), x.data ()); - } + op (r.numel (), r.fortran_vec (), x.data ()); else if (is_valid_inplace_bsxfun (opname, dr, dx)) - { - do_inplace_bsxfun_op (r, x, op, op1); - } + do_inplace_bsxfun_op (r, x, op, op1); else err_nonconformant (opname, dr, dx); + return r; } diff -r c1df36373272 -r 3ac9f47fb04b liboctave/util/oct-binmap.h --- a/liboctave/util/oct-binmap.h Wed Jan 20 15:45:58 2016 -0800 +++ b/liboctave/util/oct-binmap.h Wed Jan 20 16:08:30 2016 -0800 @@ -175,16 +175,14 @@ return binmap (xa, ya(0), fcn); else if (xad != yad) { - if (is_valid_bsxfun (name, xad, yad)) - { - bsxfun_wrapper::set_f(fcn); - return do_bsxfun_op (xa, ya, - bsxfun_wrapper::op_mm, - bsxfun_wrapper::op_sm, - bsxfun_wrapper::op_ms); - } - else + if (! is_valid_bsxfun (name, xad, yad)) err_nonconformant (name, xad, yad); + + bsxfun_wrapper::set_f(fcn); + return do_bsxfun_op (xa, ya, + bsxfun_wrapper::op_mm, + bsxfun_wrapper::op_sm, + bsxfun_wrapper::op_ms); } octave_idx_type len = xa.numel ();