(self, dev)
| 1563 | self._max_helper(gpu_dev) |
| 1564 | |
| 1565 | def _max_3inputs_helper(self, dev): |
| 1566 | data_0 = np.array([3, 2, 1]).astype(np.float32) |
| 1567 | data_1 = np.array([1, 4, 4]).astype(np.float32) |
| 1568 | data_2 = np.array([2, 5, 3]).astype(np.float32) |
| 1569 | XT = np.array([3, 5, 4]).astype(np.float32) |
| 1570 | |
| 1571 | DY = np.array([1, 1, 1]).astype(np.float32) |
| 1572 | x0 = tensor.from_numpy(data_0) |
| 1573 | x1 = tensor.from_numpy(data_1) |
| 1574 | x2 = tensor.from_numpy(data_2) |
| 1575 | dy = tensor.from_numpy(DY) |
| 1576 | x0.to_device(dev) |
| 1577 | x1.to_device(dev) |
| 1578 | x2.to_device(dev) |
| 1579 | dy.to_device(dev) |
| 1580 | |
| 1581 | result = autograd.max(x0, x1, x2) |
| 1582 | dx0, dx1, dx2 = result.creator.backward(dy.data) |
| 1583 | |
| 1584 | DX0 = np.array([1, 0, 0]).astype(np.float32) |
| 1585 | DX1 = np.array([0, 0, 1]).astype(np.float32) |
| 1586 | DX2 = np.array([0, 1, 0]).astype(np.float32) |
| 1587 | |
| 1588 | np.testing.assert_array_almost_equal(tensor.to_numpy(result), |
| 1589 | XT, |
| 1590 | decimal=5) |
| 1591 | np.testing.assert_array_almost_equal(tensor.to_numpy( |
| 1592 | tensor.from_raw_tensor(dx0)), |
| 1593 | DX0, |
| 1594 | decimal=5) |
| 1595 | np.testing.assert_array_almost_equal(tensor.to_numpy( |
| 1596 | tensor.from_raw_tensor(dx1)), |
| 1597 | DX1, |
| 1598 | decimal=5) |
| 1599 | np.testing.assert_array_almost_equal(tensor.to_numpy( |
| 1600 | tensor.from_raw_tensor(dx2)), |
| 1601 | DX2, |
| 1602 | decimal=5) |
| 1603 | |
| 1604 | def test_max_3inputs_cpu(self): |
| 1605 | self._max_3inputs_helper(cpu_dev) |
no test coverage detected