MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / testFloatOps

Method testFloatOps

tensorflow/compiler/tests/binary_ops_test.py:74–243  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

72 result[i], expected[i], rtol=rtol, atol=atol)
73
74 def testFloatOps(self):
75 for dtype in self.float_types:
76 if dtype == dtypes.bfloat16.as_numpy_dtype:
77 a = -1.01
78 b = 4.1
79 else:
80 a = -1.001
81 b = 4.01
82
83 self._testBinary(
84 lambda x, y: math_ops.approximate_equal(x, y, tolerance=0.0001),
85 np.array([[[[-1, 2.00009999], [-3, b]]]], dtype=dtype),
86 np.array([[[[a, 2], [-3.00009, 4]]]], dtype=dtype),
87 expected=np.array([[[[False, True], [True, False]]]], dtype=dtype))
88
89 self._testBinary(
90 gen_math_ops.real_div,
91 np.array([3, 3, -1.5, -8, 44], dtype=dtype),
92 np.array([2, -2, 7, -4, 0], dtype=dtype),
93 expected=np.array(
94 [1.5, -1.5, -0.2142857, 2, float("inf")], dtype=dtype),
95 rtol=1e-6,
96 atol=1e-8)
97
98 self._testBinary(
99 math_ops.atan2,
100 np.array([0, np.sqrt(2), 1, np.sqrt(2), 0], dtype),
101 np.array([1, np.sqrt(2), 0, -np.sqrt(2), -1], dtype),
102 expected=np.array(
103 [0, np.pi / 4, np.pi / 2, np.pi * 3 / 4, np.pi], dtype=dtype))
104
105 self._testBinary(
106 gen_math_ops.reciprocal_grad,
107 np.array([4, -3, -2, 1], dtype=dtype),
108 np.array([5, -6, 7, -8], dtype=dtype),
109 expected=np.array([-80, 54, -28, 8], dtype=dtype))
110
111 self._testBinary(
112 gen_math_ops.sigmoid_grad,
113 np.array([4, 3, 2, 1], dtype=dtype),
114 np.array([5, 6, 7, 8], dtype=dtype),
115 expected=np.array([-60, -36, -14, 0], dtype=dtype))
116
117 self._testBinary(
118 gen_math_ops.rsqrt_grad,
119 np.array([4, 3, 2, 1], dtype=dtype),
120 np.array([5, 6, 7, 8], dtype=dtype),
121 expected=np.array([-160, -81, -28, -4], dtype=dtype))
122
123 self._testBinary(
124 gen_math_ops.sqrt_grad,
125 np.array([4, 3, 2, 1], dtype=dtype),
126 np.array([5, 6, 7, 8], dtype=dtype),
127 expected=np.array([0.625, 1, 1.75, 4], dtype=dtype))
128
129 self._testBinary(
130 gen_nn_ops.softplus_grad,
131 np.array([4, 3, 2, 1], dtype=dtype),

Callers

nothing calls this directly

Calls 1

_testBinaryMethod · 0.95

Tested by

no test coverage detected