Convert dense ndarray between numeric types. Transforms a dense array from one numeric type to another, preserving the multidimensional structure. Handles dynamic dimensionality efficiently. ## Parameters `array` - Source array with dynamic dimensions ## Type Parameters `T` - Source numeric type `U` - Target floating-point type ## Returns New array with same shape but converted element type
(
array: ArrayBase<OwnedRepr<T>, Dim<IxDynImpl>>,
)
| 530 | /// ## Returns |
| 531 | /// New array with same shape but converted element type |
| 532 | fn convert_array<T, U>( |
| 533 | array: ArrayBase<OwnedRepr<T>, Dim<IxDynImpl>>, |
| 534 | ) -> anyhow::Result<ArrayBase<OwnedRepr<U>, Dim<IxDynImpl>>> |
| 535 | where |
| 536 | T: NumericOps + NumCast + Copy, |
| 537 | U: NumericOps + NumCast + Copy + Float, |
| 538 | { |
| 539 | let shape = array.raw_dim(); // Keep the dynamic dimension |
| 540 | |
| 541 | let (vec, _) = array.into_raw_vec_and_offset(); |
| 542 | |
| 543 | let new_values: Vec<U> = vec.into_iter().map(|x| NumCast::from(x).unwrap()).collect(); |
| 544 | |
| 545 | Ok(ArrayBase::from_shape_vec(shape, new_values)?) |
| 546 | } |
| 547 | |
| 548 | /// Create a Polars DataFrame from a HashMap of numeric vectors. |
| 549 | /// |
nothing calls this directly
no outgoing calls
no test coverage detected