1use tenferro_extension_macros::api_ops;
11
12api_ops! {
13 family: core;
14
15 layer concrete {
16 trait_doc: "Core tensor operations on anything that implements `AsView`: owned and borrowed tensors, typed tensors and strided views. Results are `Tensor`s for erased inputs and typed tensors for typed inputs. Axes are signed (`-1` is the last axis); the engine is always the last argument.";
17 trait_def: pub trait CoreOps: tenferro_tensor::AsView;
18 impl_def: impl<X: tenferro_tensor::AsView + ?Sized> CoreOps for X;
19 method_where: [Self::Repr: crate::CoreRepr];
20 receiver: self;
21 tensor_arg: &impl tenferro_tensor::AsView<Repr = Self::Repr>;
22 exec: &mut dyn tenferro_tensor::Engine;
23 dest: tenferro_tensor::Dest<<Self::Repr as tenferro_tensor::Repr>::Write<'_>>;
24 result: tenferro_tensor::Result;
25 types {
26 V = <Self::Repr as tenferro_tensor::Repr>::Value,
27 R = <Self::Repr as crate::CoreRepr>::Real,
28 B = <Self::Repr as crate::CoreRepr>::Bool
29 }
30 forward: crate::api::concrete;
31 }
32 layer traced { describe_only; }
33 layer eager { describe_only; }
34
35 op exp {
36 summary: "Elementwise exponential.";
37 operands: (a);
38 options: none;
39 output: V;
40 dtypes: "f32, f64, Complex32 or Complex64; the result has the input dtype.";
41 layers: [concrete, traced, eager];
42 into: [];
43 layout: "Every operand is read through `TensorRead` by the engine's `*_read` entry: owned, borrowed, typed and strided inputs reach the same body. Implicit broadcasting is a zero-stride view, never a copy. Whether a strided or negative-stride view is read in place or gathered once (same placement and dtype) is the engine's documented choice for that kernel.";
44 errors: [Validation, Unsupported];
45 omissions: [];
46 example concrete: r#"use tenferro_cpu::CpuEngine;
47use tenferro_runtime::CoreOps;
48use tenferro_tensor::{Tensor};
49
50let mut engine = CpuEngine::serial();
51let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
52let y = a.exp(&mut engine)?;
53assert_eq!(y.shape(), &[2, 2]);
54# Ok::<(), Box<dyn std::error::Error>>(())"#;
55 }
56 op neg {
57 summary: "Elementwise negation.";
58 operands: (a);
59 options: none;
60 output: V;
61 dtypes: "Any numeric dtype the engine supports for the operation; the result has the input dtype.";
62 layers: [concrete, traced, eager];
63 into: [];
64 layout: "Every operand is read through `TensorRead` by the engine's `*_read` entry: owned, borrowed, typed and strided inputs reach the same body. Implicit broadcasting is a zero-stride view, never a copy. Whether a strided or negative-stride view is read in place or gathered once (same placement and dtype) is the engine's documented choice for that kernel.";
65 errors: [Validation, Unsupported];
66 omissions: [];
67 example concrete: r#"use tenferro_cpu::CpuEngine;
68use tenferro_runtime::CoreOps;
69use tenferro_tensor::{Tensor};
70
71let mut engine = CpuEngine::serial();
72let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
73let y = a.neg(&mut engine)?;
74assert_eq!(y.shape(), &[2, 2]);
75# Ok::<(), Box<dyn std::error::Error>>(())"#;
76 }
77 op sign {
78 summary: "Elementwise sign.";
79 operands: (a);
80 options: none;
81 output: V;
82 dtypes: "Any numeric dtype the engine supports for the operation; the result has the input dtype.";
83 layers: [concrete, traced, eager];
84 into: [];
85 layout: "Every operand is read through `TensorRead` by the engine's `*_read` entry: owned, borrowed, typed and strided inputs reach the same body. Implicit broadcasting is a zero-stride view, never a copy. Whether a strided or negative-stride view is read in place or gathered once (same placement and dtype) is the engine's documented choice for that kernel.";
86 errors: [Validation, Unsupported];
87 omissions: [];
88 example concrete: r#"use tenferro_cpu::CpuEngine;
89use tenferro_runtime::CoreOps;
90use tenferro_tensor::{Tensor};
91
92let mut engine = CpuEngine::serial();
93let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
94let y = a.sign(&mut engine)?;
95assert_eq!(y.shape(), &[2, 2]);
96# Ok::<(), Box<dyn std::error::Error>>(())"#;
97 }
98 op conj {
99 summary: "Elementwise complex conjugate (identity on real dtypes).";
100 operands: (a);
101 options: none;
102 output: V;
103 dtypes: "f32, f64, Complex32 or Complex64; the result has the input dtype.";
104 layers: [concrete, traced, eager];
105 into: [];
106 layout: "Every operand is read through `TensorRead` by the engine's `*_read` entry: owned, borrowed, typed and strided inputs reach the same body. Implicit broadcasting is a zero-stride view, never a copy. Whether a strided or negative-stride view is read in place or gathered once (same placement and dtype) is the engine's documented choice for that kernel.";
107 errors: [Validation, Unsupported];
108 omissions: [];
109 example concrete: r#"use tenferro_cpu::CpuEngine;
110use tenferro_runtime::CoreOps;
111use tenferro_tensor::{Tensor};
112
113let mut engine = CpuEngine::serial();
114let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
115let y = a.conj(&mut engine)?;
116assert_eq!(y.shape(), &[2, 2]);
117# Ok::<(), Box<dyn std::error::Error>>(())"#;
118 }
119 op log {
120 summary: "Elementwise natural logarithm.";
121 operands: (a);
122 options: none;
123 output: V;
124 dtypes: "f32, f64, Complex32 or Complex64; the result has the input dtype.";
125 layers: [concrete, traced, eager];
126 into: [];
127 layout: "Every operand is read through `TensorRead` by the engine's `*_read` entry: owned, borrowed, typed and strided inputs reach the same body. Implicit broadcasting is a zero-stride view, never a copy. Whether a strided or negative-stride view is read in place or gathered once (same placement and dtype) is the engine's documented choice for that kernel.";
128 errors: [Validation, Unsupported];
129 omissions: [];
130 example concrete: r#"use tenferro_cpu::CpuEngine;
131use tenferro_runtime::CoreOps;
132use tenferro_tensor::{Tensor};
133
134let mut engine = CpuEngine::serial();
135let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
136let y = a.log(&mut engine)?;
137assert_eq!(y.shape(), &[2, 2]);
138# Ok::<(), Box<dyn std::error::Error>>(())"#;
139 }
140 op expm1 {
141 summary: "Elementwise `exp(x) - 1`.";
142 operands: (a);
143 options: none;
144 output: V;
145 dtypes: "f32, f64, Complex32 or Complex64; the result has the input dtype.";
146 layers: [concrete, traced, eager];
147 into: [];
148 layout: "Every operand is read through `TensorRead` by the engine's `*_read` entry: owned, borrowed, typed and strided inputs reach the same body. Implicit broadcasting is a zero-stride view, never a copy. Whether a strided or negative-stride view is read in place or gathered once (same placement and dtype) is the engine's documented choice for that kernel.";
149 errors: [Validation, Unsupported];
150 omissions: [];
151 example concrete: r#"use tenferro_cpu::CpuEngine;
152use tenferro_runtime::CoreOps;
153use tenferro_tensor::{Tensor};
154
155let mut engine = CpuEngine::serial();
156let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
157let y = a.expm1(&mut engine)?;
158assert_eq!(y.shape(), &[2, 2]);
159# Ok::<(), Box<dyn std::error::Error>>(())"#;
160 }
161 op log1p {
162 summary: "Elementwise `log(1 + x)`.";
163 operands: (a);
164 options: none;
165 output: V;
166 dtypes: "f32, f64, Complex32 or Complex64; the result has the input dtype.";
167 layers: [concrete, traced, eager];
168 into: [];
169 layout: "Every operand is read through `TensorRead` by the engine's `*_read` entry: owned, borrowed, typed and strided inputs reach the same body. Implicit broadcasting is a zero-stride view, never a copy. Whether a strided or negative-stride view is read in place or gathered once (same placement and dtype) is the engine's documented choice for that kernel.";
170 errors: [Validation, Unsupported];
171 omissions: [];
172 example concrete: r#"use tenferro_cpu::CpuEngine;
173use tenferro_runtime::CoreOps;
174use tenferro_tensor::{Tensor};
175
176let mut engine = CpuEngine::serial();
177let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
178let y = a.log1p(&mut engine)?;
179assert_eq!(y.shape(), &[2, 2]);
180# Ok::<(), Box<dyn std::error::Error>>(())"#;
181 }
182 op erf {
183 summary: "Elementwise error function.";
184 operands: (a);
185 options: none;
186 output: V;
187 dtypes: "f32, f64, Complex32 or Complex64; the result has the input dtype.";
188 layers: [concrete, traced, eager];
189 into: [];
190 layout: "Every operand is read through `TensorRead` by the engine's `*_read` entry: owned, borrowed, typed and strided inputs reach the same body. Implicit broadcasting is a zero-stride view, never a copy. Whether a strided or negative-stride view is read in place or gathered once (same placement and dtype) is the engine's documented choice for that kernel.";
191 errors: [Validation, Unsupported];
192 omissions: [];
193 example concrete: r#"use tenferro_cpu::CpuEngine;
194use tenferro_runtime::CoreOps;
195use tenferro_tensor::{Tensor};
196
197let mut engine = CpuEngine::serial();
198let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
199let y = a.erf(&mut engine)?;
200assert_eq!(y.shape(), &[2, 2]);
201# Ok::<(), Box<dyn std::error::Error>>(())"#;
202 }
203 op sin {
204 summary: "Elementwise sine.";
205 operands: (a);
206 options: none;
207 output: V;
208 dtypes: "f32, f64, Complex32 or Complex64; the result has the input dtype.";
209 layers: [concrete, traced, eager];
210 into: [];
211 layout: "Every operand is read through `TensorRead` by the engine's `*_read` entry: owned, borrowed, typed and strided inputs reach the same body. Implicit broadcasting is a zero-stride view, never a copy. Whether a strided or negative-stride view is read in place or gathered once (same placement and dtype) is the engine's documented choice for that kernel.";
212 errors: [Validation, Unsupported];
213 omissions: [];
214 example concrete: r#"use tenferro_cpu::CpuEngine;
215use tenferro_runtime::CoreOps;
216use tenferro_tensor::{Tensor};
217
218let mut engine = CpuEngine::serial();
219let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
220let y = a.sin(&mut engine)?;
221assert_eq!(y.shape(), &[2, 2]);
222# Ok::<(), Box<dyn std::error::Error>>(())"#;
223 }
224 op cos {
225 summary: "Elementwise cosine.";
226 operands: (a);
227 options: none;
228 output: V;
229 dtypes: "f32, f64, Complex32 or Complex64; the result has the input dtype.";
230 layers: [concrete, traced, eager];
231 into: [];
232 layout: "Every operand is read through `TensorRead` by the engine's `*_read` entry: owned, borrowed, typed and strided inputs reach the same body. Implicit broadcasting is a zero-stride view, never a copy. Whether a strided or negative-stride view is read in place or gathered once (same placement and dtype) is the engine's documented choice for that kernel.";
233 errors: [Validation, Unsupported];
234 omissions: [];
235 example concrete: r#"use tenferro_cpu::CpuEngine;
236use tenferro_runtime::CoreOps;
237use tenferro_tensor::{Tensor};
238
239let mut engine = CpuEngine::serial();
240let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
241let y = a.cos(&mut engine)?;
242assert_eq!(y.shape(), &[2, 2]);
243# Ok::<(), Box<dyn std::error::Error>>(())"#;
244 }
245 op tanh {
246 summary: "Elementwise hyperbolic tangent.";
247 operands: (a);
248 options: none;
249 output: V;
250 dtypes: "f32, f64, Complex32 or Complex64; the result has the input dtype.";
251 layers: [concrete, traced, eager];
252 into: [];
253 layout: "Every operand is read through `TensorRead` by the engine's `*_read` entry: owned, borrowed, typed and strided inputs reach the same body. Implicit broadcasting is a zero-stride view, never a copy. Whether a strided or negative-stride view is read in place or gathered once (same placement and dtype) is the engine's documented choice for that kernel.";
254 errors: [Validation, Unsupported];
255 omissions: [];
256 example concrete: r#"use tenferro_cpu::CpuEngine;
257use tenferro_runtime::CoreOps;
258use tenferro_tensor::{Tensor};
259
260let mut engine = CpuEngine::serial();
261let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
262let y = a.tanh(&mut engine)?;
263assert_eq!(y.shape(), &[2, 2]);
264# Ok::<(), Box<dyn std::error::Error>>(())"#;
265 }
266 op sqrt {
267 summary: "Elementwise square root.";
268 operands: (a);
269 options: none;
270 output: V;
271 dtypes: "f32, f64, Complex32 or Complex64; the result has the input dtype.";
272 layers: [concrete, traced, eager];
273 into: [];
274 layout: "Every operand is read through `TensorRead` by the engine's `*_read` entry: owned, borrowed, typed and strided inputs reach the same body. Implicit broadcasting is a zero-stride view, never a copy. Whether a strided or negative-stride view is read in place or gathered once (same placement and dtype) is the engine's documented choice for that kernel.";
275 errors: [Validation, Unsupported];
276 omissions: [];
277 example concrete: r#"use tenferro_cpu::CpuEngine;
278use tenferro_runtime::CoreOps;
279use tenferro_tensor::{Tensor};
280
281let mut engine = CpuEngine::serial();
282let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
283let y = a.sqrt(&mut engine)?;
284assert_eq!(y.shape(), &[2, 2]);
285# Ok::<(), Box<dyn std::error::Error>>(())"#;
286 }
287 op rsqrt {
288 summary: "Elementwise reciprocal square root.";
289 operands: (a);
290 options: none;
291 output: V;
292 dtypes: "f32, f64, Complex32 or Complex64; the result has the input dtype.";
293 layers: [concrete, traced, eager];
294 into: [];
295 layout: "Every operand is read through `TensorRead` by the engine's `*_read` entry: owned, borrowed, typed and strided inputs reach the same body. Implicit broadcasting is a zero-stride view, never a copy. Whether a strided or negative-stride view is read in place or gathered once (same placement and dtype) is the engine's documented choice for that kernel.";
296 errors: [Validation, Unsupported];
297 omissions: [];
298 example concrete: r#"use tenferro_cpu::CpuEngine;
299use tenferro_runtime::CoreOps;
300use tenferro_tensor::{Tensor};
301
302let mut engine = CpuEngine::serial();
303let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
304let y = a.rsqrt(&mut engine)?;
305assert_eq!(y.shape(), &[2, 2]);
306# Ok::<(), Box<dyn std::error::Error>>(())"#;
307 }
308 op abs {
309 summary: "Elementwise absolute value; complex inputs return their modulus.";
310 operands: (a);
311 options: none;
312 output: R;
313 dtypes: "Any numeric dtype; complex inputs return the real dtype of the same precision.";
314 layers: [concrete, traced, eager];
315 into: [];
316 layout: "Every operand is read through `TensorRead` by the engine's `*_read` entry: owned, borrowed, typed and strided inputs reach the same body. Implicit broadcasting is a zero-stride view, never a copy. Whether a strided or negative-stride view is read in place or gathered once (same placement and dtype) is the engine's documented choice for that kernel.";
317 errors: [Validation, Unsupported];
318 omissions: [];
319 example concrete: r#"use tenferro_cpu::CpuEngine;
320use tenferro_runtime::CoreOps;
321use tenferro_tensor::{Tensor};
322
323let mut engine = CpuEngine::serial();
324let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
325let y = a.abs(&mut engine)?;
326assert_eq!(y.shape(), &[2, 2]);
327# Ok::<(), Box<dyn std::error::Error>>(())"#;
328 }
329 op sigmoid {
330 summary: "Logistic sigmoid.";
331 operands: (a);
332 options: none;
333 output: V;
334 dtypes: "f32 or f64.";
335 layers: [concrete, traced, eager];
336 into: [];
337 layout: "Composed from core primitives inside the engine; operands are read through `TensorRead` and intermediates are engine allocations. A fused engine kernel is used when the engine offers one.";
338 errors: [Validation, Unsupported];
339 omissions: [];
340 example concrete: r#"use tenferro_cpu::CpuEngine;
341use tenferro_runtime::CoreOps;
342use tenferro_tensor::{Tensor};
343
344let mut engine = CpuEngine::serial();
345let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
346let y = a.sigmoid(&mut engine)?;
347assert_eq!(y.shape(), &[2, 2]);
348# Ok::<(), Box<dyn std::error::Error>>(())"#;
349 }
350 op silu {
351 summary: "SiLU (`x * sigmoid(x)`).";
352 operands: (a);
353 options: none;
354 output: V;
355 dtypes: "f32 or f64.";
356 layers: [concrete, traced, eager];
357 into: [];
358 layout: "Composed from core primitives inside the engine; operands are read through `TensorRead` and intermediates are engine allocations. A fused engine kernel is used when the engine offers one.";
359 errors: [Validation, Unsupported];
360 omissions: [];
361 example concrete: r#"use tenferro_cpu::CpuEngine;
362use tenferro_runtime::CoreOps;
363use tenferro_tensor::{Tensor};
364
365let mut engine = CpuEngine::serial();
366let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
367let y = a.silu(&mut engine)?;
368assert_eq!(y.shape(), &[2, 2]);
369# Ok::<(), Box<dyn std::error::Error>>(())"#;
370 }
371 op softplus {
372 summary: "Softplus `log(1 + exp(x))`.";
373 operands: (a);
374 options: none;
375 output: V;
376 dtypes: "f32 or f64.";
377 layers: [concrete, traced, eager];
378 into: [];
379 layout: "Composed from core primitives inside the engine; operands are read through `TensorRead` and intermediates are engine allocations. A fused engine kernel is used when the engine offers one.";
380 errors: [Validation, Unsupported];
381 omissions: [];
382 example concrete: r#"use tenferro_cpu::CpuEngine;
383use tenferro_runtime::CoreOps;
384use tenferro_tensor::{Tensor};
385
386let mut engine = CpuEngine::serial();
387let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
388let y = a.softplus(&mut engine)?;
389assert_eq!(y.shape(), &[2, 2]);
390# Ok::<(), Box<dyn std::error::Error>>(())"#;
391 }
392 op gelu {
393 summary: "GELU with the exact error function.";
394 operands: (a);
395 options: none;
396 output: V;
397 dtypes: "f32 or f64.";
398 layers: [concrete, traced, eager];
399 into: [];
400 layout: "Composed from core primitives inside the engine; operands are read through `TensorRead` and intermediates are engine allocations. A fused engine kernel is used when the engine offers one.";
401 errors: [Validation, Unsupported];
402 omissions: [];
403 example concrete: r#"use tenferro_cpu::CpuEngine;
404use tenferro_runtime::CoreOps;
405use tenferro_tensor::{Tensor};
406
407let mut engine = CpuEngine::serial();
408let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
409let y = a.gelu(&mut engine)?;
410assert_eq!(y.shape(), &[2, 2]);
411# Ok::<(), Box<dyn std::error::Error>>(())"#;
412 }
413 op gelu_tanh {
414 summary: "GELU with the tanh approximation.";
415 operands: (a);
416 options: none;
417 output: V;
418 dtypes: "f32 or f64.";
419 layers: [concrete, traced, eager];
420 into: [];
421 layout: "Composed from core primitives inside the engine; operands are read through `TensorRead` and intermediates are engine allocations. A fused engine kernel is used when the engine offers one.";
422 errors: [Validation, Unsupported];
423 omissions: [];
424 example concrete: r#"use tenferro_cpu::CpuEngine;
425use tenferro_runtime::CoreOps;
426use tenferro_tensor::{Tensor};
427
428let mut engine = CpuEngine::serial();
429let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
430let y = a.gelu_tanh(&mut engine)?;
431assert_eq!(y.shape(), &[2, 2]);
432# Ok::<(), Box<dyn std::error::Error>>(())"#;
433 }
434 op mul {
435 summary: "Elementwise product with broadcasting.";
436 operands: (a, b);
437 options: none;
438 output: V;
439 dtypes: "Both operands share a numeric dtype; the result has that dtype.";
440 layers: [concrete, traced, eager];
441 into: [];
442 layout: "Every operand is read through `TensorRead` by the engine's `*_read` entry: owned, borrowed, typed and strided inputs reach the same body. Implicit broadcasting is a zero-stride view, never a copy. Whether a strided or negative-stride view is read in place or gathered once (same placement and dtype) is the engine's documented choice for that kernel.";
443 errors: [Validation, Unsupported];
444 omissions: [];
445 example concrete: r#"use tenferro_cpu::CpuEngine;
446use tenferro_runtime::CoreOps;
447use tenferro_tensor::{Tensor};
448
449let mut engine = CpuEngine::serial();
450let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
451let y = a.mul(&a, &mut engine)?;
452assert_eq!(y.shape(), &[2, 2]);
453# Ok::<(), Box<dyn std::error::Error>>(())"#;
454 }
455 op sub {
456 summary: "Elementwise difference with broadcasting.";
457 operands: (a, b);
458 options: none;
459 output: V;
460 dtypes: "Both operands share a numeric dtype; the result has that dtype.";
461 layers: [concrete, traced, eager];
462 into: [];
463 layout: "Every operand is read through `TensorRead` by the engine's `*_read` entry: owned, borrowed, typed and strided inputs reach the same body. Implicit broadcasting is a zero-stride view, never a copy. Whether a strided or negative-stride view is read in place or gathered once (same placement and dtype) is the engine's documented choice for that kernel.";
464 errors: [Validation, Unsupported];
465 omissions: [];
466 example concrete: r#"use tenferro_cpu::CpuEngine;
467use tenferro_runtime::CoreOps;
468use tenferro_tensor::{Tensor};
469
470let mut engine = CpuEngine::serial();
471let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
472let y = a.sub(&a, &mut engine)?;
473assert_eq!(y.shape(), &[2, 2]);
474# Ok::<(), Box<dyn std::error::Error>>(())"#;
475 }
476 op div {
477 summary: "Elementwise quotient with broadcasting.";
478 operands: (a, b);
479 options: none;
480 output: V;
481 dtypes: "Both operands share a numeric dtype; the result has that dtype.";
482 layers: [concrete, traced, eager];
483 into: [];
484 layout: "Every operand is read through `TensorRead` by the engine's `*_read` entry: owned, borrowed, typed and strided inputs reach the same body. Implicit broadcasting is a zero-stride view, never a copy. Whether a strided or negative-stride view is read in place or gathered once (same placement and dtype) is the engine's documented choice for that kernel.";
485 errors: [Validation, Unsupported];
486 omissions: [];
487 example concrete: r#"use tenferro_cpu::CpuEngine;
488use tenferro_runtime::CoreOps;
489use tenferro_tensor::{Tensor};
490
491let mut engine = CpuEngine::serial();
492let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
493let y = a.div(&a, &mut engine)?;
494assert_eq!(y.shape(), &[2, 2]);
495# Ok::<(), Box<dyn std::error::Error>>(())"#;
496 }
497 op rem {
498 summary: "Elementwise remainder with broadcasting.";
499 operands: (a, b);
500 options: none;
501 output: V;
502 dtypes: "Both operands share a numeric dtype; the result has that dtype.";
503 layers: [concrete, traced, eager];
504 into: [];
505 layout: "Every operand is read through `TensorRead` by the engine's `*_read` entry: owned, borrowed, typed and strided inputs reach the same body. Implicit broadcasting is a zero-stride view, never a copy. Whether a strided or negative-stride view is read in place or gathered once (same placement and dtype) is the engine's documented choice for that kernel.";
506 errors: [Validation, Unsupported];
507 omissions: [];
508 example concrete: r#"use tenferro_cpu::CpuEngine;
509use tenferro_runtime::CoreOps;
510use tenferro_tensor::{Tensor};
511
512let mut engine = CpuEngine::serial();
513let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
514let y = a.rem(&a, &mut engine)?;
515assert_eq!(y.shape(), &[2, 2]);
516# Ok::<(), Box<dyn std::error::Error>>(())"#;
517 }
518 op pow {
519 summary: "Elementwise power with broadcasting.";
520 operands: (a, b);
521 options: none;
522 output: V;
523 dtypes: "Both operands share a numeric dtype; the result has that dtype.";
524 layers: [concrete, traced, eager];
525 into: [];
526 layout: "Every operand is read through `TensorRead` by the engine's `*_read` entry: owned, borrowed, typed and strided inputs reach the same body. Implicit broadcasting is a zero-stride view, never a copy. Whether a strided or negative-stride view is read in place or gathered once (same placement and dtype) is the engine's documented choice for that kernel.";
527 errors: [Validation, Unsupported];
528 omissions: [];
529 example concrete: r#"use tenferro_cpu::CpuEngine;
530use tenferro_runtime::CoreOps;
531use tenferro_tensor::{Tensor};
532
533let mut engine = CpuEngine::serial();
534let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
535let y = a.pow(&a, &mut engine)?;
536assert_eq!(y.shape(), &[2, 2]);
537# Ok::<(), Box<dyn std::error::Error>>(())"#;
538 }
539 op maximum {
540 summary: "Elementwise maximum with broadcasting.";
541 operands: (a, b);
542 options: none;
543 output: V;
544 dtypes: "Both operands share a numeric dtype; the result has that dtype.";
545 layers: [concrete, traced, eager];
546 into: [];
547 layout: "Every operand is read through `TensorRead` by the engine's `*_read` entry: owned, borrowed, typed and strided inputs reach the same body. Implicit broadcasting is a zero-stride view, never a copy. Whether a strided or negative-stride view is read in place or gathered once (same placement and dtype) is the engine's documented choice for that kernel.";
548 errors: [Validation, Unsupported];
549 omissions: [];
550 example concrete: r#"use tenferro_cpu::CpuEngine;
551use tenferro_runtime::CoreOps;
552use tenferro_tensor::{Tensor};
553
554let mut engine = CpuEngine::serial();
555let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
556let y = a.maximum(&a, &mut engine)?;
557assert_eq!(y.shape(), &[2, 2]);
558# Ok::<(), Box<dyn std::error::Error>>(())"#;
559 }
560 op minimum {
561 summary: "Elementwise minimum with broadcasting.";
562 operands: (a, b);
563 options: none;
564 output: V;
565 dtypes: "Both operands share a numeric dtype; the result has that dtype.";
566 layers: [concrete, traced, eager];
567 into: [];
568 layout: "Every operand is read through `TensorRead` by the engine's `*_read` entry: owned, borrowed, typed and strided inputs reach the same body. Implicit broadcasting is a zero-stride view, never a copy. Whether a strided or negative-stride view is read in place or gathered once (same placement and dtype) is the engine's documented choice for that kernel.";
569 errors: [Validation, Unsupported];
570 omissions: [];
571 example concrete: r#"use tenferro_cpu::CpuEngine;
572use tenferro_runtime::CoreOps;
573use tenferro_tensor::{Tensor};
574
575let mut engine = CpuEngine::serial();
576let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
577let y = a.minimum(&a, &mut engine)?;
578assert_eq!(y.shape(), &[2, 2]);
579# Ok::<(), Box<dyn std::error::Error>>(())"#;
580 }
581 op add {
582 summary: "Elementwise sum with broadcasting.";
583 operands: (a, b);
584 options: none;
585 output: V;
586 dtypes: "Both operands share a numeric dtype; the result has that dtype.";
587 layers: [concrete, traced, eager];
588 into: [overwrite];
589 layout: "Every operand is read through `TensorRead` by the engine's `*_read` entry: owned, borrowed, typed and strided inputs reach the same body. Implicit broadcasting is a zero-stride view, never a copy. Whether a strided or negative-stride view is read in place or gathered once (same placement and dtype) is the engine's documented choice for that kernel. `add_into` writes the result into the destination's storage.";
590 errors: [Validation, Unsupported];
591 omissions: ["traced and eager: only `add`; `add_into` exists on the concrete layer"];
592 example concrete: r#"use tenferro_cpu::CpuEngine;
593use tenferro_runtime::CoreOps;
594use tenferro_tensor::{Tensor};
595
596let mut engine = CpuEngine::serial();
597let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
598let y = a.add(&a, &mut engine)?;
599assert_eq!(y.shape(), &[2, 2]);
600# Ok::<(), Box<dyn std::error::Error>>(())"#;
601 }
602 op matmul {
603 summary: "Matrix product of the two leading axes, batched over trailing axes.";
604 operands: (a, b);
605 options: none;
606 output: V;
607 dtypes: "Both operands share a numeric dtype; the result has that dtype.";
608 layers: [concrete, traced, eager];
609 into: [];
610 layout: "Every operand is read through `TensorRead` by the engine's `*_read` entry: owned, borrowed, typed and strided inputs reach the same body. Implicit broadcasting is a zero-stride view, never a copy. Whether a strided or negative-stride view is read in place or gathered once (same placement and dtype) is the engine's documented choice for that kernel.";
611 errors: [Validation, Unsupported];
612 omissions: [];
613 example concrete: r#"use tenferro_cpu::CpuEngine;
614use tenferro_runtime::CoreOps;
615use tenferro_tensor::{Tensor};
616
617let mut engine = CpuEngine::serial();
618let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
619let y = a.matmul(&a, &mut engine)?;
620assert_eq!(y.shape(), &[2, 2]);
621# Ok::<(), Box<dyn std::error::Error>>(())"#;
622 }
623 op compare {
624 summary: "Elementwise comparison with broadcasting; returns a `bool` tensor.";
625 operands: (a, b, dir: tenferro_tensor::CompareDir);
626 options: none;
627 output: B;
628 dtypes: "Both operands share a dtype; the result is `bool`.";
629 layers: [concrete, traced, eager];
630 into: [];
631 layout: "Every operand is read through `TensorRead` by the engine's `*_read` entry: owned, borrowed, typed and strided inputs reach the same body. Implicit broadcasting is a zero-stride view, never a copy. Whether a strided or negative-stride view is read in place or gathered once (same placement and dtype) is the engine's documented choice for that kernel.";
632 errors: [Validation, Unsupported];
633 omissions: [];
634 example concrete: r#"use tenferro_cpu::CpuEngine;
635use tenferro_runtime::CoreOps;
636use tenferro_tensor::{CompareDir, Tensor};
637
638let mut engine = CpuEngine::serial();
639let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
640let y = a.compare(&a, CompareDir::Eq, &mut engine)?;
641assert_eq!(y.shape(), &[2, 2]);
642# Ok::<(), Box<dyn std::error::Error>>(())"#;
643 }
644 op clamp {
645 summary: "Elementwise clamp to `[lower, upper]` with broadcasting.";
646 operands: (a, lower, upper);
647 options: none;
648 output: V;
649 dtypes: "All operands share a real dtype.";
650 layers: [concrete, traced, eager];
651 into: [];
652 layout: "Every operand is read through `TensorRead` by the engine's `*_read` entry: owned, borrowed, typed and strided inputs reach the same body. Implicit broadcasting is a zero-stride view, never a copy. Whether a strided or negative-stride view is read in place or gathered once (same placement and dtype) is the engine's documented choice for that kernel.";
653 errors: [Validation, Unsupported];
654 omissions: [];
655 example concrete: r#"use tenferro_cpu::CpuEngine;
656use tenferro_runtime::CoreOps;
657use tenferro_tensor::{Tensor};
658
659let mut engine = CpuEngine::serial();
660let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
661let y = a.clamp(&a, &a, &mut engine)?;
662assert_eq!(y.shape(), &[2, 2]);
663# Ok::<(), Box<dyn std::error::Error>>(())"#;
664 }
665 op where_select {
666 summary: "Elementwise selection: `on_true` where the receiver is true, `on_false` elsewhere, with broadcasting. The receiver is the `bool` condition; a typed receiver must be `TypedTensor<bool>`.";
667 generics: <Y: crate::SelectOperand<Self::Repr> + ?Sized>;
668 operands: (condition, on_true: &Y, on_false: &impl tenferro_tensor::AsView<Repr = Y::Repr>);
669 options: none;
670 output: <Y::Repr as tenferro_tensor::Repr>::Value;
671 dtypes: "Receiver `bool`; the branches share a dtype, which is the result dtype.";
672 layers: [concrete, traced, eager];
673 into: [];
674 layout: "Every operand is read through `TensorRead` by the engine's `*_read` entry: owned, borrowed, typed and strided inputs reach the same body. Implicit broadcasting is a zero-stride view, never a copy. Whether a strided or negative-stride view is read in place or gathered once (same placement and dtype) is the engine's documented choice for that kernel.";
675 errors: [Validation, Unsupported];
676 omissions: [];
677 example concrete: r#"use tenferro_cpu::CpuEngine;
678use tenferro_runtime::CoreOps;
679use tenferro_tensor::TypedTensor;
680
681let mut engine = CpuEngine::serial();
682let c = TypedTensor::<bool>::from_vec_col_major(vec![2], vec![true, false])?;
683let x = TypedTensor::<f64>::from_vec_col_major(vec![2], vec![1.0, 2.0])?;
684let y = TypedTensor::<f64>::from_vec_col_major(vec![2], vec![3.0, 4.0])?;
685let z = c.where_select(&x, &y, &mut engine)?;
686assert_eq!(z.host_data()?, &[1.0, 4.0]);
687# Ok::<(), Box<dyn std::error::Error>>(())"#;
688 }
689 op dot_general {
690 summary: "General contraction with batch dimensions (`DotGeneralConfig`); `DotGeneralOptions` conjugates an operand.";
691 operands: (a, b, config: tenferro_tensor::DotGeneralConfig);
692 options: tenferro_tensor::DotGeneralOptions;
693 output: V;
694 dtypes: "Both operands share a numeric dtype; the result has that dtype.";
695 layers: [concrete, traced, eager];
696 into: [];
697 layout: "Every operand is read through `TensorRead` by the engine's `*_read` entry: owned, borrowed, typed and strided inputs reach the same body. Implicit broadcasting is a zero-stride view, never a copy. Whether a strided or negative-stride view is read in place or gathered once (same placement and dtype) is the engine's documented choice for that kernel.";
698 errors: [Validation, Unsupported];
699 omissions: ["traced: no `dot_general_with`; conjugate an operand with `conj()` first"];
700 example concrete: r#"use tenferro_cpu::CpuEngine;
701use tenferro_runtime::CoreOps;
702use tenferro_tensor::{DotGeneralConfig, Tensor};
703
704let mut engine = CpuEngine::serial();
705let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
706let cfg = DotGeneralConfig {
707 lhs_contracting_dims: [1usize].into_iter().collect(),
708 rhs_contracting_dims: [0usize].into_iter().collect(),
709 lhs_batch_dims: Default::default(),
710 rhs_batch_dims: Default::default(),
711};
712let y = a.dot_general(&a, cfg, &mut engine)?;
713assert_eq!(y.shape(), &[2, 2]);
714# Ok::<(), Box<dyn std::error::Error>>(())"#;
715 }
716 op reduce_sum {
717 summary: "Sum over `axes` (`None`: every axis); axes are signed, `-1` is the last axis.";
718 operands: (a, axes: Option<&[isize]>);
719 options: none;
720 output: V;
721 dtypes: "Any numeric dtype the engine supports for the operation; the result has the input dtype.";
722 layers: [concrete, traced, eager];
723 into: [];
724 layout: "Every operand is read through `TensorRead` by the engine's `*_read` entry: owned, borrowed, typed and strided inputs reach the same body. Implicit broadcasting is a zero-stride view, never a copy. Whether a strided or negative-stride view is read in place or gathered once (same placement and dtype) is the engine's documented choice for that kernel.";
725 errors: [Validation, Unsupported];
726 omissions: [];
727 example concrete: r#"use tenferro_cpu::CpuEngine;
728use tenferro_runtime::CoreOps;
729use tenferro_tensor::{Tensor};
730
731let mut engine = CpuEngine::serial();
732let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
733let y = a.reduce_sum(Some(&[-1]), &mut engine)?;
734assert_eq!(y.shape(), &[2]);
735# Ok::<(), Box<dyn std::error::Error>>(())"#;
736 }
737 op reduce_max {
738 summary: "Maximum over `axes` (`None`: every axis); axes are signed, `-1` is the last axis.";
739 operands: (a, axes: Option<&[isize]>);
740 options: none;
741 output: V;
742 dtypes: "Any numeric dtype the engine supports for the operation; the result has the input dtype.";
743 layers: [concrete, traced, eager];
744 into: [];
745 layout: "Every operand is read through `TensorRead` by the engine's `*_read` entry: owned, borrowed, typed and strided inputs reach the same body. Implicit broadcasting is a zero-stride view, never a copy. Whether a strided or negative-stride view is read in place or gathered once (same placement and dtype) is the engine's documented choice for that kernel.";
746 errors: [Validation, Unsupported];
747 omissions: [];
748 example concrete: r#"use tenferro_cpu::CpuEngine;
749use tenferro_runtime::CoreOps;
750use tenferro_tensor::{Tensor};
751
752let mut engine = CpuEngine::serial();
753let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
754let y = a.reduce_max(Some(&[-1]), &mut engine)?;
755assert_eq!(y.shape(), &[2]);
756# Ok::<(), Box<dyn std::error::Error>>(())"#;
757 }
758 op reduce_min {
759 summary: "Minimum over `axes` (`None`: every axis); axes are signed, `-1` is the last axis.";
760 operands: (a, axes: Option<&[isize]>);
761 options: none;
762 output: V;
763 dtypes: "Any numeric dtype the engine supports for the operation; the result has the input dtype.";
764 layers: [concrete, traced, eager];
765 into: [];
766 layout: "Every operand is read through `TensorRead` by the engine's `*_read` entry: owned, borrowed, typed and strided inputs reach the same body. Implicit broadcasting is a zero-stride view, never a copy. Whether a strided or negative-stride view is read in place or gathered once (same placement and dtype) is the engine's documented choice for that kernel.";
767 errors: [Validation, Unsupported];
768 omissions: [];
769 example concrete: r#"use tenferro_cpu::CpuEngine;
770use tenferro_runtime::CoreOps;
771use tenferro_tensor::{Tensor};
772
773let mut engine = CpuEngine::serial();
774let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
775let y = a.reduce_min(Some(&[-1]), &mut engine)?;
776assert_eq!(y.shape(), &[2]);
777# Ok::<(), Box<dyn std::error::Error>>(())"#;
778 }
779 op reduce_prod {
780 summary: "Product over `axes` (`None`: every axis); axes are signed, `-1` is the last axis.";
781 operands: (a, axes: Option<&[isize]>);
782 options: none;
783 output: V;
784 dtypes: "Any numeric dtype the engine supports for the operation; the result has the input dtype.";
785 layers: [concrete, traced, eager];
786 into: [];
787 layout: "Every operand is read through `TensorRead` by the engine's `*_read` entry: owned, borrowed, typed and strided inputs reach the same body. Implicit broadcasting is a zero-stride view, never a copy. Whether a strided or negative-stride view is read in place or gathered once (same placement and dtype) is the engine's documented choice for that kernel.";
788 errors: [Validation, Unsupported];
789 omissions: [];
790 example concrete: r#"use tenferro_cpu::CpuEngine;
791use tenferro_runtime::CoreOps;
792use tenferro_tensor::{Tensor};
793
794let mut engine = CpuEngine::serial();
795let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
796let y = a.reduce_prod(Some(&[-1]), &mut engine)?;
797assert_eq!(y.shape(), &[2]);
798# Ok::<(), Box<dyn std::error::Error>>(())"#;
799 }
800 op reduce_sum_squares {
801 summary: "Sum of squared magnitudes over `axes` (`None`: every axis); axes are signed, `-1` is the last axis.";
802 operands: (a, axes: Option<&[isize]>);
803 options: none;
804 output: V;
805 dtypes: "Any numeric dtype the engine supports for the operation; the result has the input dtype.";
806 layers: [concrete, traced, eager];
807 into: [];
808 layout: "Every operand is read through `TensorRead` by the engine's `*_read` entry: owned, borrowed, typed and strided inputs reach the same body. Implicit broadcasting is a zero-stride view, never a copy. Whether a strided or negative-stride view is read in place or gathered once (same placement and dtype) is the engine's documented choice for that kernel.";
809 errors: [Validation, Unsupported];
810 omissions: [];
811 example concrete: r#"use tenferro_cpu::CpuEngine;
812use tenferro_runtime::CoreOps;
813use tenferro_tensor::{Tensor};
814
815let mut engine = CpuEngine::serial();
816let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
817let y = a.reduce_sum_squares(Some(&[-1]), &mut engine)?;
818assert_eq!(y.shape(), &[2]);
819# Ok::<(), Box<dyn std::error::Error>>(())"#;
820 }
821 op reduce_mean {
822 summary: "Mean over `axes` (`None`: every axis); axes are signed, `-1` is the last axis.";
823 operands: (a, axes: Option<&[isize]>);
824 options: none;
825 output: V;
826 dtypes: "Any numeric dtype the engine supports for the operation; the result has the input dtype.";
827 layers: [concrete, traced, eager];
828 into: [];
829 layout: "Composed from core primitives inside the engine; operands are read through `TensorRead` and intermediates are engine allocations. A fused engine kernel is used when the engine offers one.";
830 errors: [Validation, Unsupported];
831 omissions: [];
832 example concrete: r#"use tenferro_cpu::CpuEngine;
833use tenferro_runtime::CoreOps;
834use tenferro_tensor::{Tensor};
835
836let mut engine = CpuEngine::serial();
837let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
838let y = a.reduce_mean(Some(&[-1]), &mut engine)?;
839assert_eq!(y.shape(), &[2]);
840# Ok::<(), Box<dyn std::error::Error>>(())"#;
841 }
842 op reshape {
843 summary: "Reshape to `shape` in column-major element order.";
844 operands: (a, shape: &[usize]);
845 options: none;
846 output: V;
847 dtypes: "Any numeric dtype the engine supports for the operation; the result has the input dtype.";
848 layers: [concrete, traced, eager];
849 into: [];
850 layout: "Every operand is read through `TensorRead` by the engine's `*_read` entry: owned, borrowed, typed and strided inputs reach the same body. Implicit broadcasting is a zero-stride view, never a copy. Whether a strided or negative-stride view is read in place or gathered once (same placement and dtype) is the engine's documented choice for that kernel. A view that is not compact in column-major order is gathered by the engine; reshape is a data operation, not a metadata query.";
851 errors: [Validation, Unsupported];
852 omissions: [];
853 example concrete: r#"use tenferro_cpu::CpuEngine;
854use tenferro_runtime::CoreOps;
855use tenferro_tensor::{Tensor};
856
857let mut engine = CpuEngine::serial();
858let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
859let y = a.reshape(&[4], &mut engine)?;
860assert_eq!(y.shape(), &[4]);
861# Ok::<(), Box<dyn std::error::Error>>(())"#;
862 }
863 op broadcast_in_dim {
864 summary: "Broadcast to `shape`; `dims[i]` is the output axis of input axis `i` (an IR-level dimension map, unsigned like the `*Config` structs).";
865 operands: (a, shape: &[usize], dims: &[usize]);
866 options: none;
867 output: V;
868 dtypes: "Any numeric dtype the engine supports for the operation; the result has the input dtype.";
869 layers: [concrete, traced, eager];
870 into: [];
871 layout: "Every operand is read through `TensorRead` by the engine's `*_read` entry: owned, borrowed, typed and strided inputs reach the same body. Implicit broadcasting is a zero-stride view, never a copy. Whether a strided or negative-stride view is read in place or gathered once (same placement and dtype) is the engine's documented choice for that kernel.";
872 errors: [Validation, Unsupported];
873 omissions: [];
874 example concrete: r#"use tenferro_cpu::CpuEngine;
875use tenferro_runtime::CoreOps;
876use tenferro_tensor::{Tensor};
877
878let mut engine = CpuEngine::serial();
879let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
880let y = a.broadcast_in_dim(&[2, 2, 3], &[0, 1], &mut engine)?;
881assert_eq!(y.shape(), &[2, 2, 3]);
882# Ok::<(), Box<dyn std::error::Error>>(())"#;
883 }
884 op transpose {
885 summary: "Permute axes; `perm` is signed (`-1` is the last axis).";
886 operands: (a, perm: &[isize]);
887 options: none;
888 output: V;
889 dtypes: "Any numeric dtype the engine supports for the operation; the result has the input dtype.";
890 layers: [concrete, traced, eager];
891 into: [];
892 layout: "Every operand is read through `TensorRead` by the engine's `*_read` entry: owned, borrowed, typed and strided inputs reach the same body. Implicit broadcasting is a zero-stride view, never a copy. Whether a strided or negative-stride view is read in place or gathered once (same placement and dtype) is the engine's documented choice for that kernel.";
893 errors: [Validation, Unsupported];
894 omissions: [];
895 example concrete: r#"use tenferro_cpu::CpuEngine;
896use tenferro_runtime::CoreOps;
897use tenferro_tensor::{Tensor};
898
899let mut engine = CpuEngine::serial();
900let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
901let y = a.transpose(&[1, 0], &mut engine)?;
902assert_eq!(y.shape(), &[2, 2]);
903# Ok::<(), Box<dyn std::error::Error>>(())"#;
904 }
905 op reverse {
906 summary: "Reverse the order of elements along `axes` (signed).";
907 operands: (a, axes: &[isize]);
908 options: none;
909 output: V;
910 dtypes: "Any numeric dtype the engine supports for the operation; the result has the input dtype.";
911 layers: [concrete, traced, eager];
912 into: [];
913 layout: "Every operand is read through `TensorRead` by the engine's `*_read` entry: owned, borrowed, typed and strided inputs reach the same body. Implicit broadcasting is a zero-stride view, never a copy. Whether a strided or negative-stride view is read in place or gathered once (same placement and dtype) is the engine's documented choice for that kernel.";
914 errors: [Validation, Unsupported];
915 omissions: [];
916 example concrete: r#"use tenferro_cpu::CpuEngine;
917use tenferro_runtime::CoreOps;
918use tenferro_tensor::{Tensor};
919
920let mut engine = CpuEngine::serial();
921let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
922let y = a.reverse(&[-1], &mut engine)?;
923assert_eq!(y.shape(), &[2, 2]);
924# Ok::<(), Box<dyn std::error::Error>>(())"#;
925 }
926 op tril {
927 summary: "Lower triangle of the two leading axes relative to diagonal `k`.";
928 operands: (a, k: i64);
929 options: none;
930 output: V;
931 dtypes: "Any numeric dtype the engine supports for the operation; the result has the input dtype.";
932 layers: [concrete, traced, eager];
933 into: [];
934 layout: "Every operand is read through `TensorRead` by the engine's `*_read` entry: owned, borrowed, typed and strided inputs reach the same body. Implicit broadcasting is a zero-stride view, never a copy. Whether a strided or negative-stride view is read in place or gathered once (same placement and dtype) is the engine's documented choice for that kernel.";
935 errors: [Validation, Unsupported];
936 omissions: [];
937 example concrete: r#"use tenferro_cpu::CpuEngine;
938use tenferro_runtime::CoreOps;
939use tenferro_tensor::{Tensor};
940
941let mut engine = CpuEngine::serial();
942let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
943let y = a.tril(0, &mut engine)?;
944assert_eq!(y.shape(), &[2, 2]);
945# Ok::<(), Box<dyn std::error::Error>>(())"#;
946 }
947 op triu {
948 summary: "Upper triangle of the two leading axes relative to diagonal `k`.";
949 operands: (a, k: i64);
950 options: none;
951 output: V;
952 dtypes: "Any numeric dtype the engine supports for the operation; the result has the input dtype.";
953 layers: [concrete, traced, eager];
954 into: [];
955 layout: "Every operand is read through `TensorRead` by the engine's `*_read` entry: owned, borrowed, typed and strided inputs reach the same body. Implicit broadcasting is a zero-stride view, never a copy. Whether a strided or negative-stride view is read in place or gathered once (same placement and dtype) is the engine's documented choice for that kernel.";
956 errors: [Validation, Unsupported];
957 omissions: [];
958 example concrete: r#"use tenferro_cpu::CpuEngine;
959use tenferro_runtime::CoreOps;
960use tenferro_tensor::{Tensor};
961
962let mut engine = CpuEngine::serial();
963let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
964let y = a.triu(0, &mut engine)?;
965assert_eq!(y.shape(), &[2, 2]);
966# Ok::<(), Box<dyn std::error::Error>>(())"#;
967 }
968 op extract_diag {
969 summary: "Extract the diagonal of axes `axis_a` and `axis_b` (signed).";
970 operands: (a, axis_a: isize, axis_b: isize);
971 options: none;
972 output: V;
973 dtypes: "Any numeric dtype the engine supports for the operation; the result has the input dtype.";
974 layers: [concrete, traced, eager];
975 into: [];
976 layout: "Every operand is read through `TensorRead` by the engine's `*_read` entry: owned, borrowed, typed and strided inputs reach the same body. Implicit broadcasting is a zero-stride view, never a copy. Whether a strided or negative-stride view is read in place or gathered once (same placement and dtype) is the engine's documented choice for that kernel.";
977 errors: [Validation, Unsupported];
978 omissions: [];
979 example concrete: r#"use tenferro_cpu::CpuEngine;
980use tenferro_runtime::CoreOps;
981use tenferro_tensor::{Tensor};
982
983let mut engine = CpuEngine::serial();
984let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
985let y = a.extract_diag(0, 1, &mut engine)?;
986assert_eq!(y.shape(), &[2]);
987# Ok::<(), Box<dyn std::error::Error>>(())"#;
988 }
989 op embed_diag {
990 summary: "Embed axis `axis_a` of the receiver as the diagonal of a new axis pair; `axis_b` (signed, against the output rank) is the position of the inserted axis.";
991 operands: (a, axis_a: isize, axis_b: isize);
992 options: none;
993 output: V;
994 dtypes: "Any numeric dtype the engine supports for the operation; the result has the input dtype.";
995 layers: [concrete, traced, eager];
996 into: [];
997 layout: "Every operand is read through `TensorRead` by the engine's `*_read` entry: owned, borrowed, typed and strided inputs reach the same body. Implicit broadcasting is a zero-stride view, never a copy. Whether a strided or negative-stride view is read in place or gathered once (same placement and dtype) is the engine's documented choice for that kernel.";
998 errors: [Validation, Unsupported];
999 omissions: [];
1000 example concrete: r#"use tenferro_cpu::CpuEngine;
1001use tenferro_runtime::CoreOps;
1002use tenferro_tensor::{Tensor};
1003
1004let mut engine = CpuEngine::serial();
1005let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
1006let y = a.embed_diag(0, -1, &mut engine)?;
1007assert_eq!(y.shape(), &[2, 2, 2]);
1008# Ok::<(), Box<dyn std::error::Error>>(())"#;
1009 }
1010 op slice {
1011 summary: "Static strided slice (`SliceConfig`).";
1012 operands: (a, config: tenferro_tensor::SliceConfig);
1013 options: none;
1014 output: V;
1015 dtypes: "Any numeric dtype the engine supports for the operation; the result has the input dtype.";
1016 layers: [concrete, traced, eager];
1017 into: [];
1018 layout: "Every operand is read through `TensorRead` by the engine's `*_read` entry: owned, borrowed, typed and strided inputs reach the same body. Implicit broadcasting is a zero-stride view, never a copy. Whether a strided or negative-stride view is read in place or gathered once (same placement and dtype) is the engine's documented choice for that kernel.";
1019 errors: [Validation, Unsupported];
1020 omissions: [];
1021 example concrete: r#"use tenferro_cpu::CpuEngine;
1022use tenferro_runtime::CoreOps;
1023use tenferro_tensor::{SliceConfig, Tensor};
1024
1025let mut engine = CpuEngine::serial();
1026let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
1027let y = a.slice(SliceConfig { starts: vec![0, 0], limits: vec![1, 2], strides: vec![1, 1] }, &mut engine)?;
1028assert_eq!(y.shape(), &[1, 2]);
1029# Ok::<(), Box<dyn std::error::Error>>(())"#;
1030 }
1031 op pad {
1032 summary: "Pad with edge and interior padding (`PadConfig`).";
1033 operands: (a, config: tenferro_tensor::PadConfig);
1034 options: none;
1035 output: V;
1036 dtypes: "Any numeric dtype the engine supports for the operation; the result has the input dtype.";
1037 layers: [concrete, traced, eager];
1038 into: [];
1039 layout: "Every operand is read through `TensorRead` by the engine's `*_read` entry: owned, borrowed, typed and strided inputs reach the same body. Implicit broadcasting is a zero-stride view, never a copy. Whether a strided or negative-stride view is read in place or gathered once (same placement and dtype) is the engine's documented choice for that kernel.";
1040 errors: [Validation, Unsupported];
1041 omissions: [];
1042 example concrete: r#"use tenferro_cpu::CpuEngine;
1043use tenferro_runtime::CoreOps;
1044use tenferro_tensor::{PadConfig, Tensor};
1045
1046let mut engine = CpuEngine::serial();
1047let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
1048let y = a.pad(PadConfig { edge_padding_low: vec![1, 0], edge_padding_high: vec![0, 0], interior_padding: vec![0, 0] }, &mut engine)?;
1049assert_eq!(y.shape(), &[3, 2]);
1050# Ok::<(), Box<dyn std::error::Error>>(())"#;
1051 }
1052 op gather {
1053 summary: "XLA-style gather (`GatherConfig`); `indices` is an integer tensor of any representation.";
1054 operands: (a, indices: &impl tenferro_tensor::AsView, config: tenferro_tensor::GatherConfig);
1055 options: none;
1056 output: V;
1057 dtypes: "Operand: any dtype; indices: an integer dtype.";
1058 layers: [concrete, traced, eager];
1059 into: [];
1060 layout: "Every operand is read through `TensorRead` by the engine's `*_read` entry: owned, borrowed, typed and strided inputs reach the same body. Implicit broadcasting is a zero-stride view, never a copy. Whether a strided or negative-stride view is read in place or gathered once (same placement and dtype) is the engine's documented choice for that kernel.";
1061 errors: [Validation, Unsupported];
1062 omissions: [];
1063 example concrete: r#"use tenferro_runtime::CoreOps;
1064
1065// See the `gather` tests for a complete configuration.
1066fn _uses_gather<X: CoreOps>() {}"#;
1067 }
1068 op scatter {
1069 summary: "XLA-style scatter (`ScatterConfig`); `indices` and `updates` may have any representation.";
1070 operands: (a, indices: &impl tenferro_tensor::AsView, updates: &impl tenferro_tensor::AsView, config: tenferro_tensor::ScatterConfig);
1071 options: none;
1072 output: V;
1073 dtypes: "Operand and updates share a dtype; indices: an integer dtype.";
1074 layers: [concrete, traced, eager];
1075 into: [];
1076 layout: "Every operand is read through `TensorRead` by the engine's `*_read` entry: owned, borrowed, typed and strided inputs reach the same body. Implicit broadcasting is a zero-stride view, never a copy. Whether a strided or negative-stride view is read in place or gathered once (same placement and dtype) is the engine's documented choice for that kernel.";
1077 errors: [Validation, Unsupported];
1078 omissions: [];
1079 example concrete: r#"use tenferro_runtime::CoreOps;
1080
1081// See the `scatter` tests for a complete configuration.
1082fn _uses_scatter<X: CoreOps>() {}"#;
1083 }
1084 op dynamic_slice {
1085 summary: "Slice of `sizes` starting at the run-time `starts` (an integer vector).";
1086 operands: (a, starts: &impl tenferro_tensor::AsView, sizes: &[usize]);
1087 options: none;
1088 output: V;
1089 dtypes: "Operand: any dtype; starts: an integer dtype.";
1090 layers: [concrete, traced, eager];
1091 into: [];
1092 layout: "Every operand is read through `TensorRead` by the engine's `*_read` entry: owned, borrowed, typed and strided inputs reach the same body. Implicit broadcasting is a zero-stride view, never a copy. Whether a strided or negative-stride view is read in place or gathered once (same placement and dtype) is the engine's documented choice for that kernel.";
1093 errors: [Validation, Unsupported];
1094 omissions: [];
1095 example concrete: r#"use tenferro_cpu::CpuEngine;
1096use tenferro_runtime::CoreOps;
1097use tenferro_tensor::{Tensor};
1098
1099let mut engine = CpuEngine::serial();
1100let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
1101let starts = Tensor::from_vec_col_major(vec![2], vec![1_i64, 0])?;
1102let y = a.dynamic_slice(&starts, &[1, 2], &mut engine)?;
1103assert_eq!(y.shape(), &[1, 2]);
1104# Ok::<(), Box<dyn std::error::Error>>(())"#;
1105 }
1106 op dynamic_update_slice {
1107 summary: "Copy of the receiver with `update` written at the run-time `starts`.";
1108 operands: (a, update, starts: &impl tenferro_tensor::AsView);
1109 options: none;
1110 output: V;
1111 dtypes: "Operand and update share a dtype; starts: an integer dtype.";
1112 layers: [concrete];
1113 into: [];
1114 layout: "Every operand is read through `TensorRead` by the engine's `*_read` entry: owned, borrowed, typed and strided inputs reach the same body. Implicit broadcasting is a zero-stride view, never a copy. Whether a strided or negative-stride view is read in place or gathered once (same placement and dtype) is the engine's documented choice for that kernel.";
1115 errors: [Validation, Unsupported];
1116 omissions: ["traced and eager: not available"];
1117 example concrete: r#"use tenferro_cpu::CpuEngine;
1118use tenferro_runtime::CoreOps;
1119use tenferro_tensor::{Tensor};
1120
1121let mut engine = CpuEngine::serial();
1122let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
1123let u = Tensor::from_vec_col_major(vec![1, 2], vec![9.0_f64, 9.0])?;
1124let starts = Tensor::from_vec_col_major(vec![2], vec![1_i64, 0])?;
1125let y = a.dynamic_update_slice(&u, &starts, &mut engine)?;
1126assert_eq!(y.shape(), &[2, 2]);
1127# Ok::<(), Box<dyn std::error::Error>>(())"#;
1128 }
1129 op concatenate {
1130 summary: "Concatenate `inputs` along `axis` (signed). Called as `CoreOps::concatenate(&[&a, &b], axis, exec)`.";
1131 associated;
1132 operands: (inputs: &[&Self], axis: isize);
1133 options: none;
1134 output: V;
1135 dtypes: "All inputs share a dtype.";
1136 layers: [concrete, traced, eager];
1137 into: [];
1138 layout: "Every operand is read through `TensorRead` by the engine's `*_read` entry: owned, borrowed, typed and strided inputs reach the same body. Implicit broadcasting is a zero-stride view, never a copy. Whether a strided or negative-stride view is read in place or gathered once (same placement and dtype) is the engine's documented choice for that kernel.";
1139 errors: [Validation, Unsupported];
1140 omissions: [];
1141 example concrete: r#"use tenferro_cpu::CpuEngine;
1142use tenferro_runtime::CoreOps;
1143use tenferro_tensor::Tensor;
1144
1145let mut engine = CpuEngine::serial();
1146let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
1147let y = Tensor::concatenate(&[&a, &a], -1, &mut engine)?;
1148assert_eq!(y.shape(), &[2, 4]);
1149# Ok::<(), Box<dyn std::error::Error>>(())"#;
1150 }
1151 op convert {
1152 summary: "Checked dtype conversion along tenferro's promotion lattice. The result is a dtype-erased `Tensor` because its dtype is a run-time value.";
1153 operands: (a, to: tenferro_tensor::DType);
1154 options: none;
1155 output: tenferro_tensor::Tensor;
1156 dtypes: "Any source dtype the conversion supports; the result has dtype `to`.";
1157 layers: [concrete, traced, eager];
1158 into: [];
1159 layout: "An owned `Tensor` receiver is converted directly. Any other receiver (a borrowed view or a typed tensor) is first gathered once into a compact tensor of the same placement and dtype, because the engine conversion reads an owned tensor.";
1160 errors: [Validation, Unsupported];
1161 omissions: [];
1162 example concrete: r#"use tenferro_cpu::CpuEngine;
1163use tenferro_runtime::CoreOps;
1164use tenferro_tensor::{DType, Tensor};
1165
1166let mut engine = CpuEngine::serial();
1167let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
1168let y = a.convert(DType::C64, &mut engine)?;
1169assert_eq!(y.shape(), &[2, 2]);
1170# Ok::<(), Box<dyn std::error::Error>>(())"#;
1171 }
1172 op cast {
1173 summary: "Explicit, possibly lossy dtype projection. The result is a dtype-erased `Tensor` because its dtype is a run-time value.";
1174 operands: (a, to: tenferro_tensor::DType);
1175 options: none;
1176 output: tenferro_tensor::Tensor;
1177 dtypes: "Any source dtype the conversion supports; the result has dtype `to`.";
1178 layers: [concrete, traced, eager];
1179 into: [];
1180 layout: "An owned `Tensor` receiver is converted directly. Any other receiver (a borrowed view or a typed tensor) is first gathered once into a compact tensor of the same placement and dtype, because the engine conversion reads an owned tensor.";
1181 errors: [Validation, Unsupported];
1182 omissions: [];
1183 example concrete: r#"use tenferro_cpu::CpuEngine;
1184use tenferro_runtime::CoreOps;
1185use tenferro_tensor::{DType, Tensor};
1186
1187let mut engine = CpuEngine::serial();
1188let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
1189let y = a.cast(DType::F32, &mut engine)?;
1190assert_eq!(y.shape(), &[2, 2]);
1191# Ok::<(), Box<dyn std::error::Error>>(())"#;
1192 }
1193 op scale_real {
1194 summary: "Multiply by a real scalar.";
1195 operands: (a, factor: f64);
1196 options: none;
1197 output: V;
1198 dtypes: "f32, f64, Complex32 or Complex64; the result has the input dtype.";
1199 layers: [concrete, traced, eager];
1200 into: [];
1201 layout: "Every operand is read through `TensorRead` by the engine's `*_read` entry: owned, borrowed, typed and strided inputs reach the same body. Implicit broadcasting is a zero-stride view, never a copy. Whether a strided or negative-stride view is read in place or gathered once (same placement and dtype) is the engine's documented choice for that kernel.";
1202 errors: [Validation, Unsupported];
1203 omissions: [];
1204 example concrete: r#"use tenferro_cpu::CpuEngine;
1205use tenferro_runtime::CoreOps;
1206use tenferro_tensor::{Tensor};
1207
1208let mut engine = CpuEngine::serial();
1209let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
1210let y = a.scale_real(2.0, &mut engine)?;
1211assert_eq!(y.shape(), &[2, 2]);
1212# Ok::<(), Box<dyn std::error::Error>>(())"#;
1213 }
1214 op scale_complex {
1215 summary: "Multiply by a complex scalar.";
1216 operands: (a, factor: num_complex::Complex64);
1217 options: none;
1218 output: V;
1219 dtypes: "Complex32 or Complex64.";
1220 layers: [concrete, traced, eager];
1221 into: [];
1222 layout: "Every operand is read through `TensorRead` by the engine's `*_read` entry: owned, borrowed, typed and strided inputs reach the same body. Implicit broadcasting is a zero-stride view, never a copy. Whether a strided or negative-stride view is read in place or gathered once (same placement and dtype) is the engine's documented choice for that kernel.";
1223 errors: [Validation, Unsupported];
1224 omissions: [];
1225 example concrete: r#"use num_complex::Complex64;
1226use tenferro_cpu::CpuEngine;
1227use tenferro_runtime::CoreOps;
1228use tenferro_tensor::Tensor;
1229
1230let mut engine = CpuEngine::serial();
1231let a = Tensor::from_vec_col_major(vec![1], vec![Complex64::new(1.0, 0.0)])?;
1232let y = a.scale_complex(Complex64::new(0.0, 1.0), &mut engine)?;
1233assert_eq!(y.shape(), &[1]);
1234# Ok::<(), Box<dyn std::error::Error>>(())"#;
1235 }
1236 op softmax {
1237 summary: "Softmax along `axis` (signed).";
1238 operands: (a, axis: isize);
1239 options: none;
1240 output: V;
1241 dtypes: "f32 or f64.";
1242 layers: [concrete, traced, eager];
1243 into: [];
1244 layout: "Composed from core primitives inside the engine; operands are read through `TensorRead` and intermediates are engine allocations. A fused engine kernel is used when the engine offers one.";
1245 errors: [Validation, Unsupported];
1246 omissions: [];
1247 example concrete: r#"use tenferro_cpu::CpuEngine;
1248use tenferro_runtime::CoreOps;
1249use tenferro_tensor::{Tensor};
1250
1251let mut engine = CpuEngine::serial();
1252let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
1253let y = a.softmax(-1, &mut engine)?;
1254assert_eq!(y.shape(), &[2, 2]);
1255# Ok::<(), Box<dyn std::error::Error>>(())"#;
1256 }
1257 op log_softmax {
1258 summary: "Log-softmax along `axis` (signed).";
1259 operands: (a, axis: isize);
1260 options: none;
1261 output: V;
1262 dtypes: "f32 or f64.";
1263 layers: [concrete, traced, eager];
1264 into: [];
1265 layout: "Composed from core primitives inside the engine; operands are read through `TensorRead` and intermediates are engine allocations. A fused engine kernel is used when the engine offers one.";
1266 errors: [Validation, Unsupported];
1267 omissions: [];
1268 example concrete: r#"use tenferro_cpu::CpuEngine;
1269use tenferro_runtime::CoreOps;
1270use tenferro_tensor::{Tensor};
1271
1272let mut engine = CpuEngine::serial();
1273let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
1274let y = a.log_softmax(-1, &mut engine)?;
1275assert_eq!(y.shape(), &[2, 2]);
1276# Ok::<(), Box<dyn std::error::Error>>(())"#;
1277 }
1278 op masked_softmax {
1279 summary: "Softmax along `axis` over the entries where `mask` is true.";
1280 operands: (a, mask: &impl tenferro_tensor::AsView, axis: isize);
1281 options: none;
1282 output: V;
1283 dtypes: "Input f32 or f64; mask `bool` of any representation.";
1284 layers: [concrete, traced, eager];
1285 into: [];
1286 layout: "Composed from core primitives inside the engine; operands are read through `TensorRead` and intermediates are engine allocations. A fused engine kernel is used when the engine offers one.";
1287 errors: [Validation, Unsupported];
1288 omissions: [];
1289 example concrete: r#"use tenferro_cpu::CpuEngine;
1290use tenferro_runtime::CoreOps;
1291use tenferro_tensor::{Tensor};
1292
1293let mut engine = CpuEngine::serial();
1294let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
1295let m = Tensor::from_vec_col_major(vec![2, 2], vec![true, true, false, true])?;
1296let y = a.masked_softmax(&m, -1, &mut engine)?;
1297assert_eq!(y.shape(), &[2, 2]);
1298# Ok::<(), Box<dyn std::error::Error>>(())"#;
1299 }
1300 op masked_log_softmax {
1301 summary: "Log-softmax along `axis` over the entries where `mask` is true.";
1302 operands: (a, mask: &impl tenferro_tensor::AsView, axis: isize);
1303 options: none;
1304 output: V;
1305 dtypes: "Input f32 or f64; mask `bool` of any representation.";
1306 layers: [concrete, traced, eager];
1307 into: [];
1308 layout: "Composed from core primitives inside the engine; operands are read through `TensorRead` and intermediates are engine allocations. A fused engine kernel is used when the engine offers one.";
1309 errors: [Validation, Unsupported];
1310 omissions: [];
1311 example concrete: r#"use tenferro_cpu::CpuEngine;
1312use tenferro_runtime::CoreOps;
1313use tenferro_tensor::{Tensor};
1314
1315let mut engine = CpuEngine::serial();
1316let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
1317let m = Tensor::from_vec_col_major(vec![2, 2], vec![true, true, false, true])?;
1318let y = a.masked_log_softmax(&m, -1, &mut engine)?;
1319assert_eq!(y.shape(), &[2, 2]);
1320# Ok::<(), Box<dyn std::error::Error>>(())"#;
1321 }
1322 op take_along_axis {
1323 summary: "Gather along `axis` (signed) with per-position integer `indices`.";
1324 operands: (a, indices: &impl tenferro_tensor::AsView, axis: isize);
1325 options: none;
1326 output: V;
1327 dtypes: "Input: any dtype; indices: an integer dtype.";
1328 layers: [concrete, traced, eager];
1329 into: [];
1330 layout: "Composed from core primitives inside the engine; operands are read through `TensorRead` and intermediates are engine allocations. A fused engine kernel is used when the engine offers one.";
1331 errors: [Validation, Unsupported];
1332 omissions: [];
1333 example concrete: r#"use tenferro_cpu::CpuEngine;
1334use tenferro_runtime::CoreOps;
1335use tenferro_tensor::{Tensor};
1336
1337let mut engine = CpuEngine::serial();
1338let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
1339let i = Tensor::from_vec_col_major(vec![2, 1], vec![1_i64, 0])?;
1340let y = a.take_along_axis(&i, -1, &mut engine)?;
1341assert_eq!(y.shape(), &[2, 1]);
1342# Ok::<(), Box<dyn std::error::Error>>(())"#;
1343 }
1344 op layer_norm {
1345 summary: "Layer normalization over `axis` (signed) with optional affine `weight` and `bias`.";
1346 operands: (a, axis: isize, weight: Option<&Self>, bias: Option<&Self>, eps: f64);
1347 options: none;
1348 output: V;
1349 dtypes: "f32 or f64; weight and bias share the input representation.";
1350 layers: [concrete, traced, eager];
1351 into: [];
1352 layout: "Composed from core primitives inside the engine; operands are read through `TensorRead` and intermediates are engine allocations. A fused engine kernel is used when the engine offers one.";
1353 errors: [Validation, Unsupported];
1354 omissions: [];
1355 example concrete: r#"use tenferro_cpu::CpuEngine;
1356use tenferro_runtime::CoreOps;
1357use tenferro_tensor::{Tensor};
1358
1359let mut engine = CpuEngine::serial();
1360let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
1361let y = a.layer_norm(-1, None, None, 1e-5, &mut engine)?;
1362assert_eq!(y.shape(), &[2, 2]);
1363# Ok::<(), Box<dyn std::error::Error>>(())"#;
1364 }
1365 op rms_norm {
1366 summary: "RMS normalization over `axis` (signed) with optional affine `weight` and `bias`.";
1367 operands: (a, axis: isize, weight: Option<&Self>, bias: Option<&Self>, eps: f64);
1368 options: none;
1369 output: V;
1370 dtypes: "f32 or f64; weight and bias share the input representation.";
1371 layers: [concrete, traced, eager];
1372 into: [];
1373 layout: "Composed from core primitives inside the engine; operands are read through `TensorRead` and intermediates are engine allocations. A fused engine kernel is used when the engine offers one.";
1374 errors: [Validation, Unsupported];
1375 omissions: [];
1376 example concrete: r#"use tenferro_cpu::CpuEngine;
1377use tenferro_runtime::CoreOps;
1378use tenferro_tensor::{Tensor};
1379
1380let mut engine = CpuEngine::serial();
1381let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;
1382let y = a.rms_norm(-1, None, None, 1e-5, &mut engine)?;
1383assert_eq!(y.shape(), &[2, 2]);
1384# Ok::<(), Box<dyn std::error::Error>>(())"#;
1385 }
1386 op select {
1387 summary: "Alias of `where_select` with the condition as the first argument.";
1388 operands: (condition, on_true, on_false);
1389 options: none;
1390 output: V;
1391 dtypes: "See the method documentation.";
1392 layers: [traced, eager];
1393 into: [];
1394 layout: "Recorded as graph operations (traced) or executed by the eager engine.";
1395 errors: [Validation, Unsupported];
1396 omissions: ["concrete: use `where_select`"];
1397 }
1398 op stack {
1399 summary: "Stack equally shaped tensors along a new signed axis.";
1400 operands: (inputs: &[&Self], axis: isize);
1401 options: none;
1402 output: V;
1403 dtypes: "See the method documentation.";
1404 layers: [traced, eager];
1405 into: [];
1406 layout: "Recorded as graph operations (traced) or executed by the eager engine.";
1407 errors: [Validation, Unsupported];
1408 omissions: ["concrete: not available; use `reshape` and `concatenate`"];
1409 }
1410 op index_select {
1411 summary: "Select positions along a signed axis.";
1412 operands: (a, axis: isize, positions: &[usize]);
1413 options: none;
1414 output: V;
1415 dtypes: "See the method documentation.";
1416 layers: [traced, eager];
1417 into: [];
1418 layout: "Recorded as graph operations (traced) or executed by the eager engine.";
1419 errors: [Validation, Unsupported];
1420 omissions: ["concrete: not available; use `gather`"];
1421 }
1422 op slice_axis {
1423 summary: "Slice a range along a signed axis.";
1424 operands: (a, axis: isize, range: Range<usize>);
1425 options: none;
1426 output: V;
1427 dtypes: "See the method documentation.";
1428 layers: [traced, eager];
1429 into: [];
1430 layout: "Recorded as graph operations (traced) or executed by the eager engine.";
1431 errors: [Validation, Unsupported];
1432 omissions: ["concrete: not available; use `slice`"];
1433 }
1434 op take_axis {
1435 summary: "Take the listed positions along a signed axis.";
1436 operands: (a, axis: isize, indices: &[usize]);
1437 options: none;
1438 output: V;
1439 dtypes: "See the method documentation.";
1440 layers: [traced, eager];
1441 into: [];
1442 layout: "Recorded as graph operations (traced) or executed by the eager engine.";
1443 errors: [Validation, Unsupported];
1444 omissions: ["concrete: not available; use `gather`"];
1445 }
1446 op take_rows {
1447 summary: "Take the listed rows of a matrix.";
1448 operands: (a, indices: &[usize]);
1449 options: none;
1450 output: V;
1451 dtypes: "See the method documentation.";
1452 layers: [eager];
1453 into: [];
1454 layout: "Recorded as graph operations (traced) or executed by the eager engine.";
1455 errors: [Validation, Unsupported];
1456 omissions: ["concrete and traced: not available"];
1457 }
1458 op take_cols {
1459 summary: "Take the listed columns of a matrix.";
1460 operands: (a, indices: &[usize]);
1461 options: none;
1462 output: V;
1463 dtypes: "See the method documentation.";
1464 layers: [eager];
1465 into: [];
1466 layout: "Recorded as graph operations (traced) or executed by the eager engine.";
1467 errors: [Validation, Unsupported];
1468 omissions: ["concrete and traced: not available"];
1469 }
1470 op take_block {
1471 summary: "Take a block given row and column positions.";
1472 operands: (a, rows: &[usize], cols: &[usize]);
1473 options: none;
1474 output: V;
1475 dtypes: "See the method documentation.";
1476 layers: [eager];
1477 into: [];
1478 layout: "Recorded as graph operations (traced) or executed by the eager engine.";
1479 errors: [Validation, Unsupported];
1480 omissions: ["concrete and traced: not available"];
1481 }
1482 op dynamic_truncate {
1483 summary: "Truncate a signed axis to a run-time size.";
1484 operands: (a, size, axis: isize);
1485 options: none;
1486 output: V;
1487 dtypes: "See the method documentation.";
1488 layers: [traced];
1489 into: [];
1490 layout: "Recorded as graph operations (traced) or executed by the eager engine.";
1491 errors: [Validation, Unsupported];
1492 omissions: ["concrete and eager: not available"];
1493 }
1494 op pad_to_match {
1495 summary: "Zero-pad a signed axis to the size of a reference tensor.";
1496 operands: (a, reference, axis: isize);
1497 options: none;
1498 output: V;
1499 dtypes: "See the method documentation.";
1500 layers: [traced];
1501 into: [];
1502 layout: "Recorded as graph operations (traced) or executed by the eager engine.";
1503 errors: [Validation, Unsupported];
1504 omissions: ["concrete and eager: not available"];
1505 }
1506
1507 exceptions {
1508 E03 {
1509 symbols: [
1510 "tenferro_einsum::ConcreteEinsumPlan::clear_cpu_cache",
1511 "tenferro_einsum::ConcreteEinsumPlan::cpu_cache_stats"
1512 ];
1513 scope: "plan-cache owner methods of the concrete einsum plan (clearing and inspecting the cache)";
1514 category: "cache owner | inherent method";
1515 owner_module: "tenferro_einsum::concrete";
1516 reason: "the plan owns its CPU numerical descriptor cache; a cache owner exposes its cache, and clearing or inspecting it is not a tensor operation and has no options, inputs or destination";
1517 verification: "the einsum registry tests, the cache tests and the doctests of both methods; the plan's execute/execute_into follow the grammar (inputs, exec, dest)";
1518 exit_condition: "kept while ConcreteEinsumPlan owns a CPU cache";
1519 status: retained;
1520 }
1521 E04 {
1522 symbols: [
1523 "tenferro_runtime::TraceContext",
1524 "tenferro_runtime::GraphCompiler::compile",
1525 "tenferro_runtime::GraphCompiler::compile_many",
1526 "tenferro_runtime::Runtime::prepare",
1527 "tenferro_runtime::Runtime::run",
1528 "tenferro_runtime::TraceContext::finish"
1529 ];
1530 scope: "trace, compile, prepare and run lifecycle";
1531 category: "lifecycle | builder";
1532 owner_module: "tenferro_runtime::{trace, graph, runtime}";
1533 reason: "program construction and execution are not tensor operations; their shapes are fixed by the public API snapshot (api/)";
1534 verification: "scripts/api-snapshot.sh --check and the runtime lifecycle tests";
1535 exit_condition: "kept";
1536 status: retained;
1537 }
1538 E05 {
1539 symbols: [
1540 "tenferro_tensor::Tensor::shape",
1541 "tenferro_tensor::Tensor::dtype",
1542 "tenferro_tensor::TypedTensor::as_view",
1543 "tenferro_tensor::TypedTensorView::transpose_view",
1544 "tenferro_tensor::TypedTensorView::slice_view",
1545 "tenferro_runtime::TracedTensor::rank",
1546 "tenferro_runtime::TracedTensor::sym_size",
1547 "tenferro_runtime::TracedTensor::axis_sym_dim",
1548 "tenferro_runtime::TracedTensor::shape_of"
1549 ];
1550 scope: "descriptor-only operations and metadata queries";
1551 category: "metadata | view";
1552 owner_module: "tenferro_tensor, tenferro_runtime::traced";
1553 reason: "they never touch element data, so they take no engine and are not operations of the grammar";
1554 verification: "tenferro-runtime `metadata_queries_and_views_do_not_copy` (pointer identity)";
1555 exit_condition: "kept";
1556 status: retained;
1557 }
1558 E06 {
1559 symbols: [
1560 "tenferro_cpu::with_borrowed_cpu_engine",
1561 "tenferro_tensor::Dest::into_accumulation",
1562 "num_complex::Complex"
1563 ];
1564 scope: "approved external types and owner-scoped doc-hidden bridges";
1565 category: "bridge | external type";
1566 owner_module: "tenferro_cpu, tenferro_tensor::dest";
1567 reason: "the lane bridge lets tenferro-linalg reach the lane engine (#2552 S2b); into_accumulation maps a Dest to the backend accumulation descriptor (#2552 Q3); num_complex is the public complex scalar";
1568 verification: "listed symbol by symbol in api/allowlist.txt; the bridges are #[doc(hidden)]";
1569 exit_condition: "kept while the owners need the bridge";
1570 status: retained;
1571 }
1572 E09 {
1573 symbols: [
1574 "tenferro_einsum::Error",
1575 "tenferro_einsum::PlanningError",
1576 "tenferro_einsum::parse_einsum_subscripts",
1577 "tenferro_einsum::parse_einsum_notation",
1578 "tenferro_einsum::ContractionTree::optimize",
1579 "tenferro_einsum::ContractionTree::optimize_with_options",
1580 "tenferro_einsum::ContractionTree::from_pairs",
1581 "tenferro_linalg::Error",
1582 "tenferro_fft::EagerFftInPlaceError"
1583 ];
1584 scope: "domain errors of parsers and planners (einsum parser and contraction planner), and failures that return ownership";
1585 category: "error | domain";
1586 owner_module: "the owning family crates";
1587 reason: "parsers and planners report einsum-domain errors; the grammar's operations wrap them (concrete: tenferro_tensor::Error::Extension, traced/eager: tenferro_runtime::Error::Extension) as the `source()` of the layer error";
1588 verification: "the error-cause tests of each family; the einsum error-cause tests reach tenferro_einsum::Error::InvalidSubscripts through source() on all three layers";
1589 exit_condition: "kept";
1590 status: retained;
1591 }
1592 E10 {
1593 symbols: [
1594 "tenferro_tensor::Engine",
1595 "tenferro_tensor::TensorDot",
1596 "tenferro_tensor::TensorDot::dot_general_read_into_accum",
1597 "tenferro_tensor::Engine::axpby_read_into_accum",
1598 "tenferro_linalg::LinalgBackend",
1599 "tenferro_fft::FftBackend"
1600 ];
1601 scope: "backend and provider traits and their read/accumulate hooks";
1602 category: "provider contract | trait";
1603 owner_module: "tenferro_tensor::backend and the family backends";
1604 reason: "a provider-facing contract, not the user grammar; `*_read` and `*_read_into_accum` name backend hooks";
1605 verification: "the backend contract tests of each crate";
1606 exit_condition: "kept";
1607 status: retained;
1608 }
1609 }
1610}