| 664 | self._Exp_helper(gpu_dev) |
| 665 | |
| 666 | def _Identity_helper(self, dev): |
| 667 | x = np.array([-0.9, -0.3, -0.1, 0.1, 0.5, |
| 668 | 0.9]).reshape(3, 2).astype(np.float32) |
| 669 | y = x.copy() |
| 670 | grad = np.ones(x.shape) |
| 671 | x = tensor.from_numpy(x) |
| 672 | x.to_device(dev) |
| 673 | |
| 674 | result = autograd.identity(x) |
| 675 | dy = tensor.from_numpy(np.ones((3, 2)).astype(np.float32)) |
| 676 | dy.to_device(dev) |
| 677 | dx = result.creator.backward(dy.data) |
| 678 | |
| 679 | np.testing.assert_array_almost_equal(tensor.to_numpy(result), |
| 680 | y, |
| 681 | decimal=5) |
| 682 | np.testing.assert_array_almost_equal(tensor.to_numpy( |
| 683 | tensor.from_raw_tensor(dx)), |
| 684 | grad, |
| 685 | decimal=5) |
| 686 | self.check_shape(dx.shape(), (3, 2)) |
| 687 | |
| 688 | def test_Identity_cpu(self): |
| 689 | self._Identity_helper(cpu_dev) |