bixverse-core 0.9.4

Core numerics for bixverse: sparse structures, linear algebra, statistics, SIMD and clustering.
Documentation
//! All type of utility modules with shared code that does not fit fully into
//! other modules. Has assertion macros, structures designed for the heap,
//! traits and their implementations, R <> Rust interface functions and more.

pub mod gemm;
pub mod heap_structures;
pub mod macros;
pub mod matrix_utils;
pub mod simd;
pub mod traits;
pub mod vec_utils;

use faer::Par;
use rustc_hash::{FxBuildHasher, FxHashSet};
use std::num::NonZeroUsize;
use std::sync::OnceLock;

///////////////////
// General utils //
///////////////////

/// String slice to FxHashSet
///
/// ### Params
///
/// * `x` - The string slice.
///
/// ### Returns
///
/// A HashSet with borrowed String values
pub fn string_vec_to_set(x: &[String]) -> FxHashSet<&String> {
    let mut set = FxHashSet::with_capacity_and_hasher(x.len(), FxBuildHasher);
    for s in x {
        set.insert(s);
    }
    set
}

/// Returns the faer parallelism enum (all available cores via Rayon).
#[inline]
pub fn faer_parallelism() -> Par {
    static N_THREADS: OnceLock<NonZeroUsize> = OnceLock::new();
    Par::Rayon(*N_THREADS.get_or_init(|| std::thread::available_parallelism().unwrap()))
}