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>)
| 657 | /// - Interfacing with external libraries requiring specific types |
| 658 | /// - Preparing data for storage or analysis pipelines |
| 659 | pub fn arr2_conversion<M, T>(array2: Array2<M>) -> anyhow::Result<Array2<T>> |
| 660 | where |
| 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 | /// |
no outgoing calls
no test coverage detected