| 109 | } |
| 110 | |
| 111 | static int |
| 112 | array_strides_set(PyArrayObject *self, PyObject *obj, void *NPY_UNUSED(ignored)) |
| 113 | { |
| 114 | PyArray_Dims newstrides = {NULL, -1}; |
| 115 | PyArrayObject *new; |
| 116 | npy_intp numbytes = 0; |
| 117 | npy_intp offset = 0; |
| 118 | npy_intp lower_offset = 0; |
| 119 | npy_intp upper_offset = 0; |
| 120 | Py_buffer view; |
| 121 | |
| 122 | if (obj == NULL) { |
| 123 | PyErr_SetString(PyExc_AttributeError, |
| 124 | "Cannot delete array strides"); |
| 125 | return -1; |
| 126 | } |
| 127 | if (!PyArray_OptionalIntpConverter(obj, &newstrides) || |
| 128 | newstrides.len == -1) { |
| 129 | PyErr_SetString(PyExc_TypeError, "invalid strides"); |
| 130 | return -1; |
| 131 | } |
| 132 | if (newstrides.len != PyArray_NDIM(self)) { |
| 133 | PyErr_Format(PyExc_ValueError, "strides must be " \ |
| 134 | " same length as shape (%d)", PyArray_NDIM(self)); |
| 135 | goto fail; |
| 136 | } |
| 137 | new = self; |
| 138 | while(PyArray_BASE(new) && PyArray_Check(PyArray_BASE(new))) { |
| 139 | new = (PyArrayObject *)(PyArray_BASE(new)); |
| 140 | } |
| 141 | /* |
| 142 | * Get the available memory through the buffer interface on |
| 143 | * PyArray_BASE(new) or if that fails from the current new |
| 144 | */ |
| 145 | if (PyArray_BASE(new) && |
| 146 | PyObject_GetBuffer(PyArray_BASE(new), &view, PyBUF_SIMPLE) >= 0) { |
| 147 | offset = PyArray_BYTES(self) - (char *)view.buf; |
| 148 | numbytes = view.len + offset; |
| 149 | PyBuffer_Release(&view); |
| 150 | } |
| 151 | else { |
| 152 | PyErr_Clear(); |
| 153 | offset_bounds_from_strides(PyArray_ITEMSIZE(new), PyArray_NDIM(new), |
| 154 | PyArray_DIMS(new), PyArray_STRIDES(new), |
| 155 | &lower_offset, &upper_offset); |
| 156 | |
| 157 | offset = PyArray_BYTES(self) - (PyArray_BYTES(new) + lower_offset); |
| 158 | numbytes = upper_offset - lower_offset; |
| 159 | } |
| 160 | |
| 161 | /* numbytes == 0 is special here, but the 0-size array case always works */ |
| 162 | if (!PyArray_CheckStrides(PyArray_ITEMSIZE(self), PyArray_NDIM(self), |
| 163 | numbytes, offset, |
| 164 | PyArray_DIMS(self), newstrides.ptr)) { |
| 165 | PyErr_SetString(PyExc_ValueError, "strides is not "\ |
| 166 | "compatible with available memory"); |
| 167 | goto fail; |
| 168 | } |
nothing calls this directly
no test coverage detected