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 }
EIGEN_DECLARE_TEST(cxx11_tensor_intdiv)
#define CALL_SUBTEST_6(FUNC)
#define CALL_SUBTEST_4(FUNC)
void test_specific()
void test_signed_32bit()
#define CALL_SUBTEST_3(FUNC)
#define CALL_SUBTEST_7(FUNC)
void test_unsigned_32bit()
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T divide(const T numerator) const
Definition: TensorIntDiv.h:172
#define VERIFY_IS_EQUAL(a, b)
Definition: main.h:386
#define CALL_SUBTEST_1(FUNC)
Values result
void test_powers_32bit()
signed __int64 int64_t
Definition: ms_stdint.h:94
unsigned __int64 uint64_t
Definition: ms_stdint.h:95
unsigned int uint32_t
Definition: ms_stdint.h:85
signed int int32_t
Definition: ms_stdint.h:82
void test_powers_64bit()
void test_unsigned_64bit()
#define CALL_SUBTEST_5(FUNC)
void test_signed_64bit()
#define CALL_SUBTEST_2(FUNC)
std::ptrdiff_t j


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:34:07