MCPcopy
hub / github.com/tensorflow/tfjs / transposeImpl

Function transposeImpl

tfjs-backend-cpu/src/kernels/Transpose_impl.ts:21–45  ·  view source on GitHub ↗
(
    xVals: TypedArray, xShape: number[], dtype: DataType, perm: number[],
    newShape: number[])

Source from the content-addressed store, hash-verified

19import {util} from '@tensorflow/tfjs-core';
20
21export function transposeImpl(
22 xVals: TypedArray, xShape: number[], dtype: DataType, perm: number[],
23 newShape: number[]): TypedArray {
24 const xRank = xShape.length;
25 const xSize = util.sizeFromShape(xShape);
26 const xStrides = util.computeStrides(xShape);
27 const newStrides = util.computeStrides(newShape);
28
29 const result = util.getTypedArrayFromDType(
30 dtype as NumericDataType, util.sizeFromShape(newShape));
31
32 for (let i = 0; i < xSize; ++i) {
33 const loc = util.indexToLoc(i, xRank, xStrides);
34
35 // Permute location.
36 const newLoc: number[] = new Array(loc.length);
37 for (let i = 0; i < newLoc.length; i++) {
38 newLoc[i] = loc[perm[i]];
39 }
40
41 const newIndex = util.locToIndex(newLoc, xRank, newStrides);
42 result[newIndex] = xVals[i];
43 }
44 return result;
45}

Callers 2

transposeFunction · 0.90
maxFunction · 0.90

Calls 2

indexToLocMethod · 0.80
locToIndexMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…