(args: {
backend: BackendWasm,
inputs: SparseFillEmptyRowsInputs,
})
| 48 | } |
| 49 | |
| 50 | export 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; |
nothing calls this directly
no test coverage detected
searching dependent graphs…