lasprs 0.6.7

Library for Acoustic Signal Processing (Rust edition, with optional Python bindings via pyo3)
Documentation
//! General math tools that are internally required
//!
//!
use crate::config::*;
use ndarray::{ArrayView1, IntoDimension};
use rand::{rngs::SmallRng, thread_rng, Rng, SeedableRng};
use rand_distr::StandardNormal;
use smallvec::Array;

/// Compute maximum value of an array of float values
pub fn max<T>(arr: ArrayView<Flt, T>) -> Flt
where
    T: ndarray::Dimension,
{
    arr.fold(
        -Flt::INFINITY,
        |acc, new| if *new > acc { *new } else { acc },
    )
}

/// Compute minimum value of an array of float values
pub fn min<T>(arr: ArrayView<Flt, T>) -> Flt
where
    T: ndarray::Dimension,
{
    arr.fold(
        Flt::INFINITY,
        |acc, new| if *new < acc { *new } else { acc },
    )
}

/// Compute maximum absolute value of an array of float values
pub fn maxabs<T>(arr: ArrayView<Flt, T>) -> Flt
where
    T: ndarray::Dimension,
{
    arr.fold(0., |acc, new| if new.abs() > acc { new.abs() } else { acc })
}

///  Generate an array of *PSEUDO* random numbers from the standard normal
///  distribution. Typically used for white noise generation. To be used for
///  noise signals, not for anything that needs to be truly random.
/// 
/// # Args
/// 
/// - `shape` - Shape of the returned array
/// 
pub fn randNormal<Sh, D>(shape: Sh) -> ndarray::Array<Flt,D>
where
    Sh: ShapeBuilder<Dim=D>,
    D: Dimension
{
    // Explicit conversion to Fortran order
    let mut rng = SmallRng::from_entropy();
    let shape = shape.f().into_shape_with_order();
    ArrayBase::from_shape_simple_fn(shape, || rng.sample(StandardNormal))
}