.. _function_transforms: Function Transforms =================== .. currentmodule:: mlx.core MLX uses composable function transformations for automatic differentiation and vectorization. The key id
.. _function_transforms: Function Transforms =================== .. currentmodule:: mlx.core MLX uses composable function transformations for automatic differentiation and vectorization. The key idea behind composable function transformations is that every transformation returns a function which can be further transformed. Here is a simple example: .. code-block:: shell >>> dfdx = mx.grad(mx.sin) >>> dfdx(mx.array(mx.pi)) array(-1, dtype=float32) >>> mx.cos(mx.array(mx.pi)) array(-1, dtype=float32) The output of :func:`grad` on :func:`sin` is simply another function. In this case it is the gradient of the sine function which is exactly the cosine function. To get the second derivative you can do:
Sign in to view the full prompt.
Sign In