# HG changeset patch # User John W. Eaton # Date 1323966231 18000 # Node ID c3d4015624100f7122fb6ab029691795f9cb75d1 # Parent 4000ad5fe0f6cbccf26b6799d2c1a5d0c0164b2b allow warning (or error) for automatic bsxfun * liboctave/bsxfun.h (is_valid_bsxfun, is_valid_inplace_bsxfun): New argument, name. Change all callers. Call warning_with_id_handler. diff -r 4000ad5fe0f6 -r c3d401562410 liboctave/bsxfun.h --- a/liboctave/bsxfun.h Thu Dec 15 10:07:57 2011 -0500 +++ b/liboctave/bsxfun.h Thu Dec 15 11:23:51 2011 -0500 @@ -26,10 +26,12 @@ #include "Array.h" #include "dim-vector.h" +#include "lo-error.h" inline bool -is_valid_bsxfun (const dim_vector& dx, const dim_vector& dy) +is_valid_bsxfun (const std::string& name, const dim_vector& dx, + const dim_vector& dy) { for (int i = 0; i < std::min (dx.length (), dy.length ()); i++) { @@ -38,6 +40,10 @@ if (! ( (xk == yk) || (xk == 1 && yk > 1) || (xk > 1 && yk == 1))) return false; } + + (*current_liboctave_warning_with_id_handler) + ("Octave:auto-bsxfun", "%s: automatic broadcasting operation applied", name.c_str ()); + return true; } @@ -46,7 +52,8 @@ // different here. inline bool -is_valid_inplace_bsxfun (const dim_vector& dr, const dim_vector& dx) +is_valid_inplace_bsxfun (const std::string& name, const dim_vector& dr, + const dim_vector& dx) { octave_idx_type drl = dr.length (), dxl = dx.length (); if (drl < dxl) @@ -60,6 +67,10 @@ if (! ( (rk == xk) || (rk > 1 && xk == 1))) return false; } + + (*current_liboctave_warning_with_id_handler) + ("Octave:auto-bsxfun", "%s: automatic broadcasting operation applied", name.c_str ()); + return true; } diff -r 4000ad5fe0f6 -r c3d401562410 liboctave/mx-inlines.cc --- a/liboctave/mx-inlines.cc Thu Dec 15 10:07:57 2011 -0500 +++ b/liboctave/mx-inlines.cc Thu Dec 15 11:23:51 2011 -0500 @@ -372,7 +372,7 @@ op (r.length (), r.fortran_vec (), x.data (), y.data ()); return r; } - else if (is_valid_bsxfun (dx, dy)) + else if (is_valid_bsxfun (opname, dx, dy)) { return do_bsxfun_op (x, y, op, op1, op2); } @@ -415,7 +415,7 @@ { op (r.length (), r.fortran_vec (), x.data ()); } - else if (is_valid_inplace_bsxfun (dr, dx)) + else if (is_valid_inplace_bsxfun (opname, dr, dx)) { do_inplace_bsxfun_op (r, x, op, op1); } diff -r 4000ad5fe0f6 -r c3d401562410 liboctave/oct-binmap.h --- a/liboctave/oct-binmap.h Thu Dec 15 10:07:57 2011 -0500 +++ b/liboctave/oct-binmap.h Thu Dec 15 11:23:51 2011 -0500 @@ -174,7 +174,7 @@ return binmap (xa, ya(0), fcn); else if (xad != yad) { - if (is_valid_bsxfun (xad, yad)) + if (is_valid_bsxfun (name, xad, yad)) { bsxfun_wrapper::set_f(fcn); return do_bsxfun_op (xa, ya, diff -r 4000ad5fe0f6 -r c3d401562410 src/OPERATORS/op-int.h --- a/src/OPERATORS/op-int.h Thu Dec 15 10:07:57 2011 -0500 +++ b/src/OPERATORS/op-int.h Thu Dec 15 11:23:51 2011 -0500 @@ -704,7 +704,7 @@ dim_vector b_dims = b.dims (); \ if (a_dims != b_dims) \ { \ - if (is_valid_bsxfun (a_dims, b_dims)) \ + if (is_valid_bsxfun ("operator .^", a_dims, b_dims)) \ { \ return bsxfun_pow (a, b); \ } \ @@ -730,7 +730,7 @@ dim_vector b_dims = b.dims (); \ if (a_dims != b_dims) \ { \ - if (is_valid_bsxfun (a_dims, b_dims)) \ + if (is_valid_bsxfun ("operator .^", a_dims, b_dims)) \ { \ return bsxfun_pow (a, b); \ } \ @@ -756,7 +756,7 @@ dim_vector b_dims = b.dims (); \ if (a_dims != b_dims) \ { \ - if (is_valid_bsxfun (a_dims, b_dims)) \ + if (is_valid_bsxfun ("operator .^", a_dims, b_dims)) \ { \ return bsxfun_pow (a, b); \ } \ @@ -782,7 +782,7 @@ dim_vector b_dims = b.dims (); \ if (a_dims != b_dims) \ { \ - if (is_valid_bsxfun (a_dims, b_dims)) \ + if (is_valid_bsxfun ("operator .^", a_dims, b_dims)) \ { \ return bsxfun_pow (a, b); \ } \ @@ -808,7 +808,7 @@ dim_vector b_dims = b.dims (); \ if (a_dims != b_dims) \ { \ - if (is_valid_bsxfun (a_dims, b_dims)) \ + if (is_valid_bsxfun ("operator .^", a_dims, b_dims)) \ { \ return bsxfun_pow (a, b); \ } \ diff -r 4000ad5fe0f6 -r c3d401562410 src/xpow.cc --- a/src/xpow.cc Thu Dec 15 10:07:57 2011 -0500 +++ b/src/xpow.cc Thu Dec 15 11:23:51 2011 -0500 @@ -1245,7 +1245,7 @@ if (a_dims != b_dims) { - if (is_valid_bsxfun (a_dims, b_dims)) + if (is_valid_bsxfun ("operator .^", a_dims, b_dims)) { //Potentially complex results NDArray xa = octave_value_extract (a); @@ -1333,7 +1333,7 @@ if (a_dims != b_dims) { - if (is_valid_bsxfun (a_dims, b_dims)) + if (is_valid_bsxfun ("operator .^", a_dims, b_dims)) { return bsxfun_pow (a, b); } @@ -1432,7 +1432,7 @@ if (a_dims != b_dims) { - if (is_valid_bsxfun (a_dims, b_dims)) + if (is_valid_bsxfun ("operator .^", a_dims, b_dims)) { return bsxfun_pow (a, b); } @@ -1482,7 +1482,7 @@ if (a_dims != b_dims) { - if (is_valid_bsxfun (a_dims, b_dims)) + if (is_valid_bsxfun ("operator .^", a_dims, b_dims)) { return bsxfun_pow (a, b); } @@ -2598,7 +2598,7 @@ if (a_dims != b_dims) { - if (is_valid_bsxfun (a_dims, b_dims)) + if (is_valid_bsxfun ("operator .^", a_dims, b_dims)) { //Potentially complex results FloatNDArray xa = octave_value_extract (a); @@ -2686,7 +2686,7 @@ if (a_dims != b_dims) { - if (is_valid_bsxfun (a_dims, b_dims)) + if (is_valid_bsxfun ("operator .^", a_dims, b_dims)) { return bsxfun_pow (a, b); } @@ -2785,7 +2785,7 @@ if (a_dims != b_dims) { - if (is_valid_bsxfun (a_dims, b_dims)) + if (is_valid_bsxfun ("operator .^", a_dims, b_dims)) { return bsxfun_pow (a, b); } @@ -2835,7 +2835,7 @@ if (a_dims != b_dims) { - if (is_valid_bsxfun (a_dims, b_dims)) + if (is_valid_bsxfun ("operator .^", a_dims, b_dims)) { return bsxfun_pow (a, b); }