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

Function sparseFillEmptyRows

tfjs-backend-wasm/src/kernels/SparseFillEmptyRows.ts:50–147  ·  view source on GitHub ↗
(args: {
  backend: BackendWasm,
  inputs: SparseFillEmptyRowsInputs,
})

Source from the content-addressed store, hash-verified

48}
49
50export function sparseFillEmptyRows(args: {
51 backend: BackendWasm,
52 inputs: SparseFillEmptyRowsInputs,
53}): [TensorInfo, TensorInfo, TensorInfo, TensorInfo] {
54 const {backend, inputs} = args;
55 const {indices, values, denseShape, defaultValue} = inputs;
56
57 const indicesCount = indices.shape[0];
58 const rank = indices.shape[1];
59 const denseRows = backend.readSync(denseShape.dataId)[0] as number;
60
61 // Set output size to maximum possible and resize later (actual result
62 // might be smaller).
63 const maxOutputIndicesShape = [indicesCount + denseRows, rank];
64
65 const indicesId = backend.dataIdMap.get(indices.dataId).id;
66 const valuesId = backend.dataIdMap.get(values.dataId).id;
67 const defaultValueId = backend.dataIdMap.get(defaultValue.dataId).id;
68
69 const outputIndices =
70 backend.makeOutput(maxOutputIndicesShape, indices.dtype);
71 const outputIndicesId = backend.dataIdMap.get(outputIndices.dataId).id;
72
73 const outputValues =
74 backend.makeOutput(maxOutputIndicesShape.slice(0, 1), values.dtype);
75 const outputValuesId = backend.dataIdMap.get(outputValues.dataId).id;
76
77 const emptyRowIndicator = backend.makeOutput([denseRows], 'bool');
78 const emptyRowIndicatorId =
79 backend.dataIdMap.get(emptyRowIndicator.dataId).id;
80
81 const reverseIndexMap = backend.makeOutput([indicesCount], indices.dtype);
82 const reverseIndexMapId = backend.dataIdMap.get(reverseIndexMap.dataId).id;
83
84 const exceptionValues = backend.makeOutput([4], 'int32');
85 const exceptionValuesId = backend.dataIdMap.get(exceptionValues.dataId).id;
86
87 const outputRows = wasmSparseFillEmptyRows(
88 indicesId, valuesId, CppDType[values.dtype], indicesCount, denseRows,
89 rank, defaultValueId, outputIndicesId, outputValuesId,
90 emptyRowIndicatorId, reverseIndexMapId, exceptionValuesId);
91
92 const exceptionValuesArray =
93 backend.readSync(exceptionValues.dataId) as Int32Array;
94
95 let exceptionMessage: string;
96 switch (exceptionValuesArray[0]) {
97 case 1: {
98 exceptionMessage =
99 backend_util.getSparseFillEmptyRowsIndicesDenseShapeMismatch(
100 exceptionValuesArray[1]);
101 break;
102 }
103 case 2: {
104 exceptionMessage =
105 backend_util.getSparseFillEmptyRowsNegativeIndexErrorMessage(
106 exceptionValuesArray[1], exceptionValuesArray[2]);
107 break;

Callers

nothing calls this directly

Calls 6

sliceFunction · 0.90
readSyncMethod · 0.65
sliceMethod · 0.65
disposeDataMethod · 0.65
getMethod · 0.45
makeOutputMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…