oarust 0.15.1

GPU-first semantic computing engine written in Rust
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
// @generated by tool/gen/fn/generate.py; DO NOT EDIT.
// schemas=matrix_elemwise.json,matrix_blas.json,matrix_reduce.json,matrix_rng.json,matrix_index.json,matrix_view.json schema_version=1 generator_version=64
// schema_sha256=0a09fdbf87ba5fe45feaec26e0f150308339f0f173d5b2f438310625b2b2b47c
use crate::matrix::{CompactRowsResult, MoeExpertPlan, TopKResult};
use crate::{Matrix, Result};

impl Matrix {
	/// Add two matrices elementwise using multidirectional broadcasting.
	///
	/// Delegates to [`crate::matrix::add`].
	pub fn add(&self, right: &Matrix) -> Result<Self> {
		crate::matrix::add(self, right)
	}

	/// Add a bias matrix to another matrix elementwise using multidirectional broadcasting.
	///
	/// Delegates to [`crate::matrix::bias_add`].
	pub fn bias_add(&self, right: &Matrix) -> Result<Self> {
		crate::matrix::bias_add(self, right)
	}

	/// Subtract two FP32 matrices elementwise using multidirectional broadcasting.
	///
	/// Delegates to [`crate::matrix::sub`].
	pub fn sub(&self, right: &Matrix) -> Result<Self> {
		crate::matrix::sub(self, right)
	}

	/// Multiply two FP32 matrices elementwise.
	///
	/// Delegates to [`crate::matrix::mul`].
	pub fn mul(&self, right: &Matrix) -> Result<Self> {
		crate::matrix::mul(self, right)
	}

	/// Divide two FP32 matrices elementwise using multidirectional broadcasting.
	///
	/// Delegates to [`crate::matrix::div`].
	pub fn div(&self, right: &Matrix) -> Result<Self> {
		crate::matrix::div(self, right)
	}

	/// Multiply every FP32 matrix element by a scalar.
	///
	/// Delegates to [`crate::matrix::scale`].
	pub fn scale(&self, scalar: f32) -> Result<Self> {
		crate::matrix::scale(self, scalar)
	}

	/// Negate every FP32 matrix element.
	///
	/// Delegates to [`crate::matrix::neg`].
	pub fn neg(&self) -> Result<Self> {
		crate::matrix::neg(self)
	}

	/// Take the absolute value of every FP32 matrix element.
	///
	/// Delegates to [`crate::matrix::abs`].
	pub fn abs(&self) -> Result<Self> {
		crate::matrix::abs(self)
	}

	/// Take the natural logarithm of every FP32 matrix element.
	///
	/// Delegates to [`crate::matrix::log`].
	pub fn log(&self) -> Result<Self> {
		crate::matrix::log(self)
	}

	/// Take the square root of every FP32 matrix element.
	///
	/// Delegates to [`crate::matrix::sqrt`].
	pub fn sqrt(&self) -> Result<Self> {
		crate::matrix::sqrt(self)
	}

	/// Raise every FP32 matrix element to a scalar exponent.
	///
	/// Delegates to [`crate::matrix::pow`].
	pub fn pow(&self, exponent: f32) -> Result<Self> {
		crate::matrix::pow(self, exponent)
	}

	/// Add a scalar to every FP32 matrix element.
	///
	/// Delegates to [`crate::matrix::add_scalar`].
	pub fn add_scalar(&self, scalar: f32) -> Result<Self> {
		crate::matrix::add_scalar(self, scalar)
	}

	/// Subtract a scalar from every FP32 matrix element.
	///
	/// Delegates to [`crate::matrix::sub_scalar`].
	pub fn sub_scalar(&self, scalar: f32) -> Result<Self> {
		crate::matrix::sub_scalar(self, scalar)
	}

	/// Divide every FP32 matrix element by a scalar.
	///
	/// Delegates to [`crate::matrix::div_scalar`].
	pub fn div_scalar(&self, scalar: f32) -> Result<Self> {
		crate::matrix::div_scalar(self, scalar)
	}

	/// Take the exponential of every FP32 matrix element.
	///
	/// Delegates to [`crate::matrix::exp`].
	pub fn exp(&self) -> Result<Self> {
		crate::matrix::exp(self)
	}

	/// Take the sine of every FP32 matrix element.
	///
	/// Delegates to [`crate::matrix::sin`].
	pub fn sin(&self) -> Result<Self> {
		crate::matrix::sin(self)
	}

