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

Function arr2_conversion

src/memory/utils/mod.rs:659–671  ·  view source on GitHub ↗

Convert a 2D array between numeric types. Type-safe conversion between different numeric types for 2D arrays, commonly used when interfacing between different libraries or precision requirements. ## Parameters `array2` - Source 2D array to convert ## Type Parameters `M` - Source numeric type `T` - Target numeric type ## Returns New 2D array with same dimensions but converted element type ## U

(array2: Array2<M>)

Source from the content-addressed store, hash-verified

657/// - Interfacing with external libraries requiring specific types
658/// - Preparing data for storage or analysis pipelines
659pub fn arr2_conversion<M, T>(array2: Array2<M>) -> anyhow::Result<Array2<T>>
660where
661 M: Num + Copy + num_traits::ToPrimitive,
662 T: Num + NumCast + Clone,
663{
664 let mut result = Array2::zeros(array2.dim());
665
666 for (target, &source) in result.iter_mut().zip(array2.iter()) {
667 *target = T::from(source).ok_or_else(|| anyhow!("Failed to convert value"))?;
668 }
669
670 Ok(result)
671}
672
673/// Convert a 1D array between numeric types.
674///

Callers 1

run_pca_sparse_maskedFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected