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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
//! Generated MLX-C wrappers for the cumulative scan family.
//!
//! Each wrapper maps one MLX-C operation onto the runtime GPU stream
//! with the crate's owned-handle and captured-error semantics. The
//! coverage contract keeps this family in lockstep with the pinned
//! upstream headers.
use crate::bindings::support::raw_optional_dtype;
use crate::raw;
use crate::{MlxArray, MlxBindingsContext, MlxCError, MlxDtype};
impl MlxBindingsContext {
/// Applies MLX-C `mlx_cummax` on the runtime GPU stream.
pub fn cummax(
&self,
a: &MlxArray,
reverse: bool,
inclusive: bool,
) -> Result<MlxArray, MlxCError> {
self.output_array("apply MLX cummax", |output, stream| {
// SAFETY: Inputs and stream are live and output is uniquely writable.
unsafe { raw::mlx_cummax(output, a.raw(), reverse, inclusive, stream) }
})
}
/// Applies MLX-C `mlx_cummax_axis` on the runtime GPU stream.
pub fn cummax_axis(
&self,
a: &MlxArray,
axis: i32,
reverse: bool,
inclusive: bool,
) -> Result<MlxArray, MlxCError> {
self.output_array("apply MLX cummax_axis", |output, stream| {
// SAFETY: Inputs and stream are live and output is uniquely writable.
unsafe { raw::mlx_cummax_axis(output, a.raw(), axis, reverse, inclusive, stream) }
})
}
/// Applies MLX-C `mlx_cummin` on the runtime GPU stream.
pub fn cummin(
&self,
a: &MlxArray,
reverse: bool,
inclusive: bool,
) -> Result<MlxArray, MlxCError> {
self.output_array("apply MLX cummin", |output, stream| {
// SAFETY: Inputs and stream are live and output is uniquely writable.
unsafe { raw::mlx_cummin(output, a.raw(), reverse, inclusive, stream) }
})
}
/// Applies MLX-C `mlx_cummin_axis` on the runtime GPU stream.
pub fn cummin_axis(
&self,
a: &MlxArray,
axis: i32,
reverse: bool,
inclusive: bool,
) -> Result<MlxArray, MlxCError> {
self.output_array("apply MLX cummin_axis", |output, stream| {
// SAFETY: Inputs and stream are live and output is uniquely writable.
unsafe { raw::mlx_cummin_axis(output, a.raw(), axis, reverse, inclusive, stream) }
})
}
/// Applies MLX-C `mlx_cumprod` on the runtime GPU stream.
pub fn cumprod(
&self,
a: &MlxArray,
reverse: bool,
inclusive: bool,
dtype: Option<MlxDtype>,
) -> Result<MlxArray, MlxCError> {
self.output_array("apply MLX cumprod", |output, stream| {
// SAFETY: Inputs and stream are live and output is uniquely writable.
unsafe {
raw::mlx_cumprod(
output,
a.raw(),
reverse,
inclusive,
raw_optional_dtype(dtype),
stream,
)
}
})
}
/// Applies MLX-C `mlx_cumprod_axis` on the runtime GPU stream.
pub fn cumprod_axis(
&self,
a: &MlxArray,
axis: i32,
reverse: bool,
inclusive: bool,
dtype: Option<MlxDtype>,
) -> Result<MlxArray, MlxCError> {
self.output_array("apply MLX cumprod_axis", |output, stream| {
// SAFETY: Inputs and stream are live and output is uniquely writable.
unsafe {
raw::mlx_cumprod_axis(
output,
a.raw(),
axis,
reverse,
inclusive,
raw_optional_dtype(dtype),
stream,
)
}
})
}
/// Applies MLX-C `mlx_cumsum` on the runtime GPU stream.
pub fn cumsum_across_all_axes(
&self,
a: &MlxArray,
reverse: bool,
inclusive: bool,
dtype: Option<MlxDtype>,
) -> Result<MlxArray, MlxCError> {
self.output_array("apply MLX cumsum_across_all_axes", |output, stream| {
// SAFETY: Inputs and stream are live and output is uniquely writable.
unsafe {
raw::mlx_cumsum(
output,
a.raw(),
reverse,
inclusive,
raw_optional_dtype(dtype),
stream,
)
}
})
}
/// Applies MLX-C `mlx_logcumsumexp` on the runtime GPU stream.
pub fn logcumsumexp(
&self,
a: &MlxArray,
reverse: bool,
inclusive: bool,
) -> Result<MlxArray, MlxCError> {
self.output_array("apply MLX logcumsumexp", |output, stream| {
// SAFETY: Inputs and stream are live and output is uniquely writable.
unsafe { raw::mlx_logcumsumexp(output, a.raw(), reverse, inclusive, stream) }
})
}
/// Applies MLX-C `mlx_logcumsumexp_axis` on the runtime GPU stream.
pub fn logcumsumexp_axis(
&self,
a: &MlxArray,
axis: i32,
reverse: bool,
inclusive: bool,
) -> Result<MlxArray, MlxCError> {
self.output_array("apply MLX logcumsumexp_axis", |output, stream| {
// SAFETY: Inputs and stream are live and output is uniquely writable.
unsafe { raw::mlx_logcumsumexp_axis(output, a.raw(), axis, reverse, inclusive, stream) }
})
}
}