tract_data/
macros.rs

1#[macro_export]
2macro_rules! tvec {
3    // count helper: transform any expression into 1
4    (@one $x:expr) => (1usize);
5    ($elem:expr; $n:expr) => ({
6        $crate::TVec::from_elem($elem, $n)
7    });
8    ($($x:expr),*$(,)*) => ({
9        let count = 0usize $(+ tvec!(@one $x))*;
10        #[allow(unused_mut)]
11        let mut vec = $crate::TVec::new();
12        if count <= vec.inline_size() {
13            $(vec.push($x);)*
14            vec
15        } else {
16            $crate::TVec::from_vec(vec![$($x,)*])
17        }
18    });
19}
20
21#[macro_export]
22macro_rules! dispatch_datum {
23    ($($path:ident)::* ($dt:expr) ($($args:expr),*)) => { {
24        use $crate::prelude::DatumType;
25        #[allow(unexpected_cfgs)]
26        match $dt {
27            DatumType::Bool => $($path)::*::<bool>($($args),*),
28            DatumType::U8   => $($path)::*::<u8>($($args),*),
29            DatumType::U16  => $($path)::*::<u16>($($args),*),
30            DatumType::U32  => $($path)::*::<u32>($($args),*),
31            DatumType::U64  => $($path)::*::<u64>($($args),*),
32            DatumType::I8   => $($path)::*::<i8>($($args),*),
33            DatumType::I16  => $($path)::*::<i16>($($args),*),
34            DatumType::I32  => $($path)::*::<i32>($($args),*),
35            DatumType::I64  => $($path)::*::<i64>($($args),*),
36            DatumType::F16  => $($path)::*::<f16>($($args),*),
37            DatumType::F32  => $($path)::*::<f32>($($args),*),
38            DatumType::F64  => $($path)::*::<f64>($($args),*),
39            DatumType::Blob => $($path)::*::<$crate::prelude::Blob>($($args),*),
40            DatumType::TDim => $($path)::*::<TDim>($($args),*),
41            DatumType::String => $($path)::*::<String>($($args),*),
42            DatumType::Opaque => $($path)::*::<$crate::prelude::Opaque>($($args),*),
43            DatumType::QI8(_) => $($path)::*::<i8>($($args),*),
44            DatumType::QU8(_) => $($path)::*::<u8>($($args),*),
45            DatumType::QI32(_) => $($path)::*::<i32>($($args),*),
46            #[cfg(feature = "complex")]
47            DatumType::ComplexI16 => $($path)::*::<Complex<i16>>($($args),*),
48            #[cfg(feature = "complex")]
49            DatumType::ComplexI32 => $($path)::*::<Complex<i32>>($($args),*),
50            #[cfg(feature = "complex")]
51            DatumType::ComplexI64 => $($path)::*::<Complex<i64>>($($args),*),
52            #[cfg(feature = "complex")]
53            DatumType::ComplexF16 => $($path)::*::<Complex<f16>>($($args),*),
54            #[cfg(feature = "complex")]
55            DatumType::ComplexF32 => $($path)::*::<Complex<f32>>($($args),*),
56            #[cfg(feature = "complex")]
57            DatumType::ComplexF64 => $($path)::*::<Complex<f64>>($($args),*),
58        }
59    } }
60}
61
62#[macro_export]
63macro_rules! dispatch_datum_by_size {
64    ($($path:ident)::* ($dt:expr) ($($args:expr),*)) => { {
65        use $crate::prelude::DatumType;
66        #[allow(unexpected_cfgs)]
67        match $dt {
68            DatumType::Bool => $($path)::*::<i8>($($args),*),
69            DatumType::U8   => $($path)::*::<i8>($($args),*),
70            DatumType::U16  => $($path)::*::<i16>($($args),*),
71            DatumType::U32  => $($path)::*::<i32>($($args),*),
72            DatumType::U64  => $($path)::*::<i64>($($args),*),
73            DatumType::I8   => $($path)::*::<i8>($($args),*),
74            DatumType::I16  => $($path)::*::<i16>($($args),*),
75            DatumType::I32  => $($path)::*::<i32>($($args),*),
76            DatumType::I64  => $($path)::*::<i64>($($args),*),
77            DatumType::F16  => $($path)::*::<i16>($($args),*),
78            DatumType::F32  => $($path)::*::<i32>($($args),*),
79            DatumType::F64  => $($path)::*::<i64>($($args),*),
80            DatumType::Blob => $($path)::*::<Blob>($($args),*),
81            DatumType::TDim => $($path)::*::<TDim>($($args),*),
82            DatumType::String => $($path)::*::<String>($($args),*),
83            DatumType::Opaque => $($path)::*::<$crate::prelude::Opaque>($($args),*),
84            DatumType::QI8(_)   => $($path)::*::<i8>($($args),*),
85            DatumType::QU8(_)   => $($path)::*::<u8>($($args),*),
86            DatumType::QI32(_)   => $($path)::*::<i32>($($args),*),
87            #[cfg(feature = "complex")]
88            DatumType::ComplexI16 => $($path)::*::<Complex<i16>>($($args),*),
89            #[cfg(feature = "complex")]
90            DatumType::ComplexI32 => $($path)::*::<Complex<i32>>($($args),*),
91            #[cfg(feature = "complex")]
92            DatumType::ComplexI64 => $($path)::*::<Complex<i64>>($($args),*),
93            #[cfg(feature = "complex")]
94            DatumType::ComplexF16 => $($path)::*::<Complex<f16>>($($args),*),
95            #[cfg(feature = "complex")]
96            DatumType::ComplexF32 => $($path)::*::<Complex<f32>>($($args),*),
97            #[cfg(feature = "complex")]
98            DatumType::ComplexF64 => $($path)::*::<Complex<f64>>($($args),*),
99        }
100    } }
101}
102
103#[macro_export]
104macro_rules! dispatch_copy {
105    ($($path:ident)::* ($dt:expr) ($($args:expr),*)) => { {
106        use $crate::prelude::DatumType;
107        #[allow(unexpected_cfgs)]
108        match $dt {
109            DatumType::Bool => $($path)::*::<bool>($($args),*),
110            DatumType::U8   => $($path)::*::<u8>($($args),*),
111            DatumType::U16  => $($path)::*::<u16>($($args),*),
112            DatumType::U32  => $($path)::*::<u32>($($args),*),
113            DatumType::U64  => $($path)::*::<u64>($($args),*),
114            DatumType::I8   => $($path)::*::<i8>($($args),*),
115            DatumType::I16  => $($path)::*::<i16>($($args),*),
116            DatumType::I32  => $($path)::*::<i32>($($args),*),
117            DatumType::I64  => $($path)::*::<i64>($($args),*),
118            DatumType::F16  => $($path)::*::<f16>($($args),*),
119            DatumType::F32  => $($path)::*::<f32>($($args),*),
120            DatumType::F64  => $($path)::*::<f64>($($args),*),
121            DatumType::QI8(_)  => $($path)::*::<i8>($($args),*),
122            DatumType::QU8(_)  => $($path)::*::<u8>($($args),*),
123            DatumType::QI32(_)  => $($path)::*::<u8>($($args),*),
124            #[cfg(feature = "complex")]
125            DatumType::ComplexI16 => $($path)::*::<Complex<i16>>($($args),*),
126            #[cfg(feature = "complex")]
127            DatumType::ComplexI32 => $($path)::*::<Complex<i32>>($($args),*),
128            #[cfg(feature = "complex")]
129            DatumType::ComplexI64 => $($path)::*::<Complex<i64>>($($args),*),
130            #[cfg(feature = "complex")]
131            DatumType::ComplexF16 => $($path)::*::<Complex<f16>>($($args),*),
132            #[cfg(feature = "complex")]
133            DatumType::ComplexF32 => $($path)::*::<Complex<f32>>($($args),*),
134            #[cfg(feature = "complex")]
135            DatumType::ComplexF64 => $($path)::*::<Complex<f64>>($($args),*),
136            _ => panic!("{:?} is not Copy", $dt)
137        }
138    } }
139}
140
141#[macro_export]
142macro_rules! dispatch_copy_by_size {
143    ($($path:ident)::* ($dt:expr) ($($args:expr),*)) => { {
144        use $crate::prelude::DatumType;
145        #[allow(unexpected_cfgs)]
146        match $dt {
147            DatumType::Bool => $($path)::*::<i8>($($args),*),
148            DatumType::U8   => $($path)::*::<i8>($($args),*),
149            DatumType::U16  => $($path)::*::<i16>($($args),*),
150            DatumType::U32  => $($path)::*::<i32>($($args),*),
151            DatumType::U64  => $($path)::*::<i64>($($args),*),
152            DatumType::I8   => $($path)::*::<i8>($($args),*),
153            DatumType::I16  => $($path)::*::<i16>($($args),*),
154            DatumType::I32  => $($path)::*::<i32>($($args),*),
155            DatumType::I64  => $($path)::*::<i64>($($args),*),
156            DatumType::F16  => $($path)::*::<i16>($($args),*),
157            DatumType::F32  => $($path)::*::<i32>($($args),*),
158            DatumType::F64  => $($path)::*::<i64>($($args),*),
159            DatumType::QI8(_)  => $($path)::*::<i8>($($args),*),
160            DatumType::QU8(_)  => $($path)::*::<u8>($($args),*),
161            DatumType::QI32(_)  => $($path)::*::<i32>($($args),*),
162            #[cfg(feature = "complex")]
163            DatumType::ComplexI32 => $($path)::*::<Complex<i32>>($($args),*),
164            #[cfg(feature = "complex")]
165            DatumType::ComplexI64 => $($path)::*::<Complex<i64>>($($args),*),
166            #[cfg(feature = "complex")]
167            DatumType::ComplexF16 => $($path)::*::<Complex<f16>>($($args),*),
168            #[cfg(feature = "complex")]
169            DatumType::ComplexF32 => $($path)::*::<Complex<f32>>($($args),*),
170            #[cfg(feature = "complex")]
171            DatumType::ComplexF64 => $($path)::*::<Complex<f64>>($($args),*),
172            _ => panic!("{:?} is not Copy", $dt)
173        }
174    } }
175}
176
177#[macro_export]
178macro_rules! dispatch_numbers {
179    ($($path:ident)::* ($dt:expr) ($($args:expr),*)) => { {
180        use $crate::prelude::DatumType;
181        match $dt {
182            DatumType::U8   => $($path)::*::<u8>($($args),*),
183            DatumType::U16  => $($path)::*::<u16>($($args),*),
184            DatumType::U32  => $($path)::*::<u32>($($args),*),
185            DatumType::U64  => $($path)::*::<u64>($($args),*),
186            DatumType::I8   => $($path)::*::<i8>($($args),*),
187            DatumType::I16  => $($path)::*::<i16>($($args),*),
188            DatumType::I32  => $($path)::*::<i32>($($args),*),
189            DatumType::I64  => $($path)::*::<i64>($($args),*),
190            DatumType::F16  => $($path)::*::<f16>($($args),*),
191            DatumType::F32  => $($path)::*::<f32>($($args),*),
192            DatumType::F64  => $($path)::*::<f64>($($args),*),
193            DatumType::QI8(_)  => $($path)::*::<i8>($($args),*),
194            DatumType::QU8(_)  => $($path)::*::<u8>($($args),*),
195            DatumType::QI32(_)  => $($path)::*::<i32>($($args),*),
196            _ => $crate::internal::bail!("{:?} is not a number", $dt)
197        }
198    } }
199}
200
201#[macro_export]
202macro_rules! dispatch_zerolike {
203    ($($path:ident)::* ($dt:expr) ($($args:expr),*)) => { {
204        use $crate::prelude::DatumType;
205        match $dt {
206            DatumType::TDim => $($path)::*::<TDim>($($args),*),
207            DatumType::U8   => $($path)::*::<u8>($($args),*),
208            DatumType::U16  => $($path)::*::<u16>($($args),*),
209            DatumType::U32  => $($path)::*::<u32>($($args),*),
210            DatumType::U64  => $($path)::*::<u64>($($args),*),
211            DatumType::I8   => $($path)::*::<i8>($($args),*),
212            DatumType::I16  => $($path)::*::<i16>($($args),*),
213            DatumType::I32  => $($path)::*::<i32>($($args),*),
214            DatumType::I64  => $($path)::*::<i64>($($args),*),
215            DatumType::F16  => $($path)::*::<f16>($($args),*),
216            DatumType::F32  => $($path)::*::<f32>($($args),*),
217            DatumType::F64  => $($path)::*::<f64>($($args),*),
218            DatumType::QI8(_)  => $($path)::*::<i8>($($args),*),
219            DatumType::QU8(_)  => $($path)::*::<u8>($($args),*),
220            DatumType::QI32(_)  => $($path)::*::<i32>($($args),*),
221            #[cfg(feature = "complex")]
222            DatumType::ComplexI32 => $($path)::*::<Complex<i32>>($($args),*),
223            #[cfg(feature = "complex")]
224            DatumType::ComplexI64 => $($path)::*::<Complex<i64>>($($args),*),
225            #[cfg(feature = "complex")]
226            DatumType::ComplexF16 => $($path)::*::<Complex<f16>>($($args),*),
227            #[cfg(feature = "complex")]
228            DatumType::ComplexF32 => $($path)::*::<Complex<f32>>($($args),*),
229            #[cfg(feature = "complex")]
230            DatumType::ComplexF64 => $($path)::*::<Complex<f64>>($($args),*),
231            _ => $crate::internal::bail!("{:?} doesn't implement num_traits::Zero", $dt)
232        }
233    } }
234}
235
236#[macro_export]
237macro_rules! dispatch_floatlike {
238    ($($path:ident)::* ($dt:expr) ($($args:expr),*)) => { {
239        use $crate::prelude::DatumType;
240        match $dt {
241            DatumType::F16  => $($path)::*::<f16>($($args),*),
242            DatumType::F32  => $($path)::*::<f32>($($args),*),
243            DatumType::F64  => $($path)::*::<f64>($($args),*),
244            _ => $crate::internal::bail!("{:?} is not float-like", $dt)
245        }
246    } }
247}
248
249#[macro_export]
250macro_rules! dispatch_signed {
251    ($($path:ident)::* ($dt:expr) ($($args:expr),*)) => { {
252        use $crate::prelude::DatumType;
253        match $dt {
254            DatumType::F16  => $($path)::*::<f16>($($args),*),
255            DatumType::F32  => $($path)::*::<f32>($($args),*),
256            DatumType::F64  => $($path)::*::<f64>($($args),*),
257            DatumType::I8   => $($path)::*::<i8>($($args),*),
258            DatumType::I16  => $($path)::*::<i16>($($args),*),
259            DatumType::I32  => $($path)::*::<i32>($($args),*),
260            DatumType::I64  => $($path)::*::<i64>($($args),*),
261            DatumType::TDim => $($path)::*::<TDim>($($args),*),
262            _ => $crate::internal::bail!("{:?} is not signed", $dt)
263        }
264    } }
265}
266
267#[macro_export]
268macro_rules! dispatch_hash {
269    ($($path:ident)::* ($dt:expr) ($($args:expr),*)) => { {
270        use $crate::prelude::DatumType;
271        #[allow(unexpected_cfgs)]
272        match $dt {
273            DatumType::Bool => $($path)::*::<bool>($($args),*),
274            DatumType::U8   => $($path)::*::<u8>($($args),*),
275            DatumType::U16  => $($path)::*::<u16>($($args),*),
276            DatumType::U32  => $($path)::*::<u32>($($args),*),
277            DatumType::U64  => $($path)::*::<u64>($($args),*),
278            DatumType::I8   => $($path)::*::<i8>($($args),*),
279            DatumType::I16  => $($path)::*::<i16>($($args),*),
280            DatumType::I32  => $($path)::*::<i32>($($args),*),
281            DatumType::I64  => $($path)::*::<i64>($($args),*),
282            DatumType::Blob => $($path)::*::<Blob>($($args),*),
283            DatumType::TDim => $($path)::*::<TDim>($($args),*),
284            DatumType::String => $($path)::*::<String>($($args),*),
285            DatumType::Opaque => $($path)::*::<$crate::prelude::Opaque>($($args),*),
286            #[cfg(feature="complex")]
287            DatumType::ComplexI16 => $($path)::*::<Complex<i16>>($($args),*),
288            #[cfg(feature="complex")]
289            DatumType::ComplexI32 => $($path)::*::<Complex<i32>>($($args),*),
290            #[cfg(feature="complex")]
291            DatumType::ComplexI64 => $($path)::*::<Complex<i64>>($($args),*),
292            _ => $crate::internal::bail!("{:?} is not Hash", $dt)
293        }
294    } }
295}