xcell-rust 0.1.0

Pure-Rust port of xCell (Aran et al. 2017) cell-type enrichment — ssGSEA, spillover-corrected — validated for numeric parity against the R xCell package. Built on gsva-rust.
Documentation
//! Parallelism helper — the single place the `parallel`/serial split lives.
//!
//! With the default `parallel` feature this dispatches to rayon over the
//! independent sample axis: each sample's spillover NNLS is solved on its own
//! unit of work. With `--no-default-features` it is a plain serial loop and the
//! crate pulls no parallelism dependency. (The ssGSEA enrichment stage
//! parallelizes inside `gsva` via the forwarded `gsva-rust/parallel` feature.)
//!
//! The parallel axis only ever reorders *independent* units of work — each
//! sample's NNLS is deterministic and self-contained, and results are written
//! back in index order — so the output is **bit-identical** to the serial build
//! and to R, never an approximation.

/// Map `f` over `0..n`, returning the results in index order.
///
/// Parallel over the range when the `parallel` feature is enabled; otherwise a
/// serial `map().collect()`.
#[cfg(feature = "parallel")]
pub(crate) fn map_collect<T, F>(n: usize, f: F) -> Vec<T>
where
    F: Fn(usize) -> T + Sync + Send,
    T: Send,
{
    use rayon::prelude::*;
    (0..n).into_par_iter().map(f).collect()
}

/// Map `f` over `0..n`, returning the results in index order (serial fallback).
#[cfg(not(feature = "parallel"))]
pub(crate) fn map_collect<T, F>(n: usize, f: F) -> Vec<T>
where
    F: Fn(usize) -> T,
{
    (0..n).map(f).collect()
}