1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use ;
use ;
/// Dynamic operations supported by execution hardware backends.
///
/// `BackendOps<T>` is the single dispatch surface that routes all tensor kernels
/// (elementwise, matmul, conv, pooling, and unfold/fold) to the
/// underlying device. Attention is an optional capability expressed by
/// `AttentionOps` and stateful updates are optional capabilities expressed by
/// `OptimizerOps`. This trait is a **super-trait** composed of six
/// interface-segregated sub-traits (see the [`super::traits`] module). Backends
/// implement each sub-trait independently; the blanket impl below provides
/// `BackendOps` automatically.
///
/// The CPU path is provided by sub-trait impls in `backend_ops::cpu_impl`;
/// other devices add new sub-trait impls without touching the algorithm
/// bodies.
///
/// # Examples
///
/// `SequentialBackend` implements `BackendOps` and drives all kernel dispatch:
///
/// ```
/// use coeus_ops::{BackendOps, add};
/// use coeus_tensor::Tensor;
/// use coeus_core::SequentialBackend;
///
/// fn compute<B: BackendOps<f32>>(
/// a: &Tensor<f32, B>,
/// b: &Tensor<f32, B>,
/// backend: &B,
/// ) -> Result<Tensor<f32, B>, B::Error> {
/// add(a, b, backend)
/// }
///
/// let backend = SequentialBackend::new();
/// let a = Tensor::<f32, SequentialBackend>::from_slice([2], &[1.0, 2.0])
/// .expect("example tensor allocation succeeds");
/// let b = Tensor::<f32, SequentialBackend>::from_slice([2], &[3.0, 4.0])
/// .expect("example tensor allocation succeeds");
/// let c = compute(&a, &b, &backend).expect("example addition succeeds");
/// assert_eq!(c.as_slice(), &[4.0, 6.0]);
/// ```
/// Blanket impl: any backend that implements all six required sub-traits automatically
/// satisfies `BackendOps`. No additional methods are required — `BackendOps`
/// is a marker super-trait.