3 #include <torch/csrc/python_headers.h> 6 #if PY_VERSION_HEX < 0x03060100 || defined(PYPY_VERSION) 14 __PySlice_Unpack(PyObject *_r,
15 Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step)
17 PySliceObject *r = (PySliceObject*)_r;
21 static_assert(PY_SSIZE_T_MIN + 1 <= -PY_SSIZE_T_MAX,
"Build failed");
23 if (r->step == Py_None) {
27 if (!_PyEval_SliceIndex(r->step, step))
return -1;
29 PyErr_SetString(PyExc_ValueError,
30 "slice step cannot be zero");
38 if (*step < -PY_SSIZE_T_MAX)
39 *step = -PY_SSIZE_T_MAX;
42 if (r->start == Py_None) {
43 *start = *step < 0 ? PY_SSIZE_T_MAX : 0;
46 if (!_PyEval_SliceIndex(r->start, start))
return -1;
49 if (r->stop == Py_None) {
50 *stop = *step < 0 ? PY_SSIZE_T_MIN : PY_SSIZE_T_MAX;
53 if (!_PyEval_SliceIndex(r->stop, stop))
return -1;
59 #define THPUtils_unpackSlice(SLICE, START, STOP, STEP) \ 60 (__PySlice_Unpack(SLICE, START, STOP, STEP) == 0) 62 #define THPUtils_unpackSlice(SLICE, START, STOP, STEP) \ 63 (PySlice_Unpack(SLICE, START, STOP, STEP) == 0) 67 #if PY_VERSION_HEX >= 0x03020000 68 #define THPUtils_parseSlice(SLICE, LEN, START, STOP, LENGTH, STEP) \ 69 (PySlice_GetIndicesEx(SLICE, LEN, START, STOP, LENGTH, STEP) == 0) 71 #define THPUtils_parseSlice(SLICE, LEN, START, STOP, LENGTH, STEP) \ 72 (PySlice_GetIndicesEx((PySliceObject*)SLICE, LEN, START, STOP, LENGTH, STEP) == 0)