Skip to content

[BUG] arithmetic operations with numpy arrays are not commutative #1066

@lkarthee

Description

@lkarthee

Describe the bug
mx array being first operand in arithmetic op is being converted complex numbers

To Reproduce

Include code snippet

import numpy as np
import mlx.core as mx

mx.array(1) + np.array(2)
x = mx.array(1)
y = np.array(2)
x + y 
# >>> array(3+0j, dtype=complex64)
x * y
# >>> array(2+0j, dtype=complex64)
y + x
# >>> 3
type(y + x)
# >>> <class 'numpy.int64'>
type(x + y)
# >>> <class 'mlx.core.array'>

Expected behavior
Conversion to complex should not happen. Arithmetic ops should be commutative (ignoring type like ndarray or mx).

Desktop (please complete the following information):

  • OS Version: [e.g. MacOS 14.1.2] MacOS 14.1.1
  • Version [e.g. 0.7.0] 0.11

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions