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

Function stridedSliceImpl

tfjs-backend-cpu/src/kernels/StridedSlice_impl.ts:20–36  ·  view source on GitHub ↗
(
    outShape: number[], xBuf: TensorBuffer<R>, strides: number[],
    begin: number[])

Source from the content-addressed store, hash-verified

18import {buffer, Rank, TensorBuffer} from '@tensorflow/tfjs-core';
19
20export function stridedSliceImpl<R extends Rank>(
21 outShape: number[], xBuf: TensorBuffer<R>, strides: number[],
22 begin: number[]): TensorBuffer<R> {
23 const outBuf = buffer(outShape, xBuf.dtype);
24
25 for (let i = 0; i < outBuf.size; i++) {
26 const loc = outBuf.indexToLoc(i);
27
28 const newLoc: number[] = new Array(loc.length);
29 for (let j = 0; j < newLoc.length; j++) {
30 newLoc[j] = loc[j] * strides[j] + begin[j];
31 }
32 outBuf.set(xBuf.get(...newLoc), ...loc);
33 }
34
35 return outBuf as TensorBuffer<R>;
36}

Callers 1

stridedSliceFunction · 0.90

Calls 4

bufferFunction · 0.90
indexToLocMethod · 0.80
setMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…