MCPcopy Index your code
hub / github.com/python/cpython / strides_from_shape

Function strides_from_shape

Lib/test/test_buffer.py:284–297  ·  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

282 return x
283
284def strides_from_shape(ndim, shape, itemsize, layout):
285 """Calculate strides of a contiguous array. Layout is 'C' or
286 'F' (Fortran)."""
287 if ndim == 0:
288 return ()
289 if layout == 'C':
290 strides = list(shape[1:]) + [itemsize]
291 for i in range(ndim-2, -1, -1):
292 strides[i] *= strides[i+1]
293 else:
294 strides = [itemsize] + list(shape[:-1])
295 for i in range(1, ndim):
296 strides[i] *= strides[i-1]
297 return strides
298
299def _ca(items, s):
300 """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

Used in the wild real call sites across dependent graphs

searching dependent graphs…