* Computes the sum along sparse segments of a tensor. * * ```js * const c = tf.tensor2d([[1,2,3,4], [-1,-2,-3,-4], [5,6,7,8]]); * // Select two rows, one segment. * const result1 = tf.sparse.sparseSegmentSum(c, * tf.tensor1d([0, 1], 'int32'), *
(
data: Tensor|TensorLike, indices: Tensor1D|TensorLike,
segmentIds: Tensor1D|TensorLike)
| 57 | * @doc {heading: 'Operations', subheading: 'Sparse'} |
| 58 | */ |
| 59 | function sparseSegmentSum_( |
| 60 | data: Tensor|TensorLike, indices: Tensor1D|TensorLike, |
| 61 | segmentIds: Tensor1D|TensorLike): Tensor { |
| 62 | const $data = convertToTensor(data, 'data', 'sparseSegmentSum'); |
| 63 | const $indices = |
| 64 | convertToTensor(indices, 'indices', 'sparseSegmentSum', 'int32'); |
| 65 | const $segmentIds = |
| 66 | convertToTensor(segmentIds, 'segmentIds', 'sparseSegmentSum', 'int32'); |
| 67 | |
| 68 | if ($data.rank < 1) { |
| 69 | throw new Error( |
| 70 | `Data should be at least 1 dimensional but received scalar`); |
| 71 | } |
| 72 | if ($indices.rank !== 1) { |
| 73 | throw new Error(`Indices should be Tensor1D but received shape |
| 74 | ${$indices.shape}`); |
| 75 | } |
| 76 | if ($segmentIds.rank !== 1) { |
| 77 | throw new Error(`Segment ids should be Tensor1D but received shape |
| 78 | ${$segmentIds.shape}`); |
| 79 | } |
| 80 | |
| 81 | const inputs: SparseSegmentSumInputs = { |
| 82 | data: $data, |
| 83 | indices: $indices, |
| 84 | segmentIds: $segmentIds |
| 85 | }; |
| 86 | |
| 87 | return ENGINE.runKernel(SparseSegmentSum, inputs as {}); |
| 88 | } |
| 89 | |
| 90 | export const sparseSegmentSum = /* @__PURE__ */ op({sparseSegmentSum_}); |
nothing calls this directly
no test coverage detected
searching dependent graphs…