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

Function sparseSegmentSum

tfjs-backend-cpu/src/kernels/SparseSegmentSum.ts:24–52  ·  view source on GitHub ↗
(
    args: {inputs: SparseSegmentSumInputs, backend: MathBackendCPU})

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 3

getMethod · 0.45
makeTensorInfoMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…