Computes the sum of the diagonal elements of a 2D array, or the sum along diagonals of a higher dimensional array.
Examples
x <- mlx_matrix(1:9, 3, 3)
mlx_trace(x)
#> mlx array []
#> dtype: float32
#> device: gpu
#> values:
#> [1] 15
mlx_trace(x, offset = 1)
#> mlx array []
#> dtype: float32
#> device: gpu
#> values:
#> [1] 12