Convert CSC sparse matrix between numeric types. Transforms a Compressed Sparse Column matrix from one numeric type to another while preserving the sparse structure. Similar to CSR conversion but for column-major format. ## Parameters `matrix` - Source CSC matrix to convert ## Type Parameters `T` - Source numeric type (e.g., i32, u32) `U` - Target floating-point type (f32 or f64) ## Returns Ne
(matrix: CscMatrix<T>)
| 498 | /// ## Returns |
| 499 | /// New CSC matrix with converted values in target type |
| 500 | fn convert_csc_sparse_matrix<T, U>(matrix: CscMatrix<T>) -> anyhow::Result<CscMatrix<U>> |
| 501 | where |
| 502 | T: NumericOps + NumCast + Copy, // Base numeric traits for source |
| 503 | U: NumericOps + NumCast + Copy + Float, // Ensure target is float (f32/f64) |
| 504 | { |
| 505 | let nrows = matrix.nrows(); |
| 506 | let ncols = matrix.ncols(); |
| 507 | let (col_offsets, row_indices, values) = matrix.disassemble(); |
| 508 | |
| 509 | let new_values: Vec<U> = values |
| 510 | .into_iter() |
| 511 | .map(|x| NumCast::from(x).unwrap()) |
| 512 | .collect(); |
| 513 | |
| 514 | CscMatrix::try_from_csc_data(nrows, ncols, col_offsets, row_indices, new_values) |
| 515 | .map_err(|e| anyhow::anyhow!("Failed to create CSC matrix: {}", e)) |
| 516 | } |
| 517 | |
| 518 | /// Convert dense ndarray between numeric types. |
| 519 | /// |
nothing calls this directly
no outgoing calls
no test coverage detected