Transpose flat item list that is regarded as a multi-dimensional matrix defined by shape: dest...[k][j][i] = src[i][j][k]...
(src, shape)
| 334 | return ret |
| 335 | |
| 336 | def transpose(src, shape): |
| 337 | """Transpose flat item list that is regarded as a multi-dimensional |
| 338 | matrix defined by shape: dest...[k][j][i] = src[i][j][k]... """ |
| 339 | if not shape: |
| 340 | return src |
| 341 | ndim = len(shape) |
| 342 | sstrides = strides_from_shape(ndim, shape, 1, 'C') |
| 343 | dstrides = strides_from_shape(ndim, shape[::-1], 1, 'C') |
| 344 | dest = [0] * len(src) |
| 345 | for ind in indices(shape): |
| 346 | fr = getindex(ndim, ind, sstrides) |
| 347 | to = getindex(ndim, ind[::-1], dstrides) |
| 348 | dest[to] = src[fr] |
| 349 | return dest |
| 350 | |
| 351 | def _flatten(lst): |
| 352 | """flatten list""" |
no test coverage detected