	/// Take the cosine of every FP32 matrix element.
	///
	/// Delegates to [`crate::matrix::cos`].
	pub fn cos(&self) -> Result<Self> {
		crate::matrix::cos(self)
	}

	/// Take the reciprocal of every FP32 matrix element.
	///
	/// Delegates to [`crate::matrix::reciprocal`].
	pub fn reciprocal(&self) -> Result<Self> {
		crate::matrix::reciprocal(self)
	}

	/// Cap every FP32 matrix element at an upper bound.
	///
	/// Delegates to [`crate::matrix::clamp_max`].
	pub fn clamp_max(&self, max: f32) -> Result<Self> {
		crate::matrix::clamp_max(self, max)
	}

	/// Raise every FP32 matrix element to a lower bound.
	///
	/// Delegates to [`crate::matrix::clamp_min`].
	pub fn clamp_min(&self, min: f32) -> Result<Self> {
		crate::matrix::clamp_min(self, min)
	}

	/// Deep-copy a dense matrix into independent device storage.
	///
	/// Delegates to [`crate::matrix::copy`].
	pub fn copy(&self) -> Result<Self> {
		crate::matrix::copy(self)
	}

	/// Multiply A by the transpose of B using the OA weight-layout convention.
	///
	/// Delegates to [`crate::matrix::mat_mul_nt`].
	pub fn mat_mul_nt(&self, right: &Matrix) -> Result<Self> {
		crate::matrix::mat_mul_nt(self, right)
	}

	/// Delegates to [`crate::matrix::softmax`].
	pub fn softmax(&self, dim: i32) -> Result<Self> {
		crate::matrix::softmax(self, dim)
	}

	/// Delegates to [`crate::matrix::log_softmax`].
	pub fn log_softmax(&self, dim: i32) -> Result<Self> {
		crate::matrix::log_softmax(self, dim)
	}

	/// Delegates to [`crate::matrix::sum`].
	pub fn sum(&self, dim: i32) -> Result<Self> {
		crate::matrix::sum(self, dim)
	}

	/// Delegates to [`crate::matrix::mean`].
	pub fn mean(&self, dim: i32) -> Result<Self> {
		crate::matrix::mean(self, dim)
	}

	/// Delegates to [`crate::matrix::max`].
	pub fn max(&self, dim: i32) -> Result<Self> {
		crate::matrix::max(self, dim)
	}

	/// Delegates to [`crate::matrix::argmax`].
	pub fn argmax(&self, dim: i32) -> Result<i64> {
		crate::matrix::argmax(self, dim)
	}

	/// Delegates to [`crate::matrix::categorical_accuracy_count`].
	pub fn categorical_accuracy_count(&self, labels: &Matrix) -> Result<Self> {
		crate::matrix::categorical_accuracy_count(self, labels)
	}

	/// Delegates to [`crate::matrix::masked_categorical_accuracy_count`].
	pub fn masked_categorical_accuracy_count(&self, labels: &Matrix, mask: &Matrix) -> Result<Self> {
		crate::matrix::masked_categorical_accuracy_count(self, labels, mask)
	}

	/// Delegates to [`crate::matrix::philox_uniform`].
	pub fn philox_uniform(&self, low: f32, high: f32, seed: u64) -> Result<Self> {
		crate::matrix::philox_uniform(self, low, high, seed)
	}

	/// Delegates to [`crate::matrix::philox_normal`].
	pub fn philox_normal(&self, mean: f32, stddev: f32, seed: u64) -> Result<Self> {
		crate::matrix::philox_normal(self, mean, stddev, seed)
	}

	/// Delegates to [`crate::matrix::dropout`].
	pub fn dropout(&self, probability: f32, seed: u64) -> Result<Self> {
		crate::matrix::dropout(self, probability, seed)
	}

	/// Delegates to [`crate::matrix::sample_logits`].
	pub fn sample_logits(&self, temperature: f32, top_k: i32, top_p: f32, seed: u64) -> Result<Self> {
		crate::matrix::sample_logits(self, temperature, top_k, top_p, seed)
	}

	/// Delegates to [`crate::matrix::top_k`].
	pub fn top_k(&self, k: i32, dim: i32) -> Result<TopKResult> {
		crate::matrix::top_k(self, k, dim)
	}

	/// Delegates to [`crate::matrix::top_k_mask`].
	pub fn top_k_mask(&self, num_experts: usize) -> Result<Self> {
		crate::matrix::top_k_mask(self, num_experts)
	}

