MCPcopy Create free account
hub / github.com/SingleRust/SingleRust / arr1_conversion

Function arr1_conversion

src/memory/utils/mod.rs:699–711  ·  view source on GitHub ↗

Convert a 1D array between numeric types. Type-safe conversion for 1D arrays, useful for converting vectors of statistics, scores, or other single-dimensional data between numeric types. ## Parameters `array1` - Source 1D array to convert ## Type Parameters `M` - Source numeric type `T` - Target numeric type ## Returns New 1D array with same length but converted element type ## Usage ```rust,

(array1: Array1<M>)

Source from the content-addressed store, hash-verified

697/// - Type compatibility between library interfaces
698/// - Converting scores or weights for storage
699pub fn arr1_conversion<M, T>(array1: Array1<M>) -> anyhow::Result<Array1<T>>
700where
701 M: Num + Copy + num_traits::ToPrimitive,
702 T: Num + NumCast + Clone,
703{
704 let mut result = Array1::zeros(array1.dim());
705
706 for (target, &source) in result.iter_mut().zip(array1.iter()) {
707 *target = T::from(source).ok_or_else(|| anyhow!("Failed to convert value"))?;
708 }
709
710 Ok(result)
711}

Callers 1

run_pca_sparse_maskedFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected