(self)
| 243 | atol=1e-6) |
| 244 | |
| 245 | def testIntOps(self): |
| 246 | for dtype in self.signed_int_types: |
| 247 | self._testBinary( |
| 248 | gen_math_ops.truncate_div, |
| 249 | np.array([3, 3, -1, -9, -8], dtype=dtype), |
| 250 | np.array([2, -2, 7, 2, -4], dtype=dtype), |
| 251 | expected=np.array([1, -1, 0, -4, 2], dtype=dtype)) |
| 252 | self._testSymmetricBinary( |
| 253 | bitwise_ops.bitwise_and, |
| 254 | np.array([0b1, 0b101, 0b1000], dtype=dtype), |
| 255 | np.array([0b0, 0b101, 0b1001], dtype=dtype), |
| 256 | expected=np.array([0b0, 0b101, 0b1000], dtype=dtype)) |
| 257 | self._testSymmetricBinary( |
| 258 | bitwise_ops.bitwise_or, |
| 259 | np.array([0b1, 0b101, 0b1000], dtype=dtype), |
| 260 | np.array([0b0, 0b101, 0b1001], dtype=dtype), |
| 261 | expected=np.array([0b1, 0b101, 0b1001], dtype=dtype)) |
| 262 | self._testSymmetricBinary( |
| 263 | bitwise_ops.bitwise_xor, |
| 264 | np.array([0b1, 0b111, 0b1100], dtype=dtype), |
| 265 | np.array([0b0, 0b101, 0b1001], dtype=dtype), |
| 266 | expected=np.array([0b1, 0b010, 0b0101], dtype=dtype)) |
| 267 | |
| 268 | lhs = np.array([0, 5, 3, 14], dtype=dtype) |
| 269 | rhs = np.array([5, 0, 7, 11], dtype=dtype) |
| 270 | self._testBinary( |
| 271 | bitwise_ops.left_shift, lhs, rhs, |
| 272 | expected=np.left_shift(lhs, rhs)) |
| 273 | self._testBinary( |
| 274 | bitwise_ops.right_shift, lhs, rhs, |
| 275 | expected=np.right_shift(lhs, rhs)) |
| 276 | |
| 277 | if dtype in [np.int8, np.int16, np.int32, np.int64]: |
| 278 | lhs = np.array([-1, -5, -3, -14, -2], dtype=dtype) |
| 279 | rhs = np.array([5, 0, 1, 11, 36], dtype=dtype) |
| 280 | # HLO has saturating shift behavior. |
| 281 | bits = np.ceil( |
| 282 | np.log(np.iinfo(dtype).max - np.iinfo(dtype).min) / np.log(2)) |
| 283 | expected = [ |
| 284 | np.right_shift(l, r) if r < bits else np.sign(l) |
| 285 | for l, r in zip(lhs, rhs) |
| 286 | ] |
| 287 | self._testBinary(bitwise_ops.right_shift, lhs, rhs, expected=expected) |
| 288 | |
| 289 | def testAdd(self): |
| 290 | for dtype in self.numeric_types: |
nothing calls this directly
no test coverage detected