1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//! Scalar operations named by type.
//!
//! An operation passed to the scalar-agnostic entry points is a *type*, not a
//! closure. A closure is part of a generic function's type parameters, so every
//! call site would produce its own instantiation of the whole `strided-kernel`
//! body. A named operation keeps the instantiation keyed on the element type and
//! the operation, so two scalar sets that call the same operation share one
//! compiled kernel instead of one per set.
/// A binary operation between two scalars of the same type.
///
/// Implement this for a marker type in the crate that owns the operation. That
/// is how an external scalar's contribution supplies its own arithmetic.
///
/// # Examples
///
/// ```rust
/// use tenferro_internal_cpu_kernels::scalar_ops::{AddOp, BinaryScalarOp};
///
/// assert_eq!(<AddOp as BinaryScalarOp<f64>>::apply(1.0, 2.0), 3.0);
/// // Integers wrap, so the shared path agrees with the preset path in every build.
/// assert_eq!(<AddOp as BinaryScalarOp<i32>>::apply(i32::MAX, 1), i32::MIN);
/// ```
/// Addition.
///
/// # Examples
///
/// ```rust
/// use tenferro_internal_cpu_kernels::scalar_ops::{AddOp, BinaryScalarOp};
///
/// assert_eq!(<AddOp as BinaryScalarOp<i32>>::apply(1, 2), 3);
/// ```
;
/// Subtraction.
///
/// # Examples
///
/// ```rust
/// use tenferro_internal_cpu_kernels::scalar_ops::{BinaryScalarOp, SubOp};
///
/// assert_eq!(<SubOp as BinaryScalarOp<f64>>::apply(5.0, 2.0), 3.0);
/// ```
;
/// Multiplication.
///
/// # Examples
///
/// ```rust
/// use tenferro_internal_cpu_kernels::scalar_ops::{BinaryScalarOp, MulOp};
///
/// assert_eq!(<MulOp as BinaryScalarOp<f64>>::apply(3.0, 4.0), 12.0);
/// ```
;