Skip to main content

tract_linalg/generic/
by_scalar.rs

1use tract_data::internal::f16;
2
3routine_by_scalar_rust!(generic;
4    f32,
5    SMulByScalar4,
6    4,
7    4,
8    fn run(x: &mut [f32], s: f32) {
9        debug_assert!(x.len() % Self::nr() == 0);
10        debug_assert!(x.as_ptr() as usize % Self::alignment_bytes() == 0);
11        x.iter_mut().for_each(|px| *px *= s)
12    },
13    op(Mul),
14    bin,
15    param(MulByScalar)
16);
17
18routine_by_scalar_rust!(generic;
19    f32,
20    SAddByScalar4,
21    4,
22    4,
23    fn run(x: &mut [f32], s: f32) {
24        debug_assert!(x.len() % Self::nr() == 0);
25        debug_assert!(x.as_ptr() as usize % Self::alignment_bytes() == 0);
26        x.iter_mut().for_each(|px| *px += s)
27    },
28    op(Add),
29    bin
30);
31
32routine_by_scalar_rust!(generic;
33    f32,
34    SSubByScalar4,
35    4,
36    4,
37    fn run(x: &mut [f32], s: f32) {
38        debug_assert!(x.len() % Self::nr() == 0);
39        debug_assert!(x.as_ptr() as usize % Self::alignment_bytes() == 0);
40        x.iter_mut().for_each(|px| *px -= s)
41    },
42    op(Sub),
43    bin
44);
45
46routine_by_scalar_rust!(generic;
47    f32,
48    SSubFByScalar4,
49    4,
50    4,
51    fn run(x: &mut [f32], s: f32) {
52        debug_assert!(x.len() % Self::nr() == 0);
53        debug_assert!(x.as_ptr() as usize % Self::alignment_bytes() == 0);
54        x.iter_mut().for_each(|px| *px = s - *px)
55    },
56    op(SubF),
57    bin
58);
59
60routine_by_scalar_rust!(generic;
61    f32,
62    SMinByScalar4,
63    4,
64    4,
65    fn run(x: &mut [f32], s: f32) {
66        debug_assert!(x.len() % Self::nr() == 0);
67        debug_assert!(x.as_ptr() as usize % Self::alignment_bytes() == 0);
68        x.iter_mut().for_each(|px| *px = px.min(s))
69    },
70    op(Min),
71    bin
72);
73
74routine_by_scalar_rust!(generic;
75    f32,
76    SMaxByScalar4,
77    4,
78    4,
79    fn run(x: &mut [f32], s: f32) {
80        debug_assert!(x.len() % Self::nr() == 0);
81        debug_assert!(x.as_ptr() as usize % Self::alignment_bytes() == 0);
82        x.iter_mut().for_each(|px| *px = px.max(s))
83    },
84    op(Max),
85    bin
86);
87
88routine_by_scalar_rust!(generic;
89    f16,
90    HMulByScalar8,
91    8,
92    8,
93    fn run(x: &mut [f16], s: f16) {
94        debug_assert!(x.len() % Self::nr() == 0);
95        debug_assert!(x.as_ptr() as usize % Self::alignment_bytes() == 0);
96        x.iter_mut().for_each(|px| *px *= s)
97    },
98    op(Mul),
99    param(MulByScalar)
100);