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

Function sparseSegmentSum_

tfjs-core/src/ops/sparse/sparse_segment_sum.ts:59–88  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

57 * @doc {heading: 'Operations', subheading: 'Sparse'}
58 */
59function 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
90export const sparseSegmentSum = /* @__PURE__ */ op({sparseSegmentSum_});

Callers

nothing calls this directly

Calls 2

convertToTensorFunction · 0.90
runKernelMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…