(self)
| 1021 | class GeluTest(test_lib.TestCase): |
| 1022 | |
| 1023 | def test(self): |
| 1024 | |
| 1025 | def gelu(x, approximate=False): |
| 1026 | if approximate: |
| 1027 | return 0.5 * x * (1.0 + np.tanh(np.sqrt(2.0 / np.pi) * |
| 1028 | (x + 0.044715 * np.power(x, 3)))) |
| 1029 | else: |
| 1030 | from scipy.stats import norm # pylint: disable=g-import-not-at-top |
| 1031 | return x * norm.cdf(x) |
| 1032 | |
| 1033 | np.random.seed(1) # Make it reproducible. |
| 1034 | x = np.random.randn(3, 4).astype(np.float32) |
| 1035 | y = gelu(x) |
| 1036 | z = self.evaluate(nn_ops.gelu(constant_op.constant(x))) |
| 1037 | self.assertAllClose(y, z) |
| 1038 | |
| 1039 | y = gelu(x, True) |
| 1040 | z = self.evaluate(nn_ops.gelu(constant_op.constant(x), True)) |
| 1041 | self.assertAllClose(y, z) |
| 1042 | |
| 1043 | |
| 1044 | class CReluTest(test_lib.TestCase): |
no test coverage detected