aboutsummaryrefslogtreecommitdiffhomepage
path: root/unsupported/test/cxx11_tensor_intdiv.cpp
diff options
context:
space:
mode:
authorGravatar Benoit Steiner <benoit.steiner.goog@gmail.com>2014-08-14 22:13:21 -0700
committerGravatar Benoit Steiner <benoit.steiner.goog@gmail.com>2014-08-14 22:13:21 -0700
commit33c702c79fe227a5b22229c26af276d359a6cb1d (patch)
tree86ca1888d05abb165b3ddbe892cfff7b5464573d /unsupported/test/cxx11_tensor_intdiv.cpp
parent756292f8aa124c842d1e6d9beeb0c416c0d9a7f3 (diff)
Added support for fast integer divisions by a constant
Sped up tensor slicing by a factor of 3 by using these fast integer divisions.
Diffstat (limited to 'unsupported/test/cxx11_tensor_intdiv.cpp')
-rw-r--r--unsupported/test/cxx11_tensor_intdiv.cpp77
1 files changed, 77 insertions, 0 deletions
diff --git a/unsupported/test/cxx11_tensor_intdiv.cpp b/unsupported/test/cxx11_tensor_intdiv.cpp
new file mode 100644
index 000000000..a510dc695
--- /dev/null
+++ b/unsupported/test/cxx11_tensor_intdiv.cpp
@@ -0,0 +1,77 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include "main.h"
+
+#include <Eigen/CXX11/Tensor>
+
+
+static void test_signed_32bit()
+{
+ for (int32_t i = 1; i < 25000; ++i) {
+ const Eigen::internal::TensorIntDivisor<int32_t> div(i);
+
+ for (int32_t j = 0; j < 25000; ++j) {
+ const int32_t fast_div = j / div;
+ const int32_t slow_div = j / i;
+ VERIFY_IS_EQUAL(fast_div, slow_div);
+ }
+ }
+}
+
+
+static void test_unsigned_32bit()
+{
+ for (uint32_t i = 1; i < 25000; ++i) {
+ const Eigen::internal::TensorIntDivisor<uint32_t> div(i);
+
+ for (uint32_t j = 0; j < 25000; ++j) {
+ const uint32_t fast_div = j / div;
+ const uint32_t slow_div = j / i;
+ VERIFY_IS_EQUAL(fast_div, slow_div);
+ }
+ }
+}
+
+
+static void test_signed_64bit()
+{
+ for (int64_t i = 2; i < 25000; ++i) {
+ const Eigen::internal::TensorIntDivisor<int64_t> div(i);
+
+ for (int64_t j = 0; j < 25000; ++j) {
+ const int64_t fast_div = j / div;
+ const int64_t slow_div = j / i;
+ VERIFY_IS_EQUAL(fast_div, slow_div);
+ }
+ }
+}
+
+
+static void test_unsigned_64bit()
+{
+ for (uint64_t i = 2; i < 25000; ++i) {
+ const Eigen::internal::TensorIntDivisor<uint64_t> div(i);
+
+ for (uint64_t j = 0; j < 25000; ++j) {
+ const uint64_t fast_div = j / div;
+ const uint64_t slow_div = j / i;
+ VERIFY_IS_EQUAL(fast_div, slow_div);
+ }
+ }
+}
+
+
+void test_cxx11_tensor_intdiv()
+{
+ CALL_SUBTEST(test_signed_32bit());
+ CALL_SUBTEST(test_unsigned_32bit());
+ CALL_SUBTEST(test_signed_64bit());
+ CALL_SUBTEST(test_unsigned_64bit());
+}