INNER CODE UNIT · Rust
array_type_err
RyanCodrai/turbovec · turbovec-python/src/lib.rs:46
fn array_type_err(name: &str, expected: &str, obj: &Bound<'_, PyAny>) -> PyErr {
pyo3::exceptions::PyTypeError::new_err(format!(
"{name} must be a {expected} array, got {}",
array_desc(obj),
))
}
/// Extract a 2-D float32 array, replacing pyo3's opaque downcast error
/// ("'ndarray' object cannot be cast as 'ndarray'") with one that names
/// the argument and states expected vs got dtype/ndim.
fn extract_f32_2d<'py>(
name: &str,
obj: &Bound<'py, PyAny>,
) -> PyResult<PyReadonlyArray2<'py, f32>> {
obj.extract()
.map_err(|_| array_type_err(name, "2-D float32", obj))
}