#[derive(Debug)]
pub struct BatchNormTask<'buffers, Element> {
input: &'buffers [Element],
scale: &'buffers [Element],
shift: &'buffers [Element],
epsilon: Element,
batch: usize,
features: usize,
}
impl<'buffers, Element> BatchNormTask<'buffers, Element> {
pub fn new(
input: &'buffers [Element],
scale: &'buffers [Element],
shift: &'buffers [Element],
epsilon: Element,
batch: usize,
features: usize,
) -> Self {
assert!(
batch > 0 && features > 0,
"a batch-norm task needs non-empty extents"
);
assert_eq!(
input.len(),
batch * features,
"the input slice does not span its {batch} x {features} matrix"
);
assert_eq!(
scale.len(),
features,
"the scale slice does not span its {features} features"
);
assert_eq!(
shift.len(),
features,
"the shift slice does not span its {features} features"
);
Self {
input,
scale,
shift,
epsilon,
batch,
features,
}
}
pub fn input(&self) -> &'buffers [Element] {
self.input
}
pub fn scale(&self) -> &'buffers [Element] {
self.scale
}
pub fn shift(&self) -> &'buffers [Element] {
self.shift
}
pub fn epsilon(&self) -> &Element {
&self.epsilon
}
pub fn batch(&self) -> usize {
self.batch
}
pub fn features(&self) -> usize {
self.features
}
}
#[derive(Debug)]
pub struct Normalized<Element> {
pub output: Vec<Element>,
pub mean: Vec<Element>,
pub variance: Vec<Element>,
}