(self, dev)
| 747 | self._Relu_helper(gpu_dev) |
| 748 | |
| 749 | def _Cos_helper(self, dev): |
| 750 | X = np.array([0.8, -1.2, 3.3, -3.6, -0.5, |
| 751 | 0.5]).reshape(3, 2).astype(np.float32) |
| 752 | XT = np.cos(X) |
| 753 | DY = np.ones((3, 2), dtype=np.float32) |
| 754 | |
| 755 | x = tensor.from_numpy(X) |
| 756 | dy = tensor.from_numpy(DY) |
| 757 | x.to_device(dev) |
| 758 | dy.to_device(dev) |
| 759 | |
| 760 | result = autograd.cos(x) |
| 761 | dx = result.creator.backward(dy.data) |
| 762 | |
| 763 | G = -np.sin(X) |
| 764 | DX = np.multiply(G, DY) |
| 765 | |
| 766 | np.testing.assert_array_almost_equal(tensor.to_numpy(result), |
| 767 | XT, |
| 768 | decimal=5) |
| 769 | np.testing.assert_array_almost_equal(tensor.to_numpy( |
| 770 | tensor.from_raw_tensor(dx)), |
| 771 | DX, |
| 772 | decimal=5) |
| 773 | |
| 774 | def test_Cos_cpu(self): |
| 775 | self._Cos_helper(cpu_dev) |
no test coverage detected