mod bin_mapper;
mod binning;
mod build;
#[cfg(test)]
mod parity_tests;
mod sample;
pub use bin_mapper::BinMapper;
pub use build::{DatasetInput, DenseData, DenseMatrix, Layout};
pub const GROUP_BIN_BUDGET: u32 = 8192;
#[derive(Debug, Clone, PartialEq)]
pub struct FeatureMeta {
pub name: String,
pub bins: BinMapper,
pub num_bins: u32,
pub group: u32,
pub column: u32,
pub hist_offset: u32,
}
impl FeatureMeta {
pub fn is_trivial(&self) -> bool {
self.num_bins == 0
}
pub fn is_categorical(&self) -> bool {
matches!(self.bins, BinMapper::Categorical { .. })
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct FeatureGroup {
pub features: Vec<usize>,
pub row_stride: u32,
pub hist_offset: u32,
pub total_bins: u32,
pub data: Vec<u8>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct BinnedDataset {
pub num_rows: usize,
pub row_offset: u64,
pub features: Vec<FeatureMeta>,
pub groups: Vec<FeatureGroup>,
pub total_bins: usize,
pub label: Vec<f32>,
pub weight: Option<Vec<f32>>,
pub query_boundaries: Option<Vec<u32>>,
}
impl BinnedDataset {
pub fn num_queries(&self) -> usize {
self.query_boundaries.as_ref().map_or(0, |b| b.len() - 1)
}
#[inline]
pub fn bin(&self, feature: usize, row: usize) -> u8 {
let meta = &self.features[feature];
let group = &self.groups[meta.group as usize];
group.data[row * group.row_stride as usize + meta.column as usize]
}
}