numcodecs_python/
utils.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
use numpy::PyUntypedArray;
use pyo3::{prelude::*, sync::GILOnceCell};

pub fn numpy_asarray<'py>(
    py: Python<'py>,
    a: Borrowed<'_, 'py, PyAny>,
) -> Result<Bound<'py, PyUntypedArray>, PyErr> {
    static AS_ARRAY: GILOnceCell<Py<PyAny>> = GILOnceCell::new();

    let as_array = AS_ARRAY.import(py, "numpy", "asarray")?;

    as_array.call1((a,))?.extract()
}