1use singe_cuda::types::{Complex32, Complex64};
2
3use crate::{
4 context::StreamContext,
5 error::Result,
6 signal::view::{SignalView, SignalViewMut},
7 types::{ComparisonOperation, ComplexI16, DataTypeLike},
8};
9
10use super::*;
11
12macro_rules! impl_signal_threshold_dispatch {
13 ($trait:ident, $method:ident, $function:ident, [$($ty:ty => ($level_ty:ty, $direct:ident)),* $(,)?]) => {
14 pub trait $trait: DataTypeLike {
15 type Level: DataTypeLike;
16
17 fn $method(
18 stream_context: &StreamContext,
19 source: &SignalView<'_, Self>,
20 destination: &mut SignalViewMut<'_, Self>,
21 level: Self::Level,
22 operation: ComparisonOperation,
23 ) -> Result<()>;
24 }
25
26 $(
27 impl $trait for $ty {
28 type Level = $level_ty;
29
30 fn $method(
31 stream_context: &StreamContext,
32 source: &SignalView<'_, Self>,
33 destination: &mut SignalViewMut<'_, Self>,
34 level: Self::Level,
35 operation: ComparisonOperation,
36 ) -> Result<()> {
37 $direct(stream_context, source, destination, level, operation)
38 }
39 }
40 )*
41
42 pub fn $function<T: $trait>(
43 stream_context: &StreamContext,
44 source: &SignalView<'_, T>,
45 destination: &mut SignalViewMut<'_, T>,
46 level: T::Level,
47 operation: ComparisonOperation,
48 ) -> Result<()> {
49 T::$method(stream_context, source, destination, level, operation)
50 }
51 };
52}
53
54macro_rules! impl_signal_threshold_in_place_dispatch {
55 ($trait:ident, $method:ident, $function:ident, [$($ty:ty => ($level_ty:ty, $direct:ident)),* $(,)?]) => {
56 pub trait $trait: DataTypeLike {
57 type Level: DataTypeLike;
58
59 fn $method(
60 stream_context: &StreamContext,
61 signal: &mut SignalViewMut<'_, Self>,
62 level: Self::Level,
63 operation: ComparisonOperation,
64 ) -> Result<()>;
65 }
66
67 $(
68 impl $trait for $ty {
69 type Level = $level_ty;
70
71 fn $method(
72 stream_context: &StreamContext,
73 signal: &mut SignalViewMut<'_, Self>,
74 level: Self::Level,
75 operation: ComparisonOperation,
76 ) -> Result<()> {
77 $direct(stream_context, signal, level, operation)
78 }
79 }
80 )*
81
82 pub fn $function<T: $trait>(
83 stream_context: &StreamContext,
84 signal: &mut SignalViewMut<'_, T>,
85 level: T::Level,
86 operation: ComparisonOperation,
87 ) -> Result<()> {
88 T::$method(stream_context, signal, level, operation)
89 }
90 };
91}
92
93macro_rules! impl_signal_threshold_fixed_dispatch {
94 ($trait:ident, $method:ident, $function:ident, [$($ty:ty => ($level_ty:ty, $direct:ident)),* $(,)?]) => {
95 pub trait $trait: DataTypeLike {
96 type Level: DataTypeLike;
97
98 fn $method(
99 stream_context: &StreamContext,
100 source: &SignalView<'_, Self>,
101 destination: &mut SignalViewMut<'_, Self>,
102 level: Self::Level,
103 ) -> Result<()>;
104 }
105
106 $(
107 impl $trait for $ty {
108 type Level = $level_ty;
109
110 fn $method(
111 stream_context: &StreamContext,
112 source: &SignalView<'_, Self>,
113 destination: &mut SignalViewMut<'_, Self>,
114 level: Self::Level,
115 ) -> Result<()> {
116 $direct(stream_context, source, destination, level)
117 }
118 }
119 )*
120
121 pub fn $function<T: $trait>(
122 stream_context: &StreamContext,
123 source: &SignalView<'_, T>,
124 destination: &mut SignalViewMut<'_, T>,
125 level: T::Level,
126 ) -> Result<()> {
127 T::$method(stream_context, source, destination, level)
128 }
129 };
130}
131
132macro_rules! impl_signal_threshold_value_dispatch {
133 ($trait:ident, $method:ident, $function:ident, [$($ty:ty => ($level_ty:ty, $direct:ident)),* $(,)?]) => {
134 pub trait $trait: DataTypeLike {
135 type Level: DataTypeLike;
136
137 fn $method(
138 stream_context: &StreamContext,
139 source: &SignalView<'_, Self>,
140 destination: &mut SignalViewMut<'_, Self>,
141 level: Self::Level,
142 value: Self,
143 ) -> Result<()>;
144 }
145
146 $(
147 impl $trait for $ty {
148 type Level = $level_ty;
149
150 fn $method(
151 stream_context: &StreamContext,
152 source: &SignalView<'_, Self>,
153 destination: &mut SignalViewMut<'_, Self>,
154 level: Self::Level,
155 value: Self,
156 ) -> Result<()> {
157 $direct(stream_context, source, destination, level, value)
158 }
159 }
160 )*
161
162 pub fn $function<T: $trait>(
163 stream_context: &StreamContext,
164 source: &SignalView<'_, T>,
165 destination: &mut SignalViewMut<'_, T>,
166 level: T::Level,
167 value: T,
168 ) -> Result<()> {
169 T::$method(stream_context, source, destination, level, value)
170 }
171 };
172}
173
174impl_signal_threshold_dispatch!(Threshold, threshold, threshold, [
175 i16 => (i16, threshold_i16),
176 f32 => (f32, threshold_f32),
177 f64 => (f64, threshold_f64),
178 ComplexI16 => (i16, threshold_i16_complex),
179 Complex32 => (f32, threshold_f32_complex),
180 Complex64 => (f64, threshold_f64_complex)
181]);
182
183impl_signal_threshold_in_place_dispatch!(ThresholdInPlace, threshold_in_place, threshold_in_place, [
184 i16 => (i16, threshold_i16_in_place),
185 f32 => (f32, threshold_f32_in_place),
186 f64 => (f64, threshold_f64_in_place),
187 ComplexI16 => (i16, threshold_i16_complex_in_place),
188 Complex32 => (f32, threshold_f32_complex_in_place),
189 Complex64 => (f64, threshold_f64_complex_in_place)
190]);
191
192impl_signal_threshold_fixed_dispatch!(ThresholdLess, threshold_less, threshold_less, [
193 i16 => (i16, threshold_less_i16),
194 f32 => (f32, threshold_less_f32),
195 f64 => (f64, threshold_less_f64),
196 ComplexI16 => (i16, threshold_less_i16_complex),
197 Complex32 => (f32, threshold_less_f32_complex),
198 Complex64 => (f64, threshold_less_f64_complex)
199]);
200
201impl_signal_threshold_fixed_dispatch!(ThresholdGreater, threshold_greater, threshold_greater, [
202 i16 => (i16, threshold_greater_i16),
203 f32 => (f32, threshold_greater_f32),
204 f64 => (f64, threshold_greater_f64),
205 ComplexI16 => (i16, threshold_greater_i16_complex),
206 Complex32 => (f32, threshold_greater_f32_complex),
207 Complex64 => (f64, threshold_greater_f64_complex)
208]);
209
210impl_signal_threshold_value_dispatch!(ThresholdLessValue, threshold_less_value, threshold_less_value, [
211 i16 => (i16, threshold_less_value_i16),
212 f32 => (f32, threshold_less_value_f32),
213 f64 => (f64, threshold_less_value_f64),
214 ComplexI16 => (i16, threshold_less_value_i16_complex),
215 Complex32 => (f32, threshold_less_value_f32_complex),
216 Complex64 => (f64, threshold_less_value_f64_complex)
217]);
218
219impl_signal_threshold_value_dispatch!(ThresholdGreaterValue, threshold_greater_value, threshold_greater_value, [
220 i16 => (i16, threshold_greater_value_i16),
221 f32 => (f32, threshold_greater_value_f32),
222 f64 => (f64, threshold_greater_value_f64),
223 ComplexI16 => (i16, threshold_greater_value_i16_complex),
224 Complex32 => (f32, threshold_greater_value_f32_complex),
225 Complex64 => (f64, threshold_greater_value_f64_complex)
226
227]);