(
args: {inputs: SparseSegmentSumInputs, backend: MathBackendWebGL})
| 21 | import {sparseSegmentReductionImplCPU} from '../kernel_utils/shared'; |
| 22 | |
| 23 | export 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 | |
| 50 | export const sparseSegmentSumConfig: KernelConfig = { |
| 51 | kernelName: SparseSegmentSum, |
nothing calls this directly
no test coverage detected
searching dependent graphs…