Skip to content

Commit

Permalink
[python] fix multiplication with ndarray when ndarray is rhs
Browse files Browse the repository at this point in the history
instead of duplicating ndarray management for int/float (more?),
just swap lhs and rhs (see bug #2102)
  • Loading branch information
serval2412 committed Feb 25, 2024
1 parent 117eea7 commit bdd618d
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions python/src/py/runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "py/builtin.h"
#include "py/stackctrl.h"
#include "py/gc.h"
#include "../../port/mod/ulab_tools.h"

#if MICROPY_DEBUG_VERBOSE // print debugging info
#define DEBUG_PRINT (1)
Expand Down Expand Up @@ -587,6 +588,14 @@ mp_obj_t mp_binary_op(mp_binary_op_t op, mp_obj_t lhs, mp_obj_t rhs) {
// generic binary_op supplied by type
const mp_obj_type_t *type;
generic_binary_op:
// instead of duplicating ndarray management for int/float/more?
// just swap lhs and rhs (see bug #2102)
if (mp_obj_is_type(rhs, &ulab_ndarray_type)) {
mp_obj_t temp = lhs;
lhs = rhs;
rhs = temp;
}

type = mp_obj_get_type(lhs);
if (type->binary_op != NULL) {
mp_obj_t result = type->binary_op(op, lhs, rhs);
Expand Down

0 comments on commit bdd618d

Please sign in to comment.