(self, dev)
| 1635 | self._max_1inputs_helper(gpu_dev) |
| 1636 | |
| 1637 | def _Div_helper(self, dev): |
| 1638 | X0 = np.array([7, -5, 0.2, -0.1, 0.3, 4]).reshape(3, |
| 1639 | 2).astype(np.float32) |
| 1640 | X1 = np.array([0.6, -1.3, 0.1, -0.1, 0.4, |
| 1641 | 0.3]).reshape(3, 2).astype(np.float32) |
| 1642 | XT = np.divide(X0, X1) |
| 1643 | |
| 1644 | DY = np.ones((3, 2), dtype=np.float32) |
| 1645 | x0 = tensor.from_numpy(X0) |
| 1646 | x1 = tensor.from_numpy(X1) |
| 1647 | dy = tensor.from_numpy(DY) |
| 1648 | x0.to_device(dev) |
| 1649 | x1.to_device(dev) |
| 1650 | dy.to_device(dev) |
| 1651 | |
| 1652 | result = autograd.div(x0, x1) |
| 1653 | dx0, dx1 = result.creator.backward(dy.data) |
| 1654 | |
| 1655 | G0 = 1.0 / X1 |
| 1656 | DX0 = np.multiply(G0, DY) |
| 1657 | G1 = np.divide(-X0, np.square(X1)) |
| 1658 | DX1 = np.multiply(G1, DY) |
| 1659 | |
| 1660 | np.testing.assert_array_almost_equal(tensor.to_numpy(result), |
| 1661 | XT, |
| 1662 | decimal=5) |
| 1663 | np.testing.assert_array_almost_equal(tensor.to_numpy( |
| 1664 | tensor.from_raw_tensor(dx0)), |
| 1665 | DX0, |
| 1666 | decimal=5) |
| 1667 | np.testing.assert_array_almost_equal(tensor.to_numpy( |
| 1668 | tensor.from_raw_tensor(dx1)), |
| 1669 | DX1, |
| 1670 | decimal=5) |
| 1671 | |
| 1672 | def test_Div_cpu(self): |
| 1673 | self._Div_helper(cpu_dev) |
no test coverage detected