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)
| 346 | return ret |
| 347 | |
| 348 | def transpose(src, shape): |
| 349 | """Transpose flat item list that is regarded as a multi-dimensional |
| 350 | matrix defined by shape: dest...[k][j][i] = src[i][j][k]... """ |
| 351 | if not shape: |
| 352 | return src |
| 353 | ndim = len(shape) |
| 354 | sstrides = strides_from_shape(ndim, shape, 1, 'C') |
| 355 | dstrides = strides_from_shape(ndim, shape[::-1], 1, 'C') |
| 356 | dest = [0] * len(src) |
| 357 | for ind in indices(shape): |
| 358 | fr = getindex(ndim, ind, sstrides) |
| 359 | to = getindex(ndim, ind[::-1], dstrides) |
| 360 | dest[to] = src[fr] |
| 361 | return dest |
| 362 | |
| 363 | def _flatten(lst): |
| 364 | """flatten list""" |
no test coverage detected
searching dependent graphs…