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

Function reduce

tfjs-backend-webgl/src/kernel_utils/reduce.ts:46–76  ·  view source on GitHub ↗
(
    x: TensorInfo, dtype: DataType, reductionType: ReduceTypes,
    backend: MathBackendWebGL)

Source from the content-addressed store, hash-verified

44}
45
46export function reduce(
47 x: TensorInfo, dtype: DataType, reductionType: ReduceTypes,
48 backend: MathBackendWebGL): TensorInfo {
49 const reductionStages = getReductionStages(x.shape);
50
51 let result = x;
52 for (let i = 0; i < reductionStages.length; i++) {
53 const {inSize, windowSize, outSize} = reductionStages[i];
54
55 let program: ReduceProgram|MeanProgram;
56 let previousResult: TensorInfo;
57 if (reductionType === 'mean') {
58 program = i === 0 ?
59 new MeanProgram(
60 {windowSize, inSize, batchSize: x.shape[0], outSize}, inSize) :
61 new MeanProgram({windowSize, inSize, batchSize: x.shape[0], outSize});
62 } else {
63 program = new ReduceProgram(
64 {windowSize, inSize, batchSize: x.shape[0], outSize}, reductionType);
65 }
66
67 previousResult = result;
68 result = backend.runWebGLProgram(program, [result], dtype);
69
70 if (previousResult.dataId !== x.dataId) {
71 backend.disposeIntermediateTensorInfo(previousResult);
72 }
73 }
74
75 return result;
76}

Callers 7

maxImplFunction · 0.90
allFunction · 0.90
anyFunction · 0.90
minFunction · 0.90
prodFunction · 0.90
meanImplFunction · 0.90
sumImplFunction · 0.90

Calls 3

getReductionStagesFunction · 0.85
runWebGLProgramMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…