File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1077,3 +1077,34 @@ def __array__(self):
10771077 # if not mocked, and the implementation does not guarantee it
10781078 # is the same Python object, just the same values.
10791079 assert_array_equal (result , data )
1080+
1081+
1082+ def test_unpack_to_numpy_from_mlx ():
1083+ """
1084+ Test that mlx arrays are converted to NumPy arrays.
1085+
1086+ We don't want to create a dependency on mlx in the test suite, so we mock it.
1087+ """
1088+ class Array :
1089+ def __init__ (self , data ):
1090+ self .data = data
1091+
1092+ def __array__ (self ):
1093+ return self .data
1094+
1095+ # mlx is something peculiar
1096+ # class `array` is in `mlx.core`
1097+ mlx_core = ModuleType ('mlx.core' )
1098+ mlx_core .array = Array
1099+
1100+ sys .modules ['mlx.core' ] = mlx_core
1101+
1102+ data = np .arange (10 )
1103+ mlx_array = mlx_core .array (data )
1104+
1105+ result = cbook ._unpack_to_numpy (mlx_array )
1106+ assert isinstance (result , np .ndarray )
1107+ # compare results, do not check for identity: the latter would fail
1108+ # if not mocked, and the implementation does not guarantee it
1109+ # is the same Python object, just the same values.
1110+ assert_array_equal (result , data )
You can’t perform that action at this time.
0 commit comments