(
args: {inputs: SparseSegmentSumInputs, backend: MathBackendCPU})
| 22 | import {sparseSegmentReductionImpl} from './SparseSegmentReduction_impl'; |
| 23 | |
| 24 | export 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 | |
| 54 | export const sparseSegmentSumConfig: KernelConfig = { |
| 55 | kernelName: SparseSegmentSum, |
nothing calls this directly
no test coverage detected
searching dependent graphs…