ArrayStatCompat

Trait ArrayStatCompat 

Source
pub trait ArrayStatCompat<T> {
    // Required methods
    fn mean_or(&self, default: T) -> T;
    fn var_or(&self, ddof: T, default: T) -> T;
    fn std_or(&self, ddof: T, default: T) -> T;
}
Expand description

Compatibility extensions for ndarray statistical operations

This trait provides stable statistical operation APIs that remain consistent across ndarray version updates, implementing the SciRS2 POLICY principle of isolating external dependency changes to scirs2-core only.

§Rationale

ndarray’s statistical methods have changed across versions:

  • v0.16: .mean() returns Option<T>
  • v0.17: .mean() returns T directly (may be NaN for invalid operations)

This trait provides a consistent API regardless of the underlying ndarray version.

§Example

use scirs2_core::ndarray::{Array1, compat::ArrayStatCompat};

let data = Array1::from(vec![1.0, 2.0, 3.0]);
let mean = data.mean_or(0.0);  // Stable API across ndarray versions

Required Methods§

Source

fn mean_or(&self, default: T) -> T

Compute the mean of the array, returning a default value if computation fails

This method abstracts over ndarray version differences:

  • For ndarray 0.16: Unwraps the Option, using default if None
  • For ndarray 0.17+: Returns the value, using default if NaN
Source

fn var_or(&self, ddof: T, default: T) -> T

Compute the variance with optional default

Source

fn std_or(&self, ddof: T, default: T) -> T

Compute the standard deviation with optional default

Implementors§

Source§

impl<T, S, D> ArrayStatCompat<T> for ArrayBase<S, D>
where T: Float + FromPrimitive, S: Data<Elem = T>, D: Dimension,