sparseglm/datasets/
impl_datasets.rs

1use super::{csc_array::CSCArray, AsMultiTargets, DatasetBase, DesignMatrix};
2use crate::Float;
3use ndarray::{ArrayBase, Data, Ix2};
4
5/// This implementation block provides a method for the creation of datasets
6/// from dense matrices.
7impl<F: Float, D: Data<Elem = F>, T: AsMultiTargets> From<(ArrayBase<D, Ix2>, T)>
8    for DatasetBase<ArrayBase<D, Ix2>, T>
9{
10    fn from(data: (ArrayBase<D, Ix2>, T)) -> Self {
11        DatasetBase {
12            design_matrix: data.0,
13            targets: data.1,
14        }
15    }
16}
17
18/// This implementation block provides a method for the creation of datasets
19/// from sparse matrices.
20impl<'a, F: Float, T: AsMultiTargets> From<(CSCArray<'a, F>, T)>
21    for DatasetBase<CSCArray<'a, F>, T>
22{
23    fn from(data: (CSCArray<'a, F>, T)) -> Self {
24        DatasetBase {
25            design_matrix: data.0,
26            targets: data.1,
27        }
28    }
29}
30
31/// This implementation block provides methods to get record and target objects
32/// from the dataset.
33impl<DM: DesignMatrix, T: AsMultiTargets> DatasetBase<DM, T> {
34    /// This method instantiates a new dataset from a design matrix and targets.
35    pub fn new(design_matrix: DM, targets: T) -> DatasetBase<DM, T> {
36        DatasetBase {
37            design_matrix,
38            targets,
39        }
40    }
41
42    /// This method is a getter for the targets.
43    pub fn targets(&self) -> &T {
44        &self.targets
45    }
46
47    /// This method is a getter for the design matrix.
48    pub fn design_matrix(&self) -> &DM {
49        &self.design_matrix
50    }
51}