aocl-data-analytics 0.8.0

Safe Rust wrappers for AOCL-DA (data analytics, statistics, ML primitives)
Documentation
//! `Pca::transform`: `n_components` must cover the components the model was fitted with.
use aocl_data_analytics::*;

// 6 x 4, column-major, full rank.
const X: [f64; 24] = [
    1.0, 2.0, 3.0, 4.0, 5.0, 7.0, 2.0, 1.0, 4.0, 3.0, 8.0, 5.0, 9.0, 4.0, 1.0, 6.0, 2.0, 3.0, 5.0,
    9.0, 2.0, 1.0, 7.0, 4.0,
];

fn transform(fitted: usize, asked: usize) -> aocl_error::Result<()> {
    let mut m = Pca::new(fitted).unwrap();
    m.fit(6, 4, &X).unwrap();
    let mut out = vec![0.0; 6 * asked];
    m.transform(6, 4, &X, asked, &mut out)
}

#[test]
fn fitted_count_is_accepted() {
    transform(3, 3).unwrap();
}

#[test]
fn fewer_than_fitted_is_refused() {
    let r = transform(3, 1);
    assert!(
        matches!(r, Err(aocl_error::Error::InvalidArgument(_))),
        "{r:?}"
    );
}