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

Function sparseReshape

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

Source from the content-addressed store, hash-verified

22import {sparseReshapeImpl} from './SparseReshape_impl';
23
24export function sparseReshape(
25 args: {inputs: SparseReshapeInputs, backend: MathBackendCPU}):
26 [TensorInfo, TensorInfo] {
27 const {inputs, backend} = args;
28 const {inputIndices, inputShape, newShape} = inputs;
29 if (inputIndices.shape.length !== 2) {
30 throw new Error(`Input indices should be a matrix but received shape
31 ${inputIndices.shape}`);
32 }
33 if (inputShape.shape.length !== 1) {
34 throw new Error(`Input shape should be a vector but received shape
35 ${inputShape.shape}`);
36 }
37
38 if (newShape.shape.length !== 1) {
39 throw new Error(
40 `Target shape should be a vector but received shape ${newShape.shape}`);
41 }
42
43 const $inputShape =
44 Array.from(backend.data.get(inputShape.dataId).values as TypedArray);
45 const $inputIndices =
46 backend.data.get(inputIndices.dataId).values as TypedArray;
47 const targetShape =
48 Array.from(backend.data.get(newShape.dataId).values as TypedArray);
49
50 const [newIndices, indicesShape, outputShape] = sparseReshapeImpl(
51 $inputIndices, inputIndices.shape, inputIndices.dtype, $inputShape,
52 targetShape);
53 return [
54 backend.makeTensorInfo(indicesShape, inputIndices.dtype, newIndices),
55 backend.makeTensorInfo(
56 [outputShape.length], newShape.dtype, new Int32Array(outputShape)),
57 ];
58}
59
60export const sparseReshapeConfig: KernelConfig = {
61 kernelName: SparseReshape,

Callers

nothing calls this directly

Calls 3

sparseReshapeImplFunction · 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…