MCPcopy Index your code
hub / github.com/tensorflow/tfjs / indexToLoc

Method indexToLoc

tfjs-core/src/tensor.ts:133–146  ·  view source on GitHub ↗
(index: number)

Source from the content-addressed store, hash-verified

131 }
132
133 indexToLoc(index: number): number[] {
134 if (this.rank === 0) {
135 return [];
136 } else if (this.rank === 1) {
137 return [index];
138 }
139 const locs: number[] = new Array(this.shape.length);
140 for (let i = 0; i < locs.length - 1; ++i) {
141 locs[i] = Math.floor(index / this.strides[i]);
142 index -= locs[i] * this.strides[i];
143 }
144 locs[locs.length - 1] = index;
145 return locs;
146 }
147
148 get rank() {
149 return this.shape.length;

Callers 14

reverseFunction · 0.95
mirrorPadFunction · 0.80
stridedSliceImplFunction · 0.80
gatherNdImplFunction · 0.80
gatherV2ImplFunction · 0.80
tileImplFunction · 0.80
padV2Function · 0.80
validateIndicesFunction · 0.80
sliceImplFunction · 0.80
transposeImplFunction · 0.80

Calls 1

floorMethod · 0.80

Tested by

no test coverage detected