Skip to content

Commit 270c80d

Browse files
manuelcandalesfacebook-github-bot
authored andcommitted
update index: dtype constraints changed in ATen (#321)
Summary: Pull Request resolved: #321 Previously reported index [issue](pytorch/pytorch#107698) related to input/out type conversion was fixed in ATen, by requiring out tensor to have the same dtype than input tensor. This diffs updates the portable index kernel, to stay Dtype-compliant. Reviewed By: larryliu0820 Differential Revision: D49218705 fbshipit-source-id: 0aa16a8ffd666c69b9386bd6b2a8c1e23398872c
1 parent 18dba91 commit 270c80d

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

kernels/portable/cpu/op_index.cpp

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -520,20 +520,17 @@ Tensor& index_Tensor_out(
520520
}
521521

522522
ScalarType in_type = in.scalar_type();
523-
ScalarType out_type = out.scalar_type();
524-
ET_SWITCH_REAL_TYPES_AND(Bool, in_type, ctx, "index", CTYPE_IN, [&]() {
525-
ET_SWITCH_REAL_TYPES_AND(Bool, out_type, ctx, "index", CTYPE_OUT, [&]() {
526-
const CTYPE_IN* const in_data = in.const_data_ptr<CTYPE_IN>();
527-
CTYPE_OUT* const out_data = out.mutable_data_ptr<CTYPE_OUT>();
528-
529-
for (auto out_ix = 0; out_ix < out.numel(); out_ix++) {
530-
size_t in_ix = block_count == 0
531-
? out_ix
532-
: get_in_ix(
533-
ctx, in, indices, out, out_ix, start, xdim, dim_map, ix_map);
534-
out_data[out_ix] = static_cast<CTYPE_OUT>(in_data[in_ix]);
535-
}
536-
});
523+
ET_SWITCH_REAL_TYPES_AND(Bool, in_type, ctx, __func__, CTYPE, [&]() {
524+
const CTYPE* const in_data = in.const_data_ptr<CTYPE>();
525+
CTYPE* const out_data = out.mutable_data_ptr<CTYPE>();
526+
527+
for (auto out_ix = 0; out_ix < out.numel(); out_ix++) {
528+
size_t in_ix = block_count == 0
529+
? out_ix
530+
: get_in_ix(
531+
ctx, in, indices, out, out_ix, start, xdim, dim_map, ix_map);
532+
out_data[out_ix] = in_data[in_ix];
533+
}
537534
});
538535

539536
return out;

0 commit comments

Comments
 (0)