(
args: {inputs: SparseReshapeInputs, backend: MathBackendCPU})
| 22 | import {sparseReshapeImpl} from './SparseReshape_impl'; |
| 23 | |
| 24 | export 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 | |
| 60 | export const sparseReshapeConfig: KernelConfig = { |
| 61 | kernelName: SparseReshape, |
nothing calls this directly
no test coverage detected
searching dependent graphs…