	/// Delegates to [`crate::matrix::moe_expert_plan`].
	pub fn moe_expert_plan(&self, num_experts: usize) -> Result<MoeExpertPlan> {
		crate::matrix::moe_expert_plan(self, num_experts)
	}

	/// Delegates to [`crate::matrix::moe_routing_bias_update`].
	pub fn moe_routing_bias_update(
		&self,
		bias: &Matrix,
		experts_per_token: usize,
		gamma: f32,
	) -> Result<()> {
		crate::matrix::moe_routing_bias_update(self, bias, experts_per_token, gamma)
	}

	/// Delegates to [`crate::matrix::slice`].
	pub fn slice(&self, dim: i32, start: i64, end: i64) -> Result<Self> {
		crate::matrix::slice(self, dim, start, end)
	}

	/// Delegates to [`crate::matrix::repeat_interleave`].
	pub fn repeat_interleave(&self, repeats: usize, dim: i32) -> Result<Self> {
		crate::matrix::repeat_interleave(self, repeats, dim)
	}

	/// Delegates to [`crate::matrix::gather`].
	pub fn gather(&self, indices: &Matrix) -> Result<Self> {
		crate::matrix::gather(self, indices)
	}

	/// Delegates to [`crate::matrix::gather_last_dim`].
	pub fn gather_last_dim(&self, indices: &Matrix) -> Result<Self> {
		crate::matrix::gather_last_dim(self, indices)
	}

	/// Delegates to [`crate::matrix::transpose`].
	pub fn transpose(&self, dim0: i32, dim1: i32) -> Result<Self> {
		crate::matrix::transpose(self, dim0, dim1)
	}

	/// Delegates to [`crate::matrix::equal`].
	pub fn equal(&self, value: f32) -> Result<Self> {
		crate::matrix::equal(self, value)
	}

	/// Delegates to [`crate::matrix::causal_mask`].
	pub fn causal_mask(&self) -> Result<Self> {
		crate::matrix::causal_mask(self)
	}

	/// Delegates to [`crate::matrix::greater_equal`].
	pub fn greater_equal(&self, value: f32) -> Result<Self> {
		crate::matrix::greater_equal(self, value)
	}

	/// Delegates to [`crate::matrix::split`].
	pub fn split(&self, sizes: &[i64], dim: i32) -> Result<Vec<Matrix>> {
		crate::matrix::split(self, sizes, dim)
	}

	/// Delegates to [`crate::matrix::compact_rows`].
	pub fn compact_rows(&self, mask: &Matrix) -> Result<CompactRowsResult> {
		crate::matrix::compact_rows(self, mask)
	}

	/// Delegates to [`crate::matrix::scatter_rows`].
	pub fn scatter_rows(&self, source: &Matrix, row_map: &Matrix, count: &Matrix) -> Result<Self> {
		crate::matrix::scatter_rows(self, source, row_map, count)
	}

	/// Delegates to [`crate::matrix::scatter_rows_indirect`].
	pub fn scatter_rows_indirect(&self, source: &Matrix, plan: &CompactRowsResult) -> Result<Self> {
		crate::matrix::scatter_rows_indirect(self, source, plan)
	}

	/// Delegates to [`crate::matrix::reshape`].
	pub fn reshape(&self, shape: impl Into<Vec<usize>>) -> Result<Self> {
		crate::matrix::reshape(self, shape)
	}
}

