(
csr: &CsrMatrix<T>,
shape: Shape,
row_selection: &SelectInfoElem,
col_selection: &SelectInfoElem,
)
| 359 | } |
| 360 | |
| 361 | fn convert_to_array_f64_csr_selected<T: NumericOps>( |
| 362 | csr: &CsrMatrix<T>, |
| 363 | shape: Shape, |
| 364 | row_selection: &SelectInfoElem, |
| 365 | col_selection: &SelectInfoElem, |
| 366 | ) -> anyhow::Result<Array2<f64>> { |
| 367 | let row_indices = select_info_elem_to_indices(row_selection, shape[0])?; |
| 368 | let col_indices = select_info_elem_to_indices(col_selection, shape[1])?; |
| 369 | let mut dense = Array2::<f64>::zeros((row_indices.len(), col_indices.len())); |
| 370 | |
| 371 | // Create a mapping from original column indices to output column indices |
| 372 | let col_map: HashMap<usize, usize> = col_indices |
| 373 | .iter() |
| 374 | .enumerate() |
| 375 | .map(|(i, &col)| (col, i)) |
| 376 | .collect(); |
| 377 | |
| 378 | for (out_row, &row) in row_indices.iter().enumerate() { |
| 379 | if row < csr.nrows() { |
| 380 | let row_start = csr.row_offsets()[row]; |
| 381 | let row_end = csr.row_offsets()[row + 1]; |
| 382 | for (&col, &value) in csr.col_indices()[row_start..row_end] |
| 383 | .iter() |
| 384 | .zip(csr.values()[row_start..row_end].iter()) |
| 385 | { |
| 386 | if let Some(&out_col) = col_map.get(&col) { |
| 387 | dense[[out_row, out_col]] = NumCast::from(value) |
| 388 | .ok_or_else(|| anyhow!("Failed to convert value to f64"))?; |
| 389 | } |
| 390 | } |
| 391 | } |
| 392 | } |
| 393 | Ok(dense) |
| 394 | } |
| 395 | |
| 396 | fn convert_to_array_f64_csc_selected<T: NumericOps>( |
| 397 | csc: &CscMatrix<T>, |
nothing calls this directly
no test coverage detected