Fix broadcasting oob error.

For vectorized 1-dimensional inputs that do not take the special
blocking path (e.g. `std::complex<...>`), there was an
index-out-of-bounds error causing the broadcast size to be
computed incorrectly.  Here we fix this, and make other minor
cleanup changes.

Fixes #2351.
This commit is contained in:
Antonio Sanchez
2021-10-21 19:57:00 -07:00
committed by Rasmus Munk Larsen
parent 0578feaabc
commit a500da1dc0
2 changed files with 46 additions and 31 deletions

View File

@@ -256,6 +256,22 @@ static void test_simple_broadcasting_n_by_one()
}
}
template <int DataLayout>
static void test_size_one_broadcasting()
{
Tensor<float, 1, DataLayout> tensor(1);
tensor.setRandom();
array<ptrdiff_t, 1> broadcasts = {64};
Tensor<float, 1, DataLayout> broadcast;
broadcast = tensor.broadcast(broadcasts);
VERIFY_IS_EQUAL(broadcast.dimension(0), broadcasts[0]);
for (int i = 0; i < broadcasts[0]; ++i) {
VERIFY_IS_EQUAL(tensor(0), broadcast(i));
}
}
template <int DataLayout>
static void test_simple_broadcasting_one_by_n_by_one_1d()
{
@@ -328,4 +344,6 @@ EIGEN_DECLARE_TEST(cxx11_tensor_broadcasting)
CALL_SUBTEST(test_simple_broadcasting_one_by_n_by_one_2d<ColMajor>());
CALL_SUBTEST(test_simple_broadcasting_one_by_n_by_one_1d<RowMajor>());
CALL_SUBTEST(test_simple_broadcasting_one_by_n_by_one_2d<RowMajor>());
CALL_SUBTEST(test_size_one_broadcasting<ColMajor>());
CALL_SUBTEST(test_size_one_broadcasting<RowMajor>());
}