(py: Python<'py>, array: *mut PyArrayObject)
| 394 | } |
| 395 | |
| 396 | fn 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 | |
| 432 | fn gcd_strides(array: *mut PyArrayObject) -> isize { |
| 433 | let nd = unsafe { (*array).nd } as usize; |
no outgoing calls