MCPcopy Create free account
hub / github.com/MegEngine/MegFlow / uget_slice

Function uget_slice

flow-rs/src/helper/python.rs:34–46  ·  view source on GitHub ↗
(py: Python, pyobject: &PyAny)

Source from the content-addressed store, hash-verified

32}
33
34pub fn uget_slice<'a, T: Element>(py: Python, pyobject: &PyAny) -> PyResult<SliceGuard<'a, T>> {
35 let array: &PyArrayDyn<T> = pyobject.extract()?;
36 unsafe {
37 let slice = array
38 .as_slice()
39 .map_err(|_| pyo3::exceptions::PyTypeError::new_err("not contiguous"))?;
40 let slice = std::slice::from_raw_parts(slice.as_ptr(), slice.len());
41 Ok(SliceGuard {
42 slice,
43 _ref: pyobject.into_py(py),
44 })
45 }
46}

Callers 2

analyzeFunction · 0.85
analyzeFunction · 0.85

Calls 2

as_ptrMethod · 0.80
lenMethod · 0.45

Tested by

no test coverage detected