coeus-nn 0.14.0

Neural-network layers and operators for Coeus.
Documentation
use coeus_autograd::Var;
use coeus_core::Float;
use coeus_tensor::Tensor;

/// Initialize weights with a constant value.
pub fn constant<T: Float + coeus_core::FloatElement, B: coeus_ops::BackendOps<T> + Default>(
    weight: &mut Var<T, B>,
    val: f64,
) -> Result<(), B::Error> {
    let shape = weight.tensor.shape_cloned();
    weight.tensor = Tensor::full_on(
        shape,
        coeus_core::FloatElement::from_f64(val),
        &B::default(),
    )?;
    Ok(())
}

/// Initialize weights with zeros.
pub fn zeros<T: Float, B: coeus_ops::BackendOps<T> + Default>(
    weight: &mut Var<T, B>,
) -> Result<(), B::Error> {
    let shape = weight.tensor.shape_cloned();
    weight.tensor = Tensor::zeros_on(shape, &B::default())?;
    Ok(())
}

/// Initialize weights with ones.
pub fn ones<T: Float, B: coeus_ops::BackendOps<T> + Default>(
    weight: &mut Var<T, B>,
) -> Result<(), B::Error> {
    let shape = weight.tensor.shape_cloned();
    weight.tensor = Tensor::ones_on(shape, &B::default())?;
    Ok(())
}