(
args: {inputs: PackInputs, backend: WebGPUBackend, attrs: PackAttrs})
| 22 | import {expandDims} from './ExpandDims'; |
| 23 | |
| 24 | export function pack( |
| 25 | args: {inputs: PackInputs, backend: WebGPUBackend, attrs: PackAttrs}): |
| 26 | TensorInfo { |
| 27 | const {inputs, backend, attrs} = args; |
| 28 | const {axis} = attrs; |
| 29 | |
| 30 | if (inputs.length === 1) { |
| 31 | return expandDims( |
| 32 | {inputs: {input: inputs[0]}, backend, attrs: {dim: axis}}); |
| 33 | } |
| 34 | |
| 35 | const shape = inputs[0].shape; |
| 36 | const dtype = inputs[0].dtype; |
| 37 | |
| 38 | inputs.forEach(t => { |
| 39 | util.assertShapesMatch( |
| 40 | shape, t.shape, |
| 41 | 'All tensors passed to stack must have matching shapes'); |
| 42 | util.assert( |
| 43 | dtype === t.dtype, |
| 44 | () => 'All tensors passed to stack must have matching dtypes'); |
| 45 | }); |
| 46 | |
| 47 | const intermediateTensorInfos: TensorInfo[] = []; |
| 48 | const expandedTensors = inputs.map(t => { |
| 49 | const expandedT = |
| 50 | expandDims({inputs: {input: t}, backend, attrs: {dim: axis}}); |
| 51 | intermediateTensorInfos.push(expandedT); |
| 52 | return expandedT; |
| 53 | }); |
| 54 | |
| 55 | const result = concat({inputs: expandedTensors, backend, attrs: {axis}}); |
| 56 | |
| 57 | intermediateTensorInfos.forEach(t => backend.disposeData(t.dataId)); |
| 58 | |
| 59 | return result; |
| 60 | } |
| 61 | |
| 62 | export const packConfig: KernelConfig = { |
| 63 | kernelName: Pack, |
nothing calls this directly
no test coverage detected
searching dependent graphs…