Skip to main content

oa/matrix/
matrix.gen.rs

1// @generated by tool/gen/fn/generate.py; DO NOT EDIT.
2// 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
3// schema_sha256=9fe1c3e58ed515aa41ce391ea17b3963a204aeb2bb7dd6405b61ffe0d3bd0ee1
4use crate::matrix::{CompactRowsResult, MoeExpertPlan, PadMode, TopKResult};
5use crate::{Matrix, Result};
6
7impl Matrix {
8	/// Add two matrices elementwise using multidirectional broadcasting.
9	///
10	/// Delegates to [`crate::matrix::add`].
11	pub fn add(&self, right: &Matrix) -> Result<Self> {
12		crate::matrix::add(self, right)
13	}
14
15	/// Add a bias matrix to another matrix elementwise using multidirectional broadcasting.
16	///
17	/// Delegates to [`crate::matrix::bias_add`].
18	pub fn bias_add(&self, right: &Matrix) -> Result<Self> {
19		crate::matrix::bias_add(self, right)
20	}
21
22	/// Subtract two FP32 matrices elementwise using multidirectional broadcasting.
23	///
24	/// Delegates to [`crate::matrix::sub`].
25	pub fn sub(&self, right: &Matrix) -> Result<Self> {
26		crate::matrix::sub(self, right)
27	}
28
29	/// Multiply two FP32 matrices elementwise.
30	///
31	/// Delegates to [`crate::matrix::mul`].
32	pub fn mul(&self, right: &Matrix) -> Result<Self> {
33		crate::matrix::mul(self, right)
34	}
35
36	/// Divide two FP32 matrices elementwise using multidirectional broadcasting.
37	///
38	/// Delegates to [`crate::matrix::div`].
39	pub fn div(&self, right: &Matrix) -> Result<Self> {
40		crate::matrix::div(self, right)
41	}
42
43	/// Multiply every FP32 matrix element by a scalar.
44	///
45	/// Delegates to [`crate::matrix::scale`].
46	pub fn scale(&self, scalar: f32) -> Result<Self> {
47		crate::matrix::scale(self, scalar)
48	}
49
50	/// Negate every FP32 matrix element.
51	///
52	/// Delegates to [`crate::matrix::neg`].
53	pub fn neg(&self) -> Result<Self> {
54		crate::matrix::neg(self)
55	}
56
57	/// Take the absolute value of every FP32 matrix element.
58	///
59	/// Delegates to [`crate::matrix::abs`].
60	pub fn abs(&self) -> Result<Self> {
61		crate::matrix::abs(self)
62	}
63
64	/// Take the natural logarithm of every FP32 matrix element.
65	///
66	/// Delegates to [`crate::matrix::log`].
67	pub fn log(&self) -> Result<Self> {
68		crate::matrix::log(self)
69	}
70
71	/// Take the square root of every FP32 matrix element.
72	///
73	/// Delegates to [`crate::matrix::sqrt`].
74	pub fn sqrt(&self) -> Result<Self> {
75		crate::matrix::sqrt(self)
76	}
77
78	/// Raise every FP32 matrix element to a scalar exponent.
79	///
80	/// Delegates to [`crate::matrix::pow`].
81	pub fn pow(&self, exponent: f32) -> Result<Self> {
82		crate::matrix::pow(self, exponent)
83	}
84
85	/// Add a scalar to every FP32 matrix element.
86	///
87	/// Delegates to [`crate::matrix::add_scalar`].
88	pub fn add_scalar(&self, scalar: f32) -> Result<Self> {
89		crate::matrix::add_scalar(self, scalar)
90	}
91
92	/// Subtract a scalar from every FP32 matrix element.
93	///
94	/// Delegates to [`crate::matrix::sub_scalar`].
95	pub fn sub_scalar(&self, scalar: f32) -> Result<Self> {
96		crate::matrix::sub_scalar(self, scalar)
97	}
98
99	/// Divide every FP32 matrix element by a scalar.
100	///
101	/// Delegates to [`crate::matrix::div_scalar`].
102	pub fn div_scalar(&self, scalar: f32) -> Result<Self> {
103		crate::matrix::div_scalar(self, scalar)
104	}
105
106	/// Take the exponential of every FP32 matrix element.
107	///
108	/// Delegates to [`crate::matrix::exp`].
109	pub fn exp(&self) -> Result<Self> {
110		crate::matrix::exp(self)
111	}
112
113	/// Take the sine of every FP32 matrix element.
114	///
115	/// Delegates to [`crate::matrix::sin`].
116	pub fn sin(&self) -> Result<Self> {
117		crate::matrix::sin(self)
118	}
119
120	/// Take the cosine of every FP32 matrix element.
121	///
122	/// Delegates to [`crate::matrix::cos`].
123	pub fn cos(&self) -> Result<Self> {
124		crate::matrix::cos(self)
125	}
126
127	/// Take the reciprocal of every FP32 matrix element.
128	///
129	/// Delegates to [`crate::matrix::reciprocal`].
130	pub fn reciprocal(&self) -> Result<Self> {
131		crate::matrix::reciprocal(self)
132	}
133
134	/// Cap every FP32 matrix element at an upper bound.
135	///
136	/// Delegates to [`crate::matrix::clamp_max`].
137	pub fn clamp_max(&self, max: f32) -> Result<Self> {
138		crate::matrix::clamp_max(self, max)
139	}
140
141	/// Raise every FP32 matrix element to a lower bound.
142	///
143	/// Delegates to [`crate::matrix::clamp_min`].
144	pub fn clamp_min(&self, min: f32) -> Result<Self> {
145		crate::matrix::clamp_min(self, min)
146	}
147
148	/// Deep-copy a dense matrix into independent device storage.
149	///
150	/// Delegates to [`crate::matrix::copy`].
151	pub fn copy(&self) -> Result<Self> {
152		crate::matrix::copy(self)
153	}
154
155	/// Multiply A by the transpose of B using the OA weight-layout convention.
156	///
157	/// Delegates to [`crate::matrix::mat_mul_nt`].
158	pub fn mat_mul_nt(&self, right: &Matrix) -> Result<Self> {
159		crate::matrix::mat_mul_nt(self, right)
160	}
161
162	/// Delegates to [`crate::matrix::softmax`].
163	pub fn softmax(&self, dim: i32) -> Result<Self> {
164		crate::matrix::softmax(self, dim)
165	}
166
167	/// Delegates to [`crate::matrix::log_softmax`].
168	pub fn log_softmax(&self, dim: i32) -> Result<Self> {
169		crate::matrix::log_softmax(self, dim)
170	}
171
172	/// Delegates to [`crate::matrix::sum`].
173	pub fn sum(&self, dim: i32) -> Result<Self> {
174		crate::matrix::sum(self, dim)
175	}
176
177	/// Delegates to [`crate::matrix::mean`].
178	pub fn mean(&self, dim: i32) -> Result<Self> {
179		crate::matrix::mean(self, dim)
180	}
181
182	/// Delegates to [`crate::matrix::max`].
183	pub fn max(&self, dim: i32) -> Result<Self> {
184		crate::matrix::max(self, dim)
185	}
186
187	/// Delegates to [`crate::matrix::argmax`].
188	pub fn argmax(&self, dim: i32) -> Result<i64> {
189		crate::matrix::argmax(self, dim)
190	}
191
192	/// Delegates to [`crate::matrix::categorical_accuracy_count`].
193	pub fn categorical_accuracy_count(&self, labels: &Matrix) -> Result<Self> {
194		crate::matrix::categorical_accuracy_count(self, labels)
195	}
196
197	/// Delegates to [`crate::matrix::masked_categorical_accuracy_count`].
198	pub fn masked_categorical_accuracy_count(&self, labels: &Matrix, mask: &Matrix) -> Result<Self> {
199		crate::matrix::masked_categorical_accuracy_count(self, labels, mask)
200	}
201
202	/// Delegates to [`crate::matrix::philox_uniform`].
203	pub fn philox_uniform(&self, low: f32, high: f32, seed: u64) -> Result<Self> {
204		crate::matrix::philox_uniform(self, low, high, seed)
205	}
206
207	/// Delegates to [`crate::matrix::philox_normal`].
208	pub fn philox_normal(&self, mean: f32, stddev: f32, seed: u64) -> Result<Self> {
209		crate::matrix::philox_normal(self, mean, stddev, seed)
210	}
211
212	/// Delegates to [`crate::matrix::dropout`].
213	pub fn dropout(&self, probability: f32, seed: u64) -> Result<Self> {
214		crate::matrix::dropout(self, probability, seed)
215	}
216
217	/// Delegates to [`crate::matrix::sample_logits`].
218	pub fn sample_logits(&self, temperature: f32, top_k: i32, top_p: f32, seed: u64) -> Result<Self> {
219		crate::matrix::sample_logits(self, temperature, top_k, top_p, seed)
220	}
221
222	/// Delegates to [`crate::matrix::top_k`].
223	pub fn top_k(&self, k: i32, dim: i32) -> Result<TopKResult> {
224		crate::matrix::top_k(self, k, dim)
225	}
226
227	/// Delegates to [`crate::matrix::top_k_mask`].
228	pub fn top_k_mask(&self, num_experts: usize) -> Result<Self> {
229		crate::matrix::top_k_mask(self, num_experts)
230	}
231
232	/// Delegates to [`crate::matrix::moe_expert_plan`].
233	pub fn moe_expert_plan(&self, num_experts: usize) -> Result<MoeExpertPlan> {
234		crate::matrix::moe_expert_plan(self, num_experts)
235	}
236
237	/// Delegates to [`crate::matrix::moe_routing_bias_update`].
238	pub fn moe_routing_bias_update(
239		&self,
240		bias: &Matrix,
241		experts_per_token: usize,
242		gamma: f32,
243	) -> Result<()> {
244		crate::matrix::moe_routing_bias_update(self, bias, experts_per_token, gamma)
245	}
246
247	/// Delegates to [`crate::matrix::slice`].
248	pub fn slice(&self, dim: i32, start: i64, end: i64) -> Result<Self> {
249		crate::matrix::slice(self, dim, start, end)
250	}
251
252	/// Delegates to [`crate::matrix::pad`].
253	pub fn pad(&self, pads: &[usize], mode: PadMode, fill: f32) -> Result<Self> {
254		crate::matrix::pad(self, pads, mode, fill)
255	}
256
257	/// Delegates to [`crate::matrix::repeat_interleave`].
258	pub fn repeat_interleave(&self, repeats: usize, dim: i32) -> Result<Self> {
259		crate::matrix::repeat_interleave(self, repeats, dim)
260	}
261
262	/// Delegates to [`crate::matrix::gather`].
263	pub fn gather(&self, indices: &Matrix) -> Result<Self> {
264		crate::matrix::gather(self, indices)
265	}
266
267	/// Delegates to [`crate::matrix::gather_last_dim`].
268	pub fn gather_last_dim(&self, indices: &Matrix) -> Result<Self> {
269		crate::matrix::gather_last_dim(self, indices)
270	}
271
272	/// Delegates to [`crate::matrix::transpose`].
273	pub fn transpose(&self, dim0: i32, dim1: i32) -> Result<Self> {
274		crate::matrix::transpose(self, dim0, dim1)
275	}
276
277	/// Delegates to [`crate::matrix::equal`].
278	pub fn equal(&self, value: f32) -> Result<Self> {
279		crate::matrix::equal(self, value)
280	}
281
282	/// Delegates to [`crate::matrix::causal_mask`].
283	pub fn causal_mask(&self) -> Result<Self> {
284		crate::matrix::causal_mask(self)
285	}
286
287	/// Delegates to [`crate::matrix::greater_equal`].
288	pub fn greater_equal(&self, value: f32) -> Result<Self> {
289		crate::matrix::greater_equal(self, value)
290	}
291
292	/// Delegates to [`crate::matrix::split`].
293	pub fn split(&self, sizes: &[i64], dim: i32) -> Result<Vec<Matrix>> {
294		crate::matrix::split(self, sizes, dim)
295	}
296
297	/// Delegates to [`crate::matrix::compact_rows`].
298	pub fn compact_rows(&self, mask: &Matrix) -> Result<CompactRowsResult> {
299		crate::matrix::compact_rows(self, mask)
300	}
301
302	/// Delegates to [`crate::matrix::scatter_rows`].
303	pub fn scatter_rows(&self, source: &Matrix, row_map: &Matrix, count: &Matrix) -> Result<Self> {
304		crate::matrix::scatter_rows(self, source, row_map, count)
305	}
306
307	/// Delegates to [`crate::matrix::scatter_rows_indirect`].
308	pub fn scatter_rows_indirect(&self, source: &Matrix, plan: &CompactRowsResult) -> Result<Self> {
309		crate::matrix::scatter_rows_indirect(self, source, plan)
310	}
311
312	/// Delegates to [`crate::matrix::cast_f32_i32`].
313	pub fn cast_f32_i32(&self) -> Result<Self> {
314		crate::matrix::cast_f32_i32(self)
315	}
316
317	/// Delegates to [`crate::matrix::cast_i32_f32`].
318	pub fn cast_i32_f32(&self) -> Result<Self> {
319		crate::matrix::cast_i32_f32(self)
320	}
321
322	/// Delegates to [`crate::matrix::reshape`].
323	pub fn reshape(&self, shape: impl Into<Vec<usize>>) -> Result<Self> {
324		crate::matrix::reshape(self, shape)
325	}
326}
327
328const _: fn(&Matrix, &Matrix) -> Result<Matrix> = crate::matrix::add;
329const _: fn(&Matrix, &Matrix) -> Result<Matrix> = Matrix::add;
330const _: fn(&Matrix, &Matrix) -> Result<Matrix> = crate::matrix::bias_add;
331const _: fn(&Matrix, &Matrix) -> Result<Matrix> = Matrix::bias_add;
332const _: fn(&Matrix, &Matrix) -> Result<Matrix> = crate::matrix::sub;
333const _: fn(&Matrix, &Matrix) -> Result<Matrix> = Matrix::sub;
334const _: fn(&Matrix, &Matrix) -> Result<Matrix> = crate::matrix::mul;
335const _: fn(&Matrix, &Matrix) -> Result<Matrix> = Matrix::mul;
336const _: fn(&Matrix, &Matrix) -> Result<Matrix> = crate::matrix::div;
337const _: fn(&Matrix, &Matrix) -> Result<Matrix> = Matrix::div;
338const _: fn(&Matrix, f32) -> Result<Matrix> = crate::matrix::scale;
339const _: fn(&Matrix, f32) -> Result<Matrix> = Matrix::scale;
340const _: fn(&Matrix) -> Result<Matrix> = crate::matrix::neg;
341const _: fn(&Matrix) -> Result<Matrix> = Matrix::neg;
342const _: fn(&Matrix) -> Result<Matrix> = crate::matrix::abs;
343const _: fn(&Matrix) -> Result<Matrix> = Matrix::abs;
344const _: fn(&Matrix) -> Result<Matrix> = crate::matrix::log;
345const _: fn(&Matrix) -> Result<Matrix> = Matrix::log;
346const _: fn(&Matrix) -> Result<Matrix> = crate::matrix::sqrt;
347const _: fn(&Matrix) -> Result<Matrix> = Matrix::sqrt;
348const _: fn(&Matrix, f32) -> Result<Matrix> = crate::matrix::pow;
349const _: fn(&Matrix, f32) -> Result<Matrix> = Matrix::pow;
350const _: fn(&Matrix, f32) -> Result<Matrix> = crate::matrix::add_scalar;
351const _: fn(&Matrix, f32) -> Result<Matrix> = Matrix::add_scalar;
352const _: fn(&Matrix, f32) -> Result<Matrix> = crate::matrix::sub_scalar;
353const _: fn(&Matrix, f32) -> Result<Matrix> = Matrix::sub_scalar;
354const _: fn(&Matrix, f32) -> Result<Matrix> = crate::matrix::div_scalar;
355const _: fn(&Matrix, f32) -> Result<Matrix> = Matrix::div_scalar;
356const _: fn(&Matrix) -> Result<Matrix> = crate::matrix::exp;
357const _: fn(&Matrix) -> Result<Matrix> = Matrix::exp;
358const _: fn(&Matrix) -> Result<Matrix> = crate::matrix::sin;
359const _: fn(&Matrix) -> Result<Matrix> = Matrix::sin;
360const _: fn(&Matrix) -> Result<Matrix> = crate::matrix::cos;
361const _: fn(&Matrix) -> Result<Matrix> = Matrix::cos;
362const _: fn(&Matrix) -> Result<Matrix> = crate::matrix::reciprocal;
363const _: fn(&Matrix) -> Result<Matrix> = Matrix::reciprocal;
364const _: fn(&Matrix, f32) -> Result<Matrix> = crate::matrix::clamp_max;
365const _: fn(&Matrix, f32) -> Result<Matrix> = Matrix::clamp_max;
366const _: fn(&Matrix, f32) -> Result<Matrix> = crate::matrix::clamp_min;
367const _: fn(&Matrix, f32) -> Result<Matrix> = Matrix::clamp_min;
368const _: fn(&Matrix) -> Result<Matrix> = crate::matrix::copy;
369const _: fn(&Matrix) -> Result<Matrix> = Matrix::copy;
370const _: fn(&Matrix, &Matrix) -> Result<Matrix> = crate::matrix::mat_mul_nt;
371const _: fn(&Matrix, &Matrix) -> Result<Matrix> = Matrix::mat_mul_nt;
372const _: fn(&Matrix, i32) -> Result<Matrix> = crate::matrix::softmax;
373const _: fn(&Matrix, i32) -> Result<Matrix> = Matrix::softmax;
374const _: fn(&Matrix, i32) -> Result<Matrix> = crate::matrix::log_softmax;
375const _: fn(&Matrix, i32) -> Result<Matrix> = Matrix::log_softmax;
376const _: fn(&Matrix, i32) -> Result<Matrix> = crate::matrix::sum;
377const _: fn(&Matrix, i32) -> Result<Matrix> = Matrix::sum;
378const _: fn(&Matrix, i32) -> Result<Matrix> = crate::matrix::mean;
379const _: fn(&Matrix, i32) -> Result<Matrix> = Matrix::mean;
380const _: fn(&Matrix, i32) -> Result<Matrix> = crate::matrix::max;
381const _: fn(&Matrix, i32) -> Result<Matrix> = Matrix::max;
382const _: fn(&Matrix, i32) -> Result<i64> = crate::matrix::argmax;
383const _: fn(&Matrix, i32) -> Result<i64> = Matrix::argmax;
384const _: fn(&Matrix, &Matrix) -> Result<Matrix> = crate::matrix::categorical_accuracy_count;
385const _: fn(&Matrix, &Matrix) -> Result<Matrix> = Matrix::categorical_accuracy_count;
386const _: fn(&Matrix, &Matrix, &Matrix) -> Result<Matrix> =
387	crate::matrix::masked_categorical_accuracy_count;
388const _: fn(&Matrix, &Matrix, &Matrix) -> Result<Matrix> =
389	Matrix::masked_categorical_accuracy_count;
390const _: fn(&Matrix, f32, f32, u64) -> Result<Matrix> = crate::matrix::philox_uniform;
391const _: fn(&Matrix, f32, f32, u64) -> Result<Matrix> = Matrix::philox_uniform;
392const _: fn(&Matrix, f32, f32, u64) -> Result<Matrix> = crate::matrix::philox_normal;
393const _: fn(&Matrix, f32, f32, u64) -> Result<Matrix> = Matrix::philox_normal;
394const _: fn(&Matrix, f32, u64) -> Result<Matrix> = crate::matrix::dropout;
395const _: fn(&Matrix, f32, u64) -> Result<Matrix> = Matrix::dropout;
396const _: fn(&Matrix, f32, i32, f32, u64) -> Result<Matrix> = crate::matrix::sample_logits;
397const _: fn(&Matrix, f32, i32, f32, u64) -> Result<Matrix> = Matrix::sample_logits;
398const _: fn(&Matrix, i32, i32) -> Result<TopKResult> = crate::matrix::top_k;
399const _: fn(&Matrix, i32, i32) -> Result<TopKResult> = Matrix::top_k;
400const _: fn(&Matrix, usize) -> Result<Matrix> = crate::matrix::top_k_mask;
401const _: fn(&Matrix, usize) -> Result<Matrix> = Matrix::top_k_mask;
402const _: fn(&Matrix, usize) -> Result<MoeExpertPlan> = crate::matrix::moe_expert_plan;
403const _: fn(&Matrix, usize) -> Result<MoeExpertPlan> = Matrix::moe_expert_plan;
404const _: fn(&Matrix, &Matrix, usize, f32) -> Result<()> = crate::matrix::moe_routing_bias_update;
405const _: fn(&Matrix, &Matrix, usize, f32) -> Result<()> = Matrix::moe_routing_bias_update;
406const _: fn(&Matrix, i32, i64, i64) -> Result<Matrix> = crate::matrix::slice;
407const _: fn(&Matrix, i32, i64, i64) -> Result<Matrix> = Matrix::slice;
408const _: fn(&Matrix, &[usize], PadMode, f32) -> Result<Matrix> = crate::matrix::pad;
409const _: fn(&Matrix, &[usize], PadMode, f32) -> Result<Matrix> = Matrix::pad;
410const _: fn(&Matrix, usize, i32) -> Result<Matrix> = crate::matrix::repeat_interleave;
411const _: fn(&Matrix, usize, i32) -> Result<Matrix> = Matrix::repeat_interleave;
412const _: fn(&Matrix, &Matrix) -> Result<Matrix> = crate::matrix::gather;
413const _: fn(&Matrix, &Matrix) -> Result<Matrix> = Matrix::gather;
414const _: fn(&Matrix, &Matrix) -> Result<Matrix> = crate::matrix::gather_last_dim;
415const _: fn(&Matrix, &Matrix) -> Result<Matrix> = Matrix::gather_last_dim;
416const _: fn(&Matrix, i32, i32) -> Result<Matrix> = crate::matrix::transpose;
417const _: fn(&Matrix, i32, i32) -> Result<Matrix> = Matrix::transpose;
418const _: fn(&Matrix, f32) -> Result<Matrix> = crate::matrix::equal;
419const _: fn(&Matrix, f32) -> Result<Matrix> = Matrix::equal;
420const _: fn(&Matrix) -> Result<Matrix> = crate::matrix::causal_mask;
421const _: fn(&Matrix) -> Result<Matrix> = Matrix::causal_mask;
422const _: fn(&Matrix, f32) -> Result<Matrix> = crate::matrix::greater_equal;
423const _: fn(&Matrix, f32) -> Result<Matrix> = Matrix::greater_equal;
424const _: fn(&Matrix, &[i64], i32) -> Result<Vec<Matrix>> = crate::matrix::split;
425const _: fn(&Matrix, &[i64], i32) -> Result<Vec<Matrix>> = Matrix::split;
426const _: fn(&Matrix, &Matrix) -> Result<CompactRowsResult> = crate::matrix::compact_rows;
427const _: fn(&Matrix, &Matrix) -> Result<CompactRowsResult> = Matrix::compact_rows;
428const _: fn(&Matrix, &Matrix, &Matrix, &Matrix) -> Result<Matrix> = crate::matrix::scatter_rows;
429const _: fn(&Matrix, &Matrix, &Matrix, &Matrix) -> Result<Matrix> = Matrix::scatter_rows;
430const _: fn(&Matrix, &Matrix, &CompactRowsResult) -> Result<Matrix> =
431	crate::matrix::scatter_rows_indirect;
432const _: fn(&Matrix, &Matrix, &CompactRowsResult) -> Result<Matrix> = Matrix::scatter_rows_indirect;
433const _: fn(&Matrix) -> Result<Matrix> = crate::matrix::cast_f32_i32;
434const _: fn(&Matrix) -> Result<Matrix> = Matrix::cast_f32_i32;
435const _: fn(&Matrix) -> Result<Matrix> = crate::matrix::cast_i32_f32;
436const _: fn(&Matrix) -> Result<Matrix> = Matrix::cast_i32_f32;