(self, dev)
| 715 | self._LeakyRelu_helper(gpu_dev) |
| 716 | |
| 717 | def _Relu_helper(self, dev): |
| 718 | X = np.array([0.8, -1.2, 3.3, -3.6, -0.5, |
| 719 | 0.5]).reshape(3, 2).astype(np.float32) |
| 720 | XT = np.maximum(X, 0) |
| 721 | DY = np.ones((3, 2), dtype=np.float32) |
| 722 | |
| 723 | x = tensor.from_numpy(X) |
| 724 | dy = tensor.from_numpy(DY) |
| 725 | x.to_device(dev) |
| 726 | dy.to_device(dev) |
| 727 | |
| 728 | result = autograd.relu(x) |
| 729 | dx = result.creator.backward(dy.data) |
| 730 | |
| 731 | G = (X > 0).astype(np.float32) |
| 732 | DX = np.multiply(G, DY) |
| 733 | |
| 734 | np.testing.assert_array_almost_equal(tensor.to_numpy(result), |
| 735 | XT, |
| 736 | decimal=5) |
| 737 | np.testing.assert_array_almost_equal(tensor.to_numpy( |
| 738 | tensor.from_raw_tensor(dx)), |
| 739 | DX, |
| 740 | decimal=5) |
| 741 | |
| 742 | def test_Relu_cpu(self): |
| 743 | self._Relu_helper(cpu_dev) |
no test coverage detected