1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//! Bulk eval and async-eval over slices of [`crate::Array`].
//!
//! Mirrors `mlx-swift`'s `eval(...)` / `asyncEval(...)`
//! ([`Transforms+Eval.swift`](https://github.com/ml-explore/mlx-swift/blob/main/Source/MLX/Transforms%2BEval.swift))
//! and `mlx.core.eval` / `mlx.core.async_eval`. Single-array eval is available
//! as the inherent [`crate::Array::eval`]; this module is for the n-array case
//! that mlx-c handles via `mlx_eval(mlx_vector_array)`.
use crate::;
/// Force evaluation of every array in `arrays`. Blocks until all results are
/// materialized.
///
/// `arrays` is borrowed (`&[&Array]`); the wrapper builds a temporary
/// `mlx_vector_array` of refcount-shared handles for the eval call and frees
/// it on return. Errors surface via [`crate::Error::Backend`].
///
/// ```no_run
/// # fn run() -> mlxrs::Result<()> {
/// let a = mlxrs::Array::ones::<f32>(&(2, 2))?;
/// let b = mlxrs::Array::ones::<f32>(&(2, 2))?;
/// mlxrs::transforms::eval(&[&a, &b])?;
/// # Ok(()) }
/// ```
/// Asynchronously enqueue evaluation of every array in `arrays`. Returns
/// immediately; the results materialize in the background on the array's
/// stream. To synchronize on completion, follow with [`eval`] (or the inherent
/// [`crate::Array::eval`]) on any of the same arrays, which will block until
/// the async work finishes.
///
/// ```no_run
/// # fn run() -> mlxrs::Result<()> {
/// let mut a = mlxrs::Array::ones::<f32>(&(2, 2))?;
/// let b = mlxrs::Array::ones::<f32>(&(2, 2))?;
/// mlxrs::transforms::async_eval(&[&a, &b])?;
/// // ... unrelated work ...
/// a.eval()?; // syncs
/// # Ok(()) }
/// ```