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

Function sparseFillEmptyRows

tfjs-backend-cpu/src/kernels/SparseFillEmptyRows.ts:24–70  ·  view source on GitHub ↗
(args: {
  inputs: SparseFillEmptyRowsInputs,
  backend: MathBackendCPU
})

Source from the content-addressed store, hash-verified

22import {sparseFillEmptyRowsImpl} from './SparseFillEmptyRows_impl';
23
24export function sparseFillEmptyRows(args: {
25 inputs: SparseFillEmptyRowsInputs,
26 backend: MathBackendCPU
27}): [TensorInfo, TensorInfo, TensorInfo, TensorInfo] {
28 const {inputs, backend} = args;
29 const {indices, values, denseShape, defaultValue} = inputs;
30 if (denseShape.shape.length !== 1) {
31 throw new Error(`Dense shape must be a vector, saw:
32 ${denseShape.shape}`);
33 }
34 if (indices.shape.length !== 2) {
35 throw new Error(`Indices must be a matrix, saw:
36 ${indices.shape}`);
37 }
38 if (values.shape.length !== 1) {
39 throw new Error(`Values must be a vector, saw:
40 ${values.shape}`);
41 }
42 if (defaultValue.shape.length !== 0) {
43 throw new Error(`Default value must be a scalar, saw:
44 ${defaultValue.shape}`);
45 }
46
47 const $indices = backend.data.get(indices.dataId).values as TypedArray;
48 const $values = backend.data.get(values.dataId).values as TypedArray;
49 const $denseShape = backend.data.get(denseShape.dataId).values as TypedArray;
50 const $defaultValue =
51 backend.data.get(defaultValue.dataId).values[0] as number;
52
53 const [outputIndices, outputIndicesShape, outputValues,
54 emptyRowIndicator, reverseIndexMap] =
55 sparseFillEmptyRowsImpl(
56 $indices, indices.shape, indices.dtype, $values, values.dtype,
57 $denseShape, $defaultValue);
58 return [
59 backend.makeTensorInfo(outputIndicesShape, indices.dtype, outputIndices),
60 backend.makeTensorInfo(
61 [outputIndicesShape[0]], values.dtype, outputValues),
62 backend.makeTensorInfo(
63 [emptyRowIndicator.length], 'bool',
64 new Uint8Array(
65 emptyRowIndicator.map((value: boolean) => Number(value)))),
66 backend.makeTensorInfo(
67 [reverseIndexMap.length], indices.dtype,
68 new Int32Array(reverseIndexMap)),
69 ];
70}
71
72export const sparseFillEmptyRowsConfig: KernelConfig = {
73 kernelName: SparseFillEmptyRows,

Callers

nothing calls this directly

Calls 3

sparseFillEmptyRowsImplFunction · 0.90
getMethod · 0.45
makeTensorInfoMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…