(self, dev)
| 1733 | self._shape_helper(gpu_dev) |
| 1734 | |
| 1735 | def _min_helper(self, dev): |
| 1736 | X0 = np.array([0.1, 0.2, 2.0, 0.0, 0.1, |
| 1737 | 0.2]).reshape(3, 2).astype(np.float32) |
| 1738 | X1 = np.array([1.0, 2.0, 1.0, 2.1, 0.0, |
| 1739 | 2.0]).reshape(3, 2).astype(np.float32) |
| 1740 | XT = np.minimum(X0, X1) |
| 1741 | |
| 1742 | DY = np.ones((3, 2), dtype=np.float32) |
| 1743 | x0 = tensor.from_numpy(X0) |
| 1744 | x1 = tensor.from_numpy(X1) |
| 1745 | dy = tensor.from_numpy(DY) |
| 1746 | x0.to_device(dev) |
| 1747 | x1.to_device(dev) |
| 1748 | dy.to_device(dev) |
| 1749 | |
| 1750 | result = autograd.min(x0, x1) |
| 1751 | dx0, dx1 = result.creator.backward(dy.data) |
| 1752 | |
| 1753 | G = np.subtract(X0, X1) |
| 1754 | DX0 = np.where(G < 0, 1, G * 0) |
| 1755 | DX1 = np.where(G > 0, 1, G * 0) |
| 1756 | |
| 1757 | np.testing.assert_array_almost_equal(tensor.to_numpy(result), |
| 1758 | XT, |
| 1759 | decimal=5) |
| 1760 | np.testing.assert_array_almost_equal(tensor.to_numpy( |
| 1761 | tensor.from_raw_tensor(dx0)), |
| 1762 | DX0, |
| 1763 | decimal=5) |
| 1764 | np.testing.assert_array_almost_equal(tensor.to_numpy( |
| 1765 | tensor.from_raw_tensor(dx1)), |
| 1766 | DX1, |
| 1767 | decimal=5) |
| 1768 | |
| 1769 | def test_min_cpu(self): |
| 1770 | self._min_helper(cpu_dev) |
no test coverage detected