onnx-export-rs 0.1.0

Export canonical Rust machine-learning models to ONNX
Documentation
use ndarray::Array1;

/// The coefficients and intercept needed for linear-regression inference.
///
/// ```
/// use ndarray::array;
/// use onnx_export_rs::canonical::LinearModelWeights;
/// let model = LinearModelWeights::new(array![2.0, -1.0], 0.5);
/// assert_eq!(model.n_features(), 2);
/// ```
#[derive(Clone, Debug, PartialEq)]
pub struct LinearModelWeights {
    /// One coefficient per input feature.
    pub coefficients: Array1<f64>,
    /// Scalar bias.
    pub intercept: f64,
}

impl LinearModelWeights {
    /// Constructs linear model weights.
    #[must_use]
    pub const fn new(coefficients: Array1<f64>, intercept: f64) -> Self {
        Self {
            coefficients,
            intercept,
        }
    }

    /// Returns the required number of input features.
    #[must_use]
    pub fn n_features(&self) -> usize {
        self.coefficients.len()
    }
}