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

Function sparseSegmentMean_

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

* Computes the mean along sparse segments of a tensor. * * ```js * const c = tf.tensor2d([[1,2,3,4], [-1,-2,-3,-4], [6,7,8,9]]); * // Select two rows, one segment. * const result1 = tf.sparse.sparseSegmentMean(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 sparseSegmentMean_(
60 data: Tensor|TensorLike, indices: Tensor1D|TensorLike,
61 segmentIds: Tensor1D|TensorLike): Tensor {
62 const $data = convertToTensor(data, 'data', 'sparseSegmentMean');
63 const $indices =
64 convertToTensor(indices, 'indices', 'sparseSegmentMean', 'int32');
65 const $segmentIds =
66 convertToTensor(segmentIds, 'segmentIds', 'sparseSegmentMean', '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: SparseSegmentMeanInputs = {
82 data: $data,
83 indices: $indices,
84 segmentIds: $segmentIds
85 };
86
87 return ENGINE.runKernel(SparseSegmentMean, inputs as {});
88}
89
90export const sparseSegmentMean = /* @__PURE__ */ op({sparseSegmentMean_});

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…