use crate::activations::ActivationKind;
use crate::layers::{LayerDesc, LayerError, LayerSpec};
pub fn chain_widths(layers: &[LayerSpec], out: &mut [usize]) -> Result<usize, LayerError> {
if layers.is_empty() {
return Err(LayerError::EmptyPlan);
}
let needed = layers.len() + 1;
if out.len() < needed {
return Err(LayerError::BufferTooSmall);
}
out[0] = layers[0].input_size();
for i in 0..layers.len() {
out[i + 1] = layers[i].output_size();
}
Ok(needed)
}
pub fn desc(
input_size: usize,
output_size: usize,
weight_offset: usize,
bias_offset: usize,
activation: ActivationKind,
) -> Result<LayerSpec, LayerError> {
if input_size == 0 || output_size == 0 {
return Err(LayerError::InvalidShape);
}
Ok(LayerSpec::Dense(LayerDesc {
input_size,
output_size,
weight_offset,
bias_offset,
activation,
}))
}