in numpy, the following is valid
Code: Select all
a = array([1, 2, 3, 4])
a < 2
2 > a
Code: Select all
MP_BINARY_OP_REVERSE_
Cheers,
Zoltán
Code: Select all
a = array([1, 2, 3, 4])
a < 2
2 > a
Code: Select all
MP_BINARY_OP_REVERSE_
Code: Select all
// in mp_binary_op (runtime.c):
// generic binary_op supplied by type
mp_binary_op_t saved_op = 0; // Add this line.
const mp_obj_type_t *type;
generic_binary_op:
....
// Add this just before the "unsupported_op" label.
if (saved_op == 0) {
saved_op = op;
switch (op) {
case MP_BINARY_OP_LESS:
op = MP_BINARY_OP_MORE;
break;
case MP_BINARY_OP_MORE:
op = MP_BINARY_OP_LESS;
break;
case MP_BINARY_OP_LESS_EQUAL:
op = MP_BINARY_OP_MORE_EQUAL;
break;
case MP_BINARY_OP_MORE_EQUAL:
op = MP_BINARY_OP_LESS_EQUAL;
break;
default:
goto unsupported_op;
}
mp_obj_t t = rhs;
rhs = lhs;
lhs = t;
// Have another go at binary_op, with updated op and arguments reversed.
goto generic_binary_op;
} else {
// Second go at generic_binary_op failed, restore the original op so the error message is correct.
op = saved_op;
}
unsupported_op: