Skip to main content

tenflowers_dataset/statistics/
extensions.rs

1//! Extension traits for dataset statistics
2//!
3//! This module provides convenient trait extensions that allow datasets
4//! to compute statistics directly via method calls.
5
6use crate::Dataset;
7use tenflowers_core::Result;
8
9use super::computation::DatasetStatisticsComputer;
10use super::core::{DatasetStats, StatisticsConfig};
11
12/// Extension trait for Dataset to add statistics computation
13pub trait DatasetStatisticsExt<T> {
14    /// Compute statistics with default configuration
15    fn compute_statistics(&self) -> Result<DatasetStats<T>>;
16
17    /// Compute statistics with custom configuration
18    fn compute_statistics_with_config(&self, config: StatisticsConfig) -> Result<DatasetStats<T>>;
19}
20
21impl<T, D> DatasetStatisticsExt<T> for D
22where
23    T: Clone
24        + Default
25        + scirs2_core::numeric::Zero
26        + scirs2_core::numeric::Float
27        + std::fmt::Debug
28        + Send
29        + Sync
30        + 'static,
31    D: Dataset<T>,
32{
33    fn compute_statistics(&self) -> Result<DatasetStats<T>> {
34        DatasetStatisticsComputer::compute(self, StatisticsConfig::default())
35    }
36
37    fn compute_statistics_with_config(&self, config: StatisticsConfig) -> Result<DatasetStats<T>> {
38        DatasetStatisticsComputer::compute(self, config)
39    }
40}