[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Removing broadcasting from Octave
From: |
John W. Eaton |
Subject: |
Re: Removing broadcasting from Octave |
Date: |
Thu, 15 Dec 2011 01:21:44 -0500 |
On 15-Dec-2011, fork wrote:
| John W. Eaton <jwe <at> octave.org> writes:
|
| > Jordi, do you agree that the patch below is enough to disable the
| > feature, or is there something else that needs to be done?
|
| Is there some way to have it turned on or off via a function instead of at
| compilation time (like debug_on_error(1))? I think it is a great feature,
but I
| agree that it is still sort of experimental.
The following patch is close, but maybe not exactly the right thing.
The problem is that if someone does
warning error Octave:auto-bsxfun
then the somewhat strange error message
error: operator .*: automatic bsxfun applied
will appear, followed by actually performing the operation. I can't
think of a message that makes better sense both as a warning and an
error. But maybe this is good enough. I would leave the warning and
error disabled by default, but users could easily change that if they
wish. It's also not so great that we go ahead and perform the
operation anyway, even if an error message is printed. But I don't
see a great short-term fix that will improve the situation very much.
Longer term, we should probably work toward making liboctave throw C++
exceptions instead of using a pointer to the Octave error handling
function since we can't check error_state in liboctave (and I really
don't think we should make it possible to do that).
jwe
diff --git a/liboctave/bsxfun.h b/liboctave/bsxfun.h
--- a/liboctave/bsxfun.h
+++ b/liboctave/bsxfun.h
@@ -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 bsxfun 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 bsxfun applied", name.c_str ());
+
return true;
}
diff --git a/liboctave/mx-inlines.cc b/liboctave/mx-inlines.cc
--- a/liboctave/mx-inlines.cc
+++ b/liboctave/mx-inlines.cc
@@ -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 --git a/liboctave/oct-binmap.h b/liboctave/oct-binmap.h
--- a/liboctave/oct-binmap.h
+++ b/liboctave/oct-binmap.h
@@ -174,7 +174,7 @@
return binmap<U, T, R, F> (xa, ya(0), fcn);
else if (xad != yad)
{
- if (is_valid_bsxfun (xad, yad))
+ if (is_valid_bsxfun (name, xad, yad))
{
bsxfun_wrapper<U, T, R, F>::set_f(fcn);
return do_bsxfun_op (xa, ya,
diff --git a/src/OPERATORS/op-int.h b/src/OPERATORS/op-int.h
--- a/src/OPERATORS/op-int.h
+++ b/src/OPERATORS/op-int.h
@@ -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 --git a/src/xpow.cc b/src/xpow.cc
--- a/src/xpow.cc
+++ b/src/xpow.cc
@@ -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<NDArray> (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<FloatNDArray> (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);
}
- Re: Removing broadcasting from Octave, (continued)
- Re: Removing broadcasting from Octave, Juan Pablo Carbajal, 2011/12/14
- Re: Removing broadcasting from Octave, Przemek Klosowski, 2011/12/14
- Re: Removing broadcasting from Octave, Robert T. Short, 2011/12/14
- Re: Removing broadcasting from Octave, Juan Pablo Carbajal, 2011/12/14
- Re: Removing broadcasting from Octave, Robert T. Short, 2011/12/14
- Re: Removing broadcasting from Octave, Michael Godfrey, 2011/12/14
- Re: Removing broadcasting from Octave, John W. Eaton, 2011/12/14
- Re: Removing broadcasting from Octave, Jordi Gutiérrez Hermoso, 2011/12/14
- Re: Removing broadcasting from Octave, Michael D Godfrey, 2011/12/14
- Re: Removing broadcasting from Octave, fork, 2011/12/14
- Re: Removing broadcasting from Octave,
John W. Eaton <=
- Re: Removing broadcasting from Octave, Juan Pablo Carbajal, 2011/12/15
- Re: Removing broadcasting from Octave, Jordi Gutiérrez Hermoso, 2011/12/15
- Re: Removing broadcasting from Octave, Søren Hauberg, 2011/12/15
- Re: Removing broadcasting from Octave, Jordi Gutiérrez Hermoso, 2011/12/15
- Re: Removing broadcasting from Octave, Judd Storrs, 2011/12/15
- Re: Removing broadcasting from Octave, John W. Eaton, 2011/12/15
- Re: Removing broadcasting from Octave, Michael Creel, 2011/12/15
- Re: Removing broadcasting from Octave, fork, 2011/12/15
- Re: Removing broadcasting from Octave, Jordi Gutiérrez Hermoso, 2011/12/15
- Re: Removing broadcasting from Octave, Michael D Godfrey, 2011/12/15