ndarray-glm 0.1.0

Performs regression for generalized linear models using IRLS on data stored in arrays.
Documentation
//! numerical trait constraints
use std::cmp;

use ndarray::NdFloat;
use ndarray_linalg::Lapack;

// NdFloat covers everything we need except Lapack, which is an ndarray_linalg trait enabling
// linear algebra.
pub trait Float: NdFloat + Lapack {
    // Return 1/2 = 0.5
    fn half() -> Self;

    // Return 2.0
    fn two() -> Self;

    /// A more conventional sign function, because the built-in signum treats signed zeros as
    /// positive and negative: <https://github.com/rust-lang/rust/issues/57543>
    fn sign(self) -> Self {
        if self == Self::zero() {
            Self::zero()
        } else {
            self.signum()
        }
    }

    /// total_cmp is not implemented in num_traits, so implement it here.
    fn total_cmp(&self, other: &Self) -> cmp::Ordering;
}

impl Float for f32 {
    fn half() -> Self {
        0.5
    }

    fn two() -> Self {
        2.0
    }

    fn total_cmp(&self, other: &Self) -> cmp::Ordering {
        self.total_cmp(other)
    }
}
impl Float for f64 {
    fn half() -> Self {
        0.5
    }

    fn two() -> Self {
        2.0
    }

    fn total_cmp(&self, other: &Self) -> cmp::Ordering {
        self.total_cmp(other)
    }
}