Skip to content

Commit 7a7f9dd

Browse files
manuelcandalesfacebook-github-bot
authored andcommitted
Simplify op copy (#711)
Summary: Pull Request resolved: #711 The fact that `src` must broadcast to `in` implies that the result of broadcasting `in` and `src` has shape equal to `in`. Therefore `out` must have the same shape than `in`. Hence, we can avoid calling `get_broadcast_target_size` and simply resize `out` to `in.sizes()` ghstack-source-id: 203404905 exported-using-ghexport Reviewed By: SS-JIA Differential Revision: D49979519 fbshipit-source-id: 5b532c098165451817bc25067ba10ff68f6f0a23
1 parent 80d9857 commit 7a7f9dd

File tree

1 file changed

+1
-15
lines changed

1 file changed

+1
-15
lines changed

kernels/portable/cpu/op_copy.cpp

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,11 @@ Tensor& copy_out(
3333

3434
ET_KERNEL_CHECK(ctx, tensors_have_same_dtype(in, out), InvalidArgument, out);
3535

36-
Tensor::SizesType expected_output_size[kTensorDimensionLimit];
37-
size_t expected_output_dim = 0;
38-
3936
ET_KERNEL_CHECK(
4037
ctx, tensor_is_broadcastable_to(src, in), InvalidArgument, src);
4138

42-
get_broadcast_target_size(
43-
in,
44-
src,
45-
expected_output_size,
46-
kTensorDimensionLimit,
47-
&expected_output_dim);
48-
4939
ET_KERNEL_CHECK(
50-
ctx,
51-
resize_tensor(out, {expected_output_size, expected_output_dim}) ==
52-
Error::Ok,
53-
InvalidArgument,
54-
out);
40+
ctx, resize_tensor(out, in.sizes()) == Error::Ok, InvalidArgument, out);
5541

5642
ScalarType in_type = in.scalar_type();
5743
ScalarType src_type = src.scalar_type();

0 commit comments

Comments
 (0)