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

Function pack

tfjs-backend-webgpu/src/kernels/Pack.ts:24–60  ·  view source on GitHub ↗
(
    args: {inputs: PackInputs, backend: WebGPUBackend, attrs: PackAttrs})

Source from the content-addressed store, hash-verified

22import {expandDims} from './ExpandDims';
23
24export 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
62export const packConfig: KernelConfig = {
63 kernelName: Pack,

Callers

nothing calls this directly

Calls 4

expandDimsFunction · 0.90
concatFunction · 0.90
disposeDataMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…