File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2411,6 +2411,18 @@ def _is_jax_array(x):
24112411 and isinstance (x , tp ))
24122412
24132413
2414+ def _is_mlx_array (x ):
2415+ """Return whether *x* is a MLX Array."""
2416+ try :
2417+ # We're intentionally not attempting to import mlx. If somebody
2418+ # has created a mlx array, mlx should already be in sys.modules.
2419+ tp = sys .modules .get ("mlx.core" ).array
2420+ except AttributeError :
2421+ return False # Module not imported or a nonstandard module with no Array attr.
2422+ return (isinstance (tp , type ) # Just in case it's a very nonstandard module.
2423+ and isinstance (x , tp ))
2424+
2425+
24142426def _is_pandas_dataframe (x ):
24152427 """Check if *x* is a Pandas DataFrame."""
24162428 try :
@@ -2454,7 +2466,10 @@ def _unpack_to_numpy(x):
24542466 # so in this case we do not want to return a function
24552467 if isinstance (xtmp , np .ndarray ):
24562468 return xtmp
2457- if _is_torch_array (x ) or _is_jax_array (x ) or _is_tensorflow_array (x ):
2469+ if _is_torch_array (x ) \
2470+ or _is_jax_array (x ) \
2471+ or _is_tensorflow_array (x ) \
2472+ or _is_mlx_array (x ):
24582473 # using np.asarray() instead of explicitly __array__(), as the latter is
24592474 # only _one_ of many methods, and it's the last resort, see also
24602475 # https://numpy.org/devdocs/user/basics.interoperability.html#using-arbitrary-objects-in-numpy
You can’t perform that action at this time.
0 commit comments