Skip to content

Unbreak BroadcastIndexesRange::operator+= when there is no broadcasting #9373

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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: 5 additions & 0 deletions kernels/portable/cpu/util/broadcast_indexes_range.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ class BroadcastIndexesIterator {
}

output_index() += n;
if (output_dim_or_zero_if_no_broadcasting_ == 0) {
std::fill(
current_indexes_.begin() + 1, current_indexes_.end(), output_index());
return *this;
}
delinearize_index(
output_index(),
output_shape_,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ TEST(BroadcastIndexesRangeTest, OneDNotBroadcasted) {

Tensor out = tf.zeros({5});
int idx = 0;
for (const auto& elem : range_to_vec(BroadcastIndexesRange<1>(out, out))) {
const auto range = BroadcastIndexesRange<1>(out, out);
for (const auto& elem : range_to_vec(range)) {
EXPECT_EQ(*(range.begin() + idx), elem);
EXPECT_EQ(elem[0], idx++);
EXPECT_EQ(elem[0], elem[1]);
}
Expand All @@ -71,7 +73,7 @@ TEST(BroadcastIndexesRangeTest, ScalarBroadcastToOneD) {
template <typename Range>
void test_operator_plus(const Range& range) {
size_t idx = 0;
for (const auto indexes : range) {
for (const auto& indexes : range) {
EXPECT_EQ(*(range.begin() + idx), indexes);
idx++;
}
Expand Down
Loading