aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/python/kernel_tests/cwise_ops_test.py
diff options
context:
space:
mode:
Diffstat (limited to 'tensorflow/python/kernel_tests/cwise_ops_test.py')
-rw-r--r--tensorflow/python/kernel_tests/cwise_ops_test.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/tensorflow/python/kernel_tests/cwise_ops_test.py b/tensorflow/python/kernel_tests/cwise_ops_test.py
index cd0d33ecf3..0846470abc 100644
--- a/tensorflow/python/kernel_tests/cwise_ops_test.py
+++ b/tensorflow/python/kernel_tests/cwise_ops_test.py
@@ -615,6 +615,13 @@ class BinaryOpTest(test.TestCase):
self._compareBoth(x, y, np.multiply, _MUL)
self._compareBoth(x, y + 0.1, np.true_divide, _TRUEDIV)
self._compareBoth(x, y + 0.1, np.floor_divide, _FLOORDIV)
+ self._compareBoth(x, y, np.arctan2, math_ops.atan2)
+ x1 = np.random.randn(5, 6).astype(np.float32)
+ x2 = np.random.randn(5, 6).astype(np.float32)
+ # Remove tiny values--atan2 gradients are flaky near the origin.
+ x1[np.abs(x1) < 0.05] = 0.05 * np.sign(x1[np.abs(x1) < 0.05])
+ x2[np.abs(x2) < 0.05] = 0.05 * np.sign(x2[np.abs(x2) < 0.05])
+ self._compareBoth(x1, x2, np.arctan2, math_ops.atan2)
try:
from scipy import special # pylint: disable=g-import-not-at-top
a_pos_small = np.linspace(0.1, 2, 15).reshape(1, 3, 5).astype(np.float32)
@@ -672,6 +679,13 @@ class BinaryOpTest(test.TestCase):
self._compareBoth(x, y, np.multiply, _MUL)
self._compareBoth(x, y + 0.1, np.true_divide, _TRUEDIV)
self._compareBoth(x, y + 0.1, np.floor_divide, _FLOORDIV)
+ self._compareBoth(x, y, np.arctan2, math_ops.atan2)
+ x1 = np.random.randn(7, 4).astype(np.float64)
+ x2 = np.random.randn(7, 4).astype(np.float64)
+ # Remove tiny values--atan2 gradients are flaky near the origin.
+ x1[np.abs(x1) < 0.5] = 0.5 * np.sign(x1[np.abs(x1) < 0.5])
+ x2[np.abs(x2) < 0.5] = 0.5 * np.sign(x2[np.abs(x2) < 0.5])
+ self._compareBoth(x1, x2, np.arctan2, math_ops.atan2)
try:
from scipy import special # pylint: disable=g-import-not-at-top
a_pos_small = np.linspace(0.1, 2, 15).reshape(1, 3, 5).astype(np.float32)
@@ -1090,6 +1104,19 @@ class BinaryOpTest(test.TestCase):
error = gradient_checker.compute_gradient_error(y, [], z, [])
self.assertLess(error, 2e-4)
+ def testAtan2SpecialValues(self):
+ x1l, x2l = zip((+0.0, +0.0), (+0.0, -0.0), (-0.0, +0.0), (-0.0, -0.0),
+ (1.2345, float("inf")), (1.2345, -float("inf")),
+ (-4.321, float("inf")), (-4.125, -float("inf")),
+ (float("inf"), float("inf")), (float("inf"), -float("inf")),
+ (-float("inf"), float("inf")), (-float("inf"),
+ -float("inf")))
+ for dtype in np.float32, np.float64:
+ x1 = np.array(x1l).astype(dtype)
+ x2 = np.array(x2l).astype(dtype)
+ self._compareCpu(x1, x2, np.arctan2, math_ops.atan2)
+ self._compareGpu(x1, x2, np.arctan2, math_ops.atan2)
+
class ComparisonOpTest(test.TestCase):