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

Function sparseToDense

tfjs-backend-wasm/src/kernels/SparseToDense.ts:46–77  ·  view source on GitHub ↗
(args: {
  backend: BackendWasm,
  inputs: SparseToDenseInputs,
  attrs: SparseToDenseAttrs
})

Source from the content-addressed store, hash-verified

44}
45
46function sparseToDense(args: {
47 backend: BackendWasm,
48 inputs: SparseToDenseInputs,
49 attrs: SparseToDenseAttrs
50}): TensorInfo {
51 const {backend, inputs, attrs} = args;
52 const {sparseIndices, sparseValues, defaultValue} = inputs;
53 const {outputShape} = attrs;
54
55 const out = backend.makeOutput(outputShape, defaultValue.dtype);
56 if (util.sizeFromShape(outputShape) === 0) {
57 return out;
58 }
59
60 const {sliceRank, numUpdates, sliceSize, strides, outputSize} =
61 backend_util.calculateShapes(sparseValues, sparseIndices, outputShape);
62
63 const sparseIndicesId = backend.dataIdMap.get(sparseIndices.dataId).id;
64 const sparseValuesId = backend.dataIdMap.get(sparseValues.dataId).id;
65 const defaultValueId = backend.dataIdMap.get(defaultValue.dataId).id;
66
67 const stridesBytes = new Uint8Array(new Int32Array(strides).buffer);
68
69 const outId = backend.dataIdMap.get(out.dataId).id;
70
71 wasmSparseToDense(
72 sparseIndicesId, sparseValuesId, sparseValues.shape.length,
73 defaultValueId, CppDType[defaultValue.dtype], sliceRank, numUpdates,
74 sliceSize, stridesBytes, outputSize, outId);
75
76 return out;
77}
78
79export const sparseToDenseConfig: KernelConfig = {
80 kernelName: SparseToDense,

Callers

nothing calls this directly

Calls 2

makeOutputMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…