aboutsummaryrefslogtreecommitdiffhomepage
path: root/unsupported/test/cxx11_tensor_intdiv.cpp
diff options
context:
space:
mode:
authorGravatar Benoit Steiner <benoit.steiner.goog@gmail.com>2015-07-22 17:02:30 -0700
committerGravatar Benoit Steiner <benoit.steiner.goog@gmail.com>2015-07-22 17:02:30 -0700
commit4200bdec2478d07b77f25ccc87094e2fba63cec6 (patch)
tree33e625de45ab43ada403e15153f3088974961d46 /unsupported/test/cxx11_tensor_intdiv.cpp
parentd259b719d1703e9271612d944e432edd72be1051 (diff)
Extended the range of value inputs for TensorIntDiv to support tensors with more than 4 billion elements.
Diffstat (limited to 'unsupported/test/cxx11_tensor_intdiv.cpp')
-rw-r--r--unsupported/test/cxx11_tensor_intdiv.cpp46
1 files changed, 42 insertions, 4 deletions
diff --git a/unsupported/test/cxx11_tensor_intdiv.cpp b/unsupported/test/cxx11_tensor_intdiv.cpp
index 134329034..b005238bd 100644
--- a/unsupported/test/cxx11_tensor_intdiv.cpp
+++ b/unsupported/test/cxx11_tensor_intdiv.cpp
@@ -67,10 +67,46 @@ void test_unsigned_64bit()
}
}
+void test_powers_32bit() {
+ for (int expon = 1; expon < 31; expon++) {
+ int32_t div = (1ull << expon);
+ for (int num_expon = 0; num_expon < 32; num_expon++) {
+ int32_t start_num = (1ull << num_expon) - 100;
+ int32_t end_num = (1ull << num_expon) + 100;
+ if (start_num < 0)
+ start_num = 0;
+ for (int64_t num = start_num; num < end_num; num++) {
+ Eigen::internal::TensorIntDivisor<int32_t> divider =
+ Eigen::internal::TensorIntDivisor<int32_t>(div);
+ int32_t result = num/div;
+ int32_t result_op = divider.divide(num);
+ VERIFY_IS_EQUAL(result_op, result);
+ }
+ }
+ }
+}
-void test_specific()
-{
- // A particular combination that exposed a bug in the past.
+void test_powers_64bit() {
+ for (int expon = 0; expon < 63; expon++) {
+ int64_t div = (1ull << expon);
+ for (int num_expon = 0; num_expon < 63; num_expon++) {
+ int64_t start_num = (1ull << num_expon) - 10;
+ int64_t end_num = (1ull << num_expon) + 10;
+ if (start_num < 0)
+ start_num = 0;
+ for (int64_t num = start_num; num < end_num; num++) {
+ Eigen::internal::TensorIntDivisor<int64_t> divider =
+ Eigen::internal::TensorIntDivisor<int64_t>(div);
+ int64_t result = num/div;
+ int64_t result_op = divider.divide(num);
+ VERIFY_IS_EQUAL(result_op, result);
+ }
+ }
+ }
+}
+
+void test_specific() {
+ // A particular combination that was previously failing
int64_t div = 209715200;
int64_t num = 3238002688;
Eigen::internal::TensorIntDivisor<int64_t> divider =
@@ -86,5 +122,7 @@ void test_cxx11_tensor_intdiv()
CALL_SUBTEST_2(test_unsigned_32bit());
CALL_SUBTEST_3(test_signed_64bit());
CALL_SUBTEST_4(test_unsigned_64bit());
- CALL_SUBTEST_5(test_specific());
+ CALL_SUBTEST_5(test_powers_32bit());
+ CALL_SUBTEST_6(test_powers_64bit());
+ CALL_SUBTEST_7(test_specific());
}