const _: fn(&Matrix, &Matrix) -> Result<Matrix> = crate::matrix::add;
const _: fn(&Matrix, &Matrix) -> Result<Matrix> = Matrix::add;
const _: fn(&Matrix, &Matrix) -> Result<Matrix> = crate::matrix::bias_add;
const _: fn(&Matrix, &Matrix) -> Result<Matrix> = Matrix::bias_add;
const _: fn(&Matrix, &Matrix) -> Result<Matrix> = crate::matrix::sub;
const _: fn(&Matrix, &Matrix) -> Result<Matrix> = Matrix::sub;
const _: fn(&Matrix, &Matrix) -> Result<Matrix> = crate::matrix::mul;
const _: fn(&Matrix, &Matrix) -> Result<Matrix> = Matrix::mul;
const _: fn(&Matrix, &Matrix) -> Result<Matrix> = crate::matrix::div;
const _: fn(&Matrix, &Matrix) -> Result<Matrix> = Matrix::div;
const _: fn(&Matrix, f32) -> Result<Matrix> = crate::matrix::scale;
const _: fn(&Matrix, f32) -> Result<Matrix> = Matrix::scale;
const _: fn(&Matrix) -> Result<Matrix> = crate::matrix::neg;
const _: fn(&Matrix) -> Result<Matrix> = Matrix::neg;
const _: fn(&Matrix) -> Result<Matrix> = crate::matrix::abs;
const _: fn(&Matrix) -> Result<Matrix> = Matrix::abs;
const _: fn(&Matrix) -> Result<Matrix> = crate::matrix::log;
const _: fn(&Matrix) -> Result<Matrix> = Matrix::log;
const _: fn(&Matrix) -> Result<Matrix> = crate::matrix::sqrt;
const _: fn(&Matrix) -> Result<Matrix> = Matrix::sqrt;
const _: fn(&Matrix, f32) -> Result<Matrix> = crate::matrix::pow;
const _: fn(&Matrix, f32) -> Result<Matrix> = Matrix::pow;
const _: fn(&Matrix, f32) -> Result<Matrix> = crate::matrix::add_scalar;
const _: fn(&Matrix, f32) -> Result<Matrix> = Matrix::add_scalar;
const _: fn(&Matrix, f32) -> Result<Matrix> = crate::matrix::sub_scalar;
const _: fn(&Matrix, f32) -> Result<Matrix> = Matrix::sub_scalar;
const _: fn(&Matrix, f32) -> Result<Matrix> = crate::matrix::div_scalar;
const _: fn(&Matrix, f32) -> Result<Matrix> = Matrix::div_scalar;
const _: fn(&Matrix) -> Result<Matrix> = crate::matrix::exp;
const _: fn(&Matrix) -> Result<Matrix> = Matrix::exp;
const _: fn(&Matrix) -> Result<Matrix> = crate::matrix::sin;
const _: fn(&Matrix) -> Result<Matrix> = Matrix::sin;
const _: fn(&Matrix) -> Result<Matrix> = crate::matrix::cos;
const _: fn(&Matrix) -> Result<Matrix> = Matrix::cos;
const _: fn(&Matrix) -> Result<Matrix> = crate::matrix::reciprocal;
const _: fn(&Matrix) -> Result<Matrix> = Matrix::reciprocal;
const _: fn(&Matrix, f32) -> Result<Matrix> = crate::matrix::clamp_max;
const _: fn(&Matrix, f32) -> Result<Matrix> = Matrix::clamp_max;
const _: fn(&Matrix, f32) -> Result<Matrix> = crate::matrix::clamp_min;
const _: fn(&Matrix, f32) -> Result<Matrix> = Matrix::clamp_min;
const _: fn(&Matrix) -> Result<Matrix> = crate::matrix::copy;
const _: fn(&Matrix) -> Result<Matrix> = Matrix::copy;
const _: fn(&Matrix, &Matrix) -> Result<Matrix> = crate::matrix::mat_mul_nt;
const _: fn(&Matrix, &Matrix) -> Result<Matrix> = Matrix::mat_mul_nt;
const _: fn(&Matrix, i32) -> Result<Matrix> = crate::matrix::softmax;
const _: fn(&Matrix, i32) -> Result<Matrix> = Matrix::softmax;
const _: fn(&Matrix, i32) -> Result<Matrix> = crate::matrix::log_softmax;
const _: fn(&Matrix, i32) -> Result<Matrix> = Matrix::log_softmax;
const _: fn(&Matrix, i32) -> Result<Matrix> = crate::matrix::sum;
const _: fn(&Matrix, i32) -> Result<Matrix> = Matrix::sum;
const _: fn(&Matrix, i32) -> Result<Matrix> = crate::matrix::mean;
const _: fn(&Matrix, i32) -> Result<Matrix> = Matrix::mean;
const _: fn(&Matrix, i32) -> Result<Matrix> = crate::matrix::max;
const _: fn(&Matrix, i32) -> Result<Matrix> = Matrix::max;
const _: fn(&Matrix, i32) -> Result<i64> = crate::matrix::argmax;
const _: fn(&Matrix, i32) -> Result<i64> = Matrix::argmax;
const _: fn(&Matrix, &Matrix) -> Result<Matrix> = crate::matrix::categorical_accuracy_count;
const _: fn(&Matrix, &Matrix) -> Result<Matrix> = Matrix::categorical_accuracy_count;
const _: fn(&Matrix, &Matrix, &Matrix) -> Result<Matrix> =
	crate::matrix::masked_categorical_accuracy_count;
const _: fn(&Matrix, &Matrix, &Matrix) -> Result<Matrix> =
	Matrix::masked_categorical_accuracy_count;
const _: fn(&Matrix, f32, f32, u64) -> Result<Matrix> = crate::matrix::philox_uniform;
const _: fn(&Matrix, f32, f32, u64) -> Result<Matrix> = Matrix::philox_uniform;
const _: fn(&Matrix, f32, f32, u64) -> Result<Matrix> = crate::matrix::philox_normal;
const _: fn(&Matrix, f32, f32, u64) -> Result<Matrix> = Matrix::philox_normal;
const _: fn(&Matrix, f32, u64) -> Result<Matrix> = crate::matrix::dropout;
const _: fn(&Matrix, f32, u64) -> Result<Matrix> = Matrix::dropout;
const _: fn(&Matrix, f32, i32, f32, u64) -> Result<Matrix> = crate::matrix::sample_logits;
const _: fn(&Matrix, f32, i32, f32, u64) -> Result<Matrix> = Matrix::sample_logits;
const _: fn(&Matrix, i32, i32) -> Result<TopKResult> = crate::matrix::top_k;
const _: fn(&Matrix, i32, i32) -> Result<TopKResult> = Matrix::top_k;
const _: fn(&Matrix, usize) -> Result<Matrix> = crate::matrix::top_k_mask;
const _: fn(&Matrix, usize) -> Result<Matrix> = Matrix::top_k_mask;
const _: fn(&Matrix, usize) -> Result<MoeExpertPlan> = crate::matrix::moe_expert_plan;
const _: fn(&Matrix, usize) -> Result<MoeExpertPlan> = Matrix::moe_expert_plan;
const _: fn(&Matrix, &Matrix, usize, f32) -> Result<()> = crate::matrix::moe_routing_bias_update;
const _: fn(&Matrix, &Matrix, usize, f32) -> Result<()> = Matrix::moe_routing_bias_update;
const _: fn(&Matrix, i32, i64, i64) -> Result<Matrix> = crate::matrix::slice;
const _: fn(&Matrix, i32, i64, i64) -> Result<Matrix> = Matrix::slice;
const _: fn(&Matrix, usize, i32) -> Result<Matrix> = crate::matrix::repeat_interleave;
const _: fn(&Matrix, usize, i32) -> Result<Matrix> = Matrix::repeat_interleave;
const _: fn(&Matrix, &Matrix) -> Result<Matrix> = crate::matrix::gather;
const _: fn(&Matrix, &Matrix) -> Result<Matrix> = Matrix::gather;
const _: fn(&Matrix, &Matrix) -> Result<Matrix> = crate::matrix::gather_last_dim;
const _: fn(&Matrix, &Matrix) -> Result<Matrix> = Matrix::gather_last_dim;
const _: fn(&Matrix, i32, i32) -> Result<Matrix> = crate::matrix::transpose;
const _: fn(&Matrix, i32, i32) -> Result<Matrix> = Matrix::transpose;
const _: fn(&Matrix, f32) -> Result<Matrix> = crate::matrix::equal;
const _: fn(&Matrix, f32) -> Result<Matrix> = Matrix::equal;
const _: fn(&Matrix) -> Result<Matrix> = crate::matrix::causal_mask;
const _: fn(&Matrix) -> Result<Matrix> = Matrix::causal_mask;
const _: fn(&Matrix, f32) -> Result<Matrix> = crate::matrix::greater_equal;
const _: fn(&Matrix, f32) -> Result<Matrix> = Matrix::greater_equal;
const _: fn(&Matrix, &[i64], i32) -> Result<Vec<Matrix>> = crate::matrix::split;
const _: fn(&Matrix, &[i64], i32) -> Result<Vec<Matrix>> = Matrix::split;
const _: fn(&Matrix, &Matrix) -> Result<CompactRowsResult> = crate::matrix::compact_rows;
const _: fn(&Matrix, &Matrix) -> Result<CompactRowsResult> = Matrix::compact_rows;
const _: fn(&Matrix, &Matrix, &Matrix, &Matrix) -> Result<Matrix> = crate::matrix::scatter_rows;
const _: fn(&Matrix, &Matrix, &Matrix, &Matrix) -> Result<Matrix> = Matrix::scatter_rows;
const _: fn(&Matrix, &Matrix, &CompactRowsResult) -> Result<Matrix> =
	crate::matrix::scatter_rows_indirect;
const _: fn(&Matrix, &Matrix, &CompactRowsResult) -> Result<Matrix> = Matrix::scatter_rows_indirect;