MCPcopy Create free account
hub / github.com/PyO3/rust-numpy / data_range

Function data_range

src/borrow/shared.rs:396–430  ·  view source on GitHub ↗
(py: Python<'py>, array: *mut PyArrayObject)

Source from the content-addressed store, hash-verified

394}
395
396fn data_range<'py>(py: Python<'py>, array: *mut PyArrayObject) -> (*mut c_char, *mut c_char) {
397 let nd = unsafe { (*array).nd } as usize;
398 let data = unsafe { (*array).data };
399
400 if nd == 0 {
401 return (data, data);
402 }
403
404 let shape = unsafe { from_raw_parts((*array).dimensions as *mut usize, nd) };
405 let strides = unsafe { from_raw_parts((*array).strides, nd) };
406
407 let itemsize = unsafe { PyDataType_ELSIZE(py, (*array).descr) } as isize;
408
409 let mut start = 0;
410 let mut end = 0;
411
412 if shape.iter().all(|dim| *dim != 0) {
413 for (&dim, &stride) in shape.iter().zip(strides) {
414 let offset = (dim - 1) as isize * stride;
415
416 if offset >= 0 {
417 end += offset;
418 } else {
419 start += offset;
420 }
421 }
422
423 end += itemsize;
424 }
425
426 let start = unsafe { data.offset(start) };
427 let end = unsafe { data.offset(end) };
428
429 (start, end)
430}
431
432fn gcd_strides(array: *mut PyArrayObject) -> isize {
433 let nd = unsafe { (*array).nd } as usize;

Callers 9

borrow_keyFunction · 0.85
without_base_objectFunction · 0.85
with_base_objectFunction · 0.85
view_without_base_objectFunction · 0.85
view_with_base_objectFunction · 0.85

Calls

no outgoing calls

Tested by 8

without_base_objectFunction · 0.68
with_base_objectFunction · 0.68
view_without_base_objectFunction · 0.68
view_with_base_objectFunction · 0.68