extmod/Matrix: scalar division
@@ -618,7 +618,7 @@ STATIC mp_obj_t robotics_Matrix_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp
return robotics_Matrix__add(lhs_in, rhs_in, false);
case MP_BINARY_OP_MULTIPLY:
case MP_BINARY_OP_INPLACE_MULTIPLY:
- // If right of the operands is a number, just scale.
+ // If right of operand is a number, just scale to be faster
if (mp_obj_is_float(rhs_in) || mp_obj_is_int(rhs_in)) {
return robotics_Matrix__scale(lhs_in, mp_obj_get_float_to_f(rhs_in));
}
@@ -627,6 +627,10 @@ STATIC mp_obj_t robotics_Matrix_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp
case MP_BINARY_OP_REVERSE_MULTIPLY:
// This gets called for c*A, so scale A by c (rhs/lhs is meaningless here)
return robotics_Matrix__scale(lhs_in, mp_obj_get_float_to_f(rhs_in));
+ case MP_BINARY_OP_TRUE_DIVIDE:
+ case MP_BINARY_OP_INPLACE_TRUE_DIVIDE:
+ // Scalar division by c is scalar multiplication by 1/c
+ return robotics_Matrix__scale(lhs_in, 1 / mp_obj_get_float_to_f(rhs_in));
default:
// Other operations not supported
return MP_OBJ_NULL;
