MCPcopy Create free account
hub / github.com/tensorflow/tfjs / sparseSegmentSum

Function sparseSegmentSum

tfjs-backend-webgl/src/kernels/SparseSegmentSum.ts:23–48  ·  view source on GitHub ↗
(
    args: {inputs: SparseSegmentSumInputs, backend: MathBackendWebGL})

Source from the content-addressed store, hash-verified

21import {sparseSegmentReductionImplCPU} from '../kernel_utils/shared';
22
23export function sparseSegmentSum(
24 args: {inputs: SparseSegmentSumInputs, backend: MathBackendWebGL}):
25 TensorInfo {
26 const {inputs, backend} = args;
27 const {data, indices, segmentIds} = inputs;
28 if (data.shape.length < 1) {
29 throw new Error(
30 `Data should be at least 1 dimensional but received scalar`);
31 }
32 if (indices.shape.length !== 1) {
33 throw new Error(`Indices should be a vector but received shape
34 ${indices.shape}`);
35 }
36 if (segmentIds.shape.length !== 1) {
37 throw new Error(`Segment ids should be a vector but received shape
38 ${segmentIds.shape}`);
39 }
40
41 const $data = backend.readSync(data.dataId) as TypedArray;
42 const $indices = backend.readSync(indices.dataId) as TypedArray;
43 const $segmentIds = backend.readSync(segmentIds.dataId) as TypedArray;
44
45 const [outputData, outputDataShape] = sparseSegmentReductionImplCPU(
46 $data, data.shape, data.dtype, $indices, $segmentIds);
47 return backend.makeTensorInfo(outputDataShape, data.dtype, outputData);
48}
49
50export const sparseSegmentSumConfig: KernelConfig = {
51 kernelName: SparseSegmentSum,

Callers

nothing calls this directly

Calls 2

readSyncMethod · 0.65
makeTensorInfoMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…