mlx.core.import_function#
- import_function(file: str, return_metadata: bool = False) Callable | tuple[Callable, str]#
Import a function from a file.
The imported function can be called either with
*argsand**kwargsor with a tuple of arrays and/or dictionary of string keys with array values. Imported functions always return a tuple of arrays.Warning
This is part of an experimental API which is likely to change in future versions of MLX. Functions exported with older versions of MLX may not be compatible with future versions.
- Parameters:
- Returns:
The imported function. If
return_metadataisTruea tuple of the imported function and the metadata string is returned instead.- Return type:
Callable or tuple
Example
>>> fn = mx.import_function("function.mlxfn") >>> out = fn(a, b, x=x, y=y)[0] >>> >>> out = fn((a, b), {"x": x, "y": y})[0]