1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
   Appellation: params <mod>
   Contrib: FL03 <jo3mccain@icloud.com>
*/
//! # Parameters
//!
//! ## Overview
//!
pub use self::{kinds::*, parameter::*};

pub(crate) mod kinds;
pub(crate) mod parameter;

pub mod store;

mod impls {
    #[cfg(feature = "rand")]
    mod impl_rand;
}

pub trait Param {
    type Key;
    type Value;
}

pub trait Params {
    type Store;
}

pub(crate) mod prelude {
    pub use super::kinds::ParamKind;
    pub use super::parameter::Parameter;
    pub use super::store::ParamStore;
    pub use super::{Param, Params};
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::linarr;
    use ndarray::linalg::Dot;
    use ndarray::prelude::{Ix1, Ix2};

    #[test]
    fn test_parameter() {
        let value = linarr::<f64, Ix2>((3, 3)).unwrap();
        let mut param = Parameter::<f64, Ix2>::new((10, 1), ParamKind::Bias, "bias");
        param.set_params(value.clone());

        assert_eq!(param.kind(), &ParamKind::Bias);
        assert_eq!(param.name(), "bias");

        let x = linarr::<f64, Ix1>((3,)).unwrap();
        assert_eq!(param.dot(&x), value.dot(&x));
    }
}