MCPcopy Index your code
hub / github.com/RustPython/RustPython / strides_from_shape

Function strides_from_shape

Lib/test/test_buffer.py:272–285  ·  view source on GitHub ↗

Calculate strides of a contiguous array. Layout is 'C' or 'F' (Fortran).

(ndim, shape, itemsize, layout)

Source from the content-addressed store, hash-verified

270 return x
271
272def strides_from_shape(ndim, shape, itemsize, layout):
273 """Calculate strides of a contiguous array. Layout is 'C' or
274 'F' (Fortran)."""
275 if ndim == 0:
276 return ()
277 if layout == 'C':
278 strides = list(shape[1:]) + [itemsize]
279 for i in range(ndim-2, -1, -1):
280 strides[i] *= strides[i+1]
281 else:
282 strides = [itemsize] + list(shape[:-1])
283 for i in range(1, ndim):
284 strides[i] *= strides[i-1]
285 return strides
286
287def _ca(items, s):
288 """Convert flat item list to the nested list representation of a

Callers 3

transposeFunction · 0.85
test_ndarray_multidimMethod · 0.85

Calls 1

listClass · 0.85

Tested by

no test coverage detected