mlx.core.compile#
- compile(fun: Callable, inputs: object | None = None, outputs: object | None = None, shapeless: bool = False) Callable #
Returns a compiled function which produces the same output as
fun
.- Parameters:
fun (Callable) – A function which takes a variable number of
array
or trees ofarray
and returns a variable number ofarray
or trees ofarray
.inputs (list or dict, optional) – These inputs will be captured during the function compilation along with the inputs to
fun
. Theinputs
can be alist
or adict
containing arbitrarily nested lists, dictionaries, or arrays. Leaf nodes that are notarray
are ignored. Default:None
outputs (list or dict, optional) – These outputs will be captured and updated in a compiled function. The
outputs
can be alist
or adict
containing arbitrarily nested lists, dictionaries, or arrays. Leaf nodes that are notarray
are ignored. Default:None
shapeless (bool, optional) – A function compiled with the
shapeless
option enabled will not be recompiled when the input shape changes. Not all functions can be compiled withshapeless
enabled. Attempting to compile such functions with shapeless enabled will throw. Note, changing the number of dimensions or type of any input will result in a recompilation even withshapeless
set toTrue
. Default:False
- Returns:
A compiled function which has the same input arguments as
fun
and returns the the same output(s).- Return type:
Callable