1mod data_formats;
2mod reduce;
3mod softmax;
4
5pub use self::data_formats::{BaseDataShape, DataFormat, DataShape, SymDataShape};
6pub use self::reduce::{Reduce, Reducer, expand_mean_of_squares};
7pub use self::softmax::{Softmax, SoftmaxExp};
8
9pub use crate::internal::*;
10
11use tract_num_traits::AsPrimitive;
12
13element_wise!(sigmoid, Sigmoid,
14 [f16] => |_, xs| { (tract_linalg::ops().sigmoid_f16)().run(xs) },
15 [f32] => |_, xs| { (tract_linalg::ops().sigmoid_f32)().run(xs) };
16 q: [i8, u8, i32, i32] => |x: f32| 1.0 / (1.0+(-x).exp());
17 cost: |dt| {tvec!((Cost::FMA(dt), 11), (Cost::Div(dt), 1))}
18);
19
20element_wise!(hard_swish, HardSwish,
21[f16] => |_, xs| { xs.iter_mut().for_each(|x| *x = *x * f16::from_f32(0.0).max(f16::from_f32(1.0).min(f16::from_f32(1. / 6.) * *x + f16::from_f32(0.5)))); Ok(()) },
22[f32] => |_, xs| { xs.iter_mut().for_each(|x| *x = *x * 0f32.max(1f32.min((1. / 6.) * *x + 0.5))); Ok(()) }
23 );
24
25element_wise!(leaky_relu, LeakyRelu { alpha: f32 },
26 [f16] => |op, xs| { (tract_linalg::ops().leaky_relu_f16)().run_with_params(xs, f16::from_f32(op.alpha)) },
27 [f32] => |op, xs| { (tract_linalg::ops().leaky_relu_f32)().run_with_params(xs, op.alpha) }
28);