Return a contiguous span of N-D array data. Parameters ---------- shape : tuple strides : tuple itemsize : int Specify array shape data Returns ------- start, end : int The span end points.
(shape, strides, itemsize)
| 159 | |
| 160 | |
| 161 | def get_contiguous_span(shape, strides, itemsize): |
| 162 | """ |
| 163 | Return a contiguous span of N-D array data. |
| 164 | |
| 165 | Parameters |
| 166 | ---------- |
| 167 | shape : tuple |
| 168 | strides : tuple |
| 169 | itemsize : int |
| 170 | Specify array shape data |
| 171 | |
| 172 | Returns |
| 173 | ------- |
| 174 | start, end : int |
| 175 | The span end points. |
| 176 | """ |
| 177 | if not strides: |
| 178 | start = 0 |
| 179 | end = itemsize * product(shape) |
| 180 | else: |
| 181 | start = 0 |
| 182 | end = itemsize |
| 183 | for i, dim in enumerate(shape): |
| 184 | if dim == 0: |
| 185 | start = end = 0 |
| 186 | break |
| 187 | stride = strides[i] |
| 188 | if stride > 0: |
| 189 | end += stride * (dim - 1) |
| 190 | elif stride < 0: |
| 191 | start += stride * (dim - 1) |
| 192 | if end - start != itemsize * product(shape): |
| 193 | raise ValueError('array data is non-contiguous') |
| 194 | return start, end |
| 195 | |
| 196 | |
| 197 | def find_free_port(): |