(self, dev)
| 1918 | self._prelu_helper(gpu_dev) |
| 1919 | |
| 1920 | def _SeLU_helper(self, dev): |
| 1921 | x = np.random.randn(3, 2) |
| 1922 | a = 0.2 |
| 1923 | g = 0.3 |
| 1924 | y = np.clip(x, 0, |
| 1925 | np.inf) * g + (np.exp(np.clip(x, -np.inf, 0)) - 1) * a * g |
| 1926 | dy = np.random.randn(3, 2) |
| 1927 | grad = (np.exp(np.clip(x, -np.inf, 0))) * g |
| 1928 | grad[x <= 0] = grad[x <= 0] * a |
| 1929 | grad *= dy |
| 1930 | |
| 1931 | x = tensor.from_numpy(x) |
| 1932 | dy = tensor.from_numpy(dy) |
| 1933 | x.to_device(dev) |
| 1934 | dy.to_device(dev) |
| 1935 | result = autograd.selu(x, a, g) |
| 1936 | dx = result.creator.backward(dy.data) |
| 1937 | np.testing.assert_array_almost_equal(tensor.to_numpy(result), |
| 1938 | y, |
| 1939 | decimal=5) |
| 1940 | np.testing.assert_array_almost_equal(tensor.to_numpy( |
| 1941 | tensor.from_raw_tensor(dx)), |
| 1942 | grad, |
| 1943 | decimal=5) |
| 1944 | |
| 1945 | def test_SeLU_cpu(self): |
| 1946 | self._SeLU_helper(cpu_dev) |
no test coverage detected