(self, dev)
| 1706 | self._squeeze_helper(gpu_dev) |
| 1707 | |
| 1708 | def _shape_helper(self, dev): |
| 1709 | x = np.array([0.1, -1.0, 0.4, 4.0, -0.9, |
| 1710 | 9.0]).reshape(3, 2).astype(np.float32) |
| 1711 | y = list(x.shape) |
| 1712 | dy = np.ones((3, 2), dtype=np.float32) |
| 1713 | grad = list(dy.shape) |
| 1714 | |
| 1715 | x = tensor.from_numpy(x) |
| 1716 | dy = tensor.from_numpy(dy) |
| 1717 | x.to_device(dev) |
| 1718 | dy.to_device(dev) |
| 1719 | |
| 1720 | result = autograd.shape(x) |
| 1721 | dx = result.creator.backward(dy.data) |
| 1722 | |
| 1723 | np.testing.assert_array_almost_equal(tensor.to_numpy(result), |
| 1724 | y, |
| 1725 | decimal=5) |
| 1726 | np.testing.assert_array_almost_equal(dx, grad, decimal=5) |
| 1727 | |
| 1728 | def test_shape_cpu(self): |
| 1729 | self._shape_helper(cpu_dev) |
no test coverage detected