cxx11_tensor_intdiv.cpp
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2014-2015 Benoit Steiner <benoit.steiner.goog@gmail.com>
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 #include "main.h"
11 
12 #include <Eigen/CXX11/Tensor>
13 
14 
16 {
17  // Divide by one
19 
20  for (int32_t j = 0; j < 25000; ++j) {
21  const int32_t fast_div = j / div_by_one;
22  const int32_t slow_div = j / 1;
23  VERIFY_IS_EQUAL(fast_div, slow_div);
24  }
25 
26  // Standard divide by 2 or more
27  for (int32_t i = 2; i < 25000; ++i) {
29 
30  for (int32_t j = 0; j < 25000; ++j) {
31  const int32_t fast_div = j / div;
32  const int32_t slow_div = j / i;
33  VERIFY_IS_EQUAL(fast_div, slow_div);
34  }
35  }
36 
37  // Optimized divide by 2 or more
38  for (int32_t i = 2; i < 25000; ++i) {
40 
41  for (int32_t j = 0; j < 25000; ++j) {
42  const int32_t fast_div = j / div;
43  const int32_t slow_div = j / i;
44  VERIFY_IS_EQUAL(fast_div, slow_div);
45  }
46  }
47 }
48 
49 
51 {
52  for (uint32_t i = 1; i < 25000; ++i) {
54 
55  for (uint32_t j = 0; j < 25000; ++j) {
56  const uint32_t fast_div = j / div;
57  const uint32_t slow_div = j / i;
58  VERIFY_IS_EQUAL(fast_div, slow_div);
59  }
60  }
61 }
62 
63 
65 {
66  for (int64_t i = 1; i < 25000; ++i) {
68 
69  for (int64_t j = 0; j < 25000; ++j) {
70  const int64_t fast_div = j / div;
71  const int64_t slow_div = j / i;
72  VERIFY_IS_EQUAL(fast_div, slow_div);
73  }
74  }
75 }
76 
77 
79 {
80  for (uint64_t i = 1; i < 25000; ++i) {
82 
83  for (uint64_t j = 0; j < 25000; ++j) {
84  const uint64_t fast_div = j / div;
85  const uint64_t slow_div = j / i;
86  VERIFY_IS_EQUAL(fast_div, slow_div);
87  }
88  }
89 }
90 
92  for (int expon = 1; expon < 31; expon++) {
93  int32_t div = (1 << expon);
94  for (int num_expon = 0; num_expon < 32; num_expon++) {
95  int32_t start_num = (1 << num_expon) - 100;
96  int32_t end_num = (1 << num_expon) + 100;
97  if (start_num < 0)
98  start_num = 0;
99  for (int32_t num = start_num; num < end_num; num++) {
102  int32_t result = num/div;
103  int32_t result_op = divider.divide(num);
104  VERIFY_IS_EQUAL(result_op, result);
105  }
106  }
107  }
108 }
109 
111  for (int expon = 0; expon < 63; expon++) {
112  int64_t div = (1ull << expon);
113  for (int num_expon = 0; num_expon < 63; num_expon++) {
114  int64_t start_num = (1ull << num_expon) - 10;
115  int64_t end_num = (1ull << num_expon) + 10;
116  if (start_num < 0)
117  start_num = 0;
118  for (int64_t num = start_num; num < end_num; num++) {
120  int64_t result = num/div;
121  int64_t result_op = divider.divide(num);
122  VERIFY_IS_EQUAL(result_op, result);
123  }
124  }
125  }
126 }
127 
129  // A particular combination that was previously failing
130  int64_t div = 209715200;
131  int64_t num = 3238002688ll;
133  int64_t result = num/div;
134  int64_t result_op = divider.divide(num);
135  VERIFY_IS_EQUAL(result, result_op);
136 }
137 
138 EIGEN_DECLARE_TEST(cxx11_tensor_intdiv)
139 {
147 }
test_unsigned_32bit
void test_unsigned_32bit()
Definition: cxx11_tensor_intdiv.cpp:50
uint32_t
unsigned int uint32_t
Definition: ms_stdint.h:85
VERIFY_IS_EQUAL
#define VERIFY_IS_EQUAL(a, b)
Definition: main.h:386
test_unsigned_64bit
void test_unsigned_64bit()
Definition: cxx11_tensor_intdiv.cpp:78
result
Values result
Definition: OdometryOptimize.cpp:8
Eigen::internal::TensorIntDivisor
Definition: TensorIntDiv.h:142
CALL_SUBTEST_4
#define CALL_SUBTEST_4(FUNC)
Definition: split_test_helper.h:22
CALL_SUBTEST_3
#define CALL_SUBTEST_3(FUNC)
Definition: split_test_helper.h:16
CALL_SUBTEST_1
#define CALL_SUBTEST_1(FUNC)
Definition: split_test_helper.h:4
j
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2
int64_t
signed __int64 int64_t
Definition: ms_stdint.h:94
test_signed_64bit
void test_signed_64bit()
Definition: cxx11_tensor_intdiv.cpp:64
Eigen::internal::TensorIntDivisor< int32_t, true >
Definition: TensorIntDiv.h:193
CALL_SUBTEST_5
#define CALL_SUBTEST_5(FUNC)
Definition: split_test_helper.h:28
test_powers_32bit
void test_powers_32bit()
Definition: cxx11_tensor_intdiv.cpp:91
CALL_SUBTEST_6
#define CALL_SUBTEST_6(FUNC)
Definition: split_test_helper.h:34
CALL_SUBTEST_2
#define CALL_SUBTEST_2(FUNC)
Definition: split_test_helper.h:10
test_specific
void test_specific()
Definition: cxx11_tensor_intdiv.cpp:128
EIGEN_DECLARE_TEST
EIGEN_DECLARE_TEST(cxx11_tensor_intdiv)
Definition: cxx11_tensor_intdiv.cpp:138
main.h
Eigen::internal::TensorIntDivisor::divide
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T divide(const T numerator) const
Definition: TensorIntDiv.h:172
int32_t
signed int int32_t
Definition: ms_stdint.h:82
uint64_t
unsigned __int64 uint64_t
Definition: ms_stdint.h:95
test_powers_64bit
void test_powers_64bit()
Definition: cxx11_tensor_intdiv.cpp:110
CALL_SUBTEST_7
#define CALL_SUBTEST_7(FUNC)
Definition: split_test_helper.h:40
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
test_signed_32bit
void test_signed_32bit()
Definition: cxx11_tensor_intdiv.cpp:15


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:02:09