(self, dev)
| 1522 | self._reshape_helper(gpu_dev) |
| 1523 | |
| 1524 | def _max_helper(self, dev): |
| 1525 | X0 = np.array([0.1, 0.2, 2.0, 0.0, 0.1, |
| 1526 | 0.2]).reshape(3, 2).astype(np.float32) |
| 1527 | X1 = np.array([1.0, 2.0, 1.0, 2.1, 0.0, |
| 1528 | 2.0]).reshape(3, 2).astype(np.float32) |
| 1529 | XT = np.maximum(X0, X1) |
| 1530 | |
| 1531 | DY = np.ones((3, 2), dtype=np.float32) |
| 1532 | x0 = tensor.from_numpy(X0) |
| 1533 | x1 = tensor.from_numpy(X1) |
| 1534 | dy = tensor.from_numpy(DY) |
| 1535 | x0.to_device(dev) |
| 1536 | x1.to_device(dev) |
| 1537 | dy.to_device(dev) |
| 1538 | |
| 1539 | result = autograd.max(x0, x1) |
| 1540 | dx0, dx1 = result.creator.backward(dy.data) |
| 1541 | |
| 1542 | G = np.subtract(X0, X1) |
| 1543 | DX0 = np.where(G > 0, 1, G * 0) |
| 1544 | DX1 = np.where(G < 0, 1, G * 0) |
| 1545 | |
| 1546 | np.testing.assert_array_almost_equal(tensor.to_numpy(result), |
| 1547 | XT, |
| 1548 | decimal=5) |
| 1549 | np.testing.assert_array_almost_equal(tensor.to_numpy( |
| 1550 | tensor.from_raw_tensor(dx0)), |
| 1551 | DX0, |
| 1552 | decimal=5) |
| 1553 | np.testing.assert_array_almost_equal(tensor.to_numpy( |
| 1554 | tensor.from_raw_tensor(dx1)), |
| 1555 | DX1, |
| 1556 | decimal=5) |
| 1557 | |
| 1558 | def test_max_cpu(self): |
| 1559 | self._max_helper(cpu_dev) |
no test coverage detected