Test integer division intrinsics: npyv_divisor_##sfx npyv_divc_##sfx
(self)
| 1176 | assert div == data_div |
| 1177 | |
| 1178 | def test_arithmetic_intdiv(self): |
| 1179 | """ |
| 1180 | Test integer division intrinsics: |
| 1181 | npyv_divisor_##sfx |
| 1182 | npyv_divc_##sfx |
| 1183 | """ |
| 1184 | if self._is_fp(): |
| 1185 | return |
| 1186 | |
| 1187 | int_min = self._int_min() |
| 1188 | def trunc_div(a, d): |
| 1189 | """ |
| 1190 | Divide towards zero works with large integers > 2^53, |
| 1191 | and wrap around overflow similar to what C does. |
| 1192 | """ |
| 1193 | if d == -1 and a == int_min: |
| 1194 | return a |
| 1195 | sign_a, sign_d = a < 0, d < 0 |
| 1196 | if a == 0 or sign_a == sign_d: |
| 1197 | return a // d |
| 1198 | return (a + sign_d - sign_a) // d + 1 |
| 1199 | |
| 1200 | data = [1, -int_min] # to test overflow |
| 1201 | data += range(0, 2**8, 2**5) |
| 1202 | data += range(0, 2**8, 2**5-1) |
| 1203 | bsize = self._scalar_size() |
| 1204 | if bsize > 8: |
| 1205 | data += range(2**8, 2**16, 2**13) |
| 1206 | data += range(2**8, 2**16, 2**13-1) |
| 1207 | if bsize > 16: |
| 1208 | data += range(2**16, 2**32, 2**29) |
| 1209 | data += range(2**16, 2**32, 2**29-1) |
| 1210 | if bsize > 32: |
| 1211 | data += range(2**32, 2**64, 2**61) |
| 1212 | data += range(2**32, 2**64, 2**61-1) |
| 1213 | # negate |
| 1214 | data += [-x for x in data] |
| 1215 | for dividend, divisor in itertools.product(data, data): |
| 1216 | divisor = self.setall(divisor)[0] # cast |
| 1217 | if divisor == 0: |
| 1218 | continue |
| 1219 | dividend = self.load(self._data(dividend)) |
| 1220 | data_divc = [trunc_div(a, divisor) for a in dividend] |
| 1221 | divisor_parms = self.divisor(divisor) |
| 1222 | divc = self.divc(dividend, divisor_parms) |
| 1223 | assert divc == data_divc |
| 1224 | |
| 1225 | def test_arithmetic_reduce_sum(self): |
| 1226 | """ |
nothing calls this directly
no test coverage detected