Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion tfjs-backend-wasm/src/kernels/Concat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ interface ConcatAttrs extends NamedAttrMap {

function concat(
args: {inputs: TensorInfo[], backend: BackendWasm, attrs: ConcatAttrs}) {
const {inputs, backend, attrs: {axis}} = args;
const {inputs, backend} = args;

const axis = util.parseAxisParam(args.attrs.axis, inputs[0].shape)[0];

const outShape = backend_util.computeOutShape(inputs.map(t => t.shape), axis);
const out = backend.makeOutput(outShape, inputs[0].dtype);

Expand Down
1 change: 0 additions & 1 deletion tfjs-core/src/ops/concat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ function concat_<T extends Tensor>(tensors: Array<T|TensorLike>, axis = 0): T {
assertParamsConsistent(shapes, $axis);

const forward: ForwardFunc<Tensor> = (backend, save) => {
const $axis = parseAxisParam(axis, $tensors[0].shape)[0];
const res = backend.concat($tensors, $axis);
save($tensors);
return res;
Expand Down
8 changes: 8 additions & 0 deletions tfjs-core/src/ops/concat_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,14 @@ describeWithFlags('concat2d', ALL_ENVS, () => {
});

describeWithFlags('concat3d', ALL_ENVS, () => {
it('shapes correct concat axis=-1', async () => {
const tensor1 = tf.tensor3d([1, 2, 3], [1, 1, 3]);
const tensor2 = tf.tensor3d([4, 5, 6], [1, 1, 3]);
const values = tf.concat3d([tensor1, tensor2], -1);
expect(values.shape).toEqual([1, 1, 6]);
expectArraysClose(await values.data(), [1, 2, 3, 4, 5, 6]);
});

it('shapes correct concat axis=0', async () => {
const tensor1 = tf.tensor3d([1, 2, 3], [1, 1, 3]);
const tensor2 = tf.tensor3d([4, 5, 6], [1, 1, 3]);
Expand Down