mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Improved partial reductions in more cases
This commit is contained in:
@@ -239,6 +239,33 @@ static void test_simple_reductions() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <int DataLayout>
|
||||
static void test_reductions_in_expr() {
|
||||
Tensor<float, 4, DataLayout> tensor(2, 3, 5, 7);
|
||||
tensor.setRandom();
|
||||
array<ptrdiff_t, 2> reduction_axis2;
|
||||
reduction_axis2[0] = 1;
|
||||
reduction_axis2[1] = 3;
|
||||
|
||||
Tensor<float, 2, DataLayout> result(2, 5);
|
||||
result = result.constant(1.0f) - tensor.sum(reduction_axis2);
|
||||
VERIFY_IS_EQUAL(result.dimension(0), 2);
|
||||
VERIFY_IS_EQUAL(result.dimension(1), 5);
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
for (int j = 0; j < 5; ++j) {
|
||||
float sum = 0.0f;
|
||||
for (int k = 0; k < 3; ++k) {
|
||||
for (int l = 0; l < 7; ++l) {
|
||||
sum += tensor(i, k, j, l);
|
||||
}
|
||||
}
|
||||
VERIFY_IS_APPROX(result(i, j), 1.0f - sum);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <int DataLayout>
|
||||
static void test_full_reductions() {
|
||||
Tensor<float, 2, DataLayout> tensor(2, 3);
|
||||
@@ -462,6 +489,8 @@ void test_cxx11_tensor_reduction() {
|
||||
CALL_SUBTEST(test_trivial_reductions<RowMajor>());
|
||||
CALL_SUBTEST(test_simple_reductions<ColMajor>());
|
||||
CALL_SUBTEST(test_simple_reductions<RowMajor>());
|
||||
CALL_SUBTEST(test_reductions_in_expr<ColMajor>());
|
||||
CALL_SUBTEST(test_reductions_in_expr<RowMajor>());
|
||||
CALL_SUBTEST(test_full_reductions<ColMajor>());
|
||||
CALL_SUBTEST(test_full_reductions<RowMajor>());
|
||||
CALL_SUBTEST(test_user_defined_reductions<ColMajor>());
|
||||
|
||||
Reference in New Issue
Block a user