diff --git a/tensorflow/compiler/tests/unary_ops_test.py b/tensorflow/compiler/tests/unary_ops_test.py index d9a230664af..a9f5a5e743d 100644 --- a/tensorflow/compiler/tests/unary_ops_test.py +++ b/tensorflow/compiler/tests/unary_ops_test.py @@ -151,20 +151,37 @@ class UnaryOpsTest(xla_test.XLATestCase): def testSin(self): for dtype in self.float_types - {dtypes.bfloat16.as_numpy_dtype}: - tol = 1e-3 if dtype == np.float32 else 1e-10 + tol = 1e-6 if dtype == np.float32 else 1e-12 - x = np.linspace(-4 * np.pi, 4 * np.pi, num=1000, dtype=dtype) + x = np.linspace(-4 * np.e, 4 * np.e, num=1000, dtype=dtype) self._assertOpOutputMatchesExpected( math_ops.sin, x, expected=np.sin(x), rtol=tol, atol=tol) - x = np.linspace(0., 2.71828e-30, num=1000, dtype=dtype) + x = np.linspace(0., np.e * 1e-30, num=1000, dtype=dtype) self._assertOpOutputMatchesExpected( math_ops.sin, x, expected=np.sin(x), rtol=tol, atol=tol) if dtype == np.float64: - x = np.linspace(0., 3.141592e8, num=1000, dtype=dtype) + x = np.linspace(0., np.e * 1e8, num=1000, dtype=dtype) self._assertOpOutputMatchesExpected( - math_ops.sin, x, expected=np.sin(x), rtol=1e-5, atol=1e-5) + math_ops.sin, x, expected=np.sin(x), rtol=tol, atol=1e-5) + + def testCos(self): + for dtype in self.float_types - {dtypes.bfloat16.as_numpy_dtype}: + tol = 1e-6 if dtype == np.float32 else 1e-12 + + x = np.linspace(-4 * np.e, 4 * np.e, num=1000, dtype=dtype) + self._assertOpOutputMatchesExpected( + math_ops.cos, x, expected=np.cos(x), rtol=tol, atol=tol) + + x = np.linspace(0., np.e * 1e-30, num=1000, dtype=dtype) + self._assertOpOutputMatchesExpected( + math_ops.cos, x, expected=np.cos(x), rtol=tol, atol=tol) + + if dtype == np.float64: + x = np.linspace(0., np.e * 1e8, num=1000, dtype=dtype) + self._assertOpOutputMatchesExpected( + math_ops.cos, x, expected=np.cos(x), rtol=tol, atol=1e-5) def testFloatOps(self): for dtype in self.float_types: