(self, dev)
| 606 | self._Abs_helper(gpu_dev) |
| 607 | |
| 608 | def _Mean_helper(self, dev): |
| 609 | x0 = np.array([-0.9, -0.3, -0.1, 0.1, 0.5, |
| 610 | 0.9]).reshape(3, 2).astype(np.float32) |
| 611 | x1 = np.array([0, -0.3, 0, 0.1, 0, 0.9]).reshape(3, |
| 612 | 2).astype(np.float32) |
| 613 | y = (x0 + x1) / 2 |
| 614 | grad = np.ones(x0.shape) / 2 |
| 615 | x0 = tensor.from_numpy(x0) |
| 616 | x1 = tensor.from_numpy(x1) |
| 617 | x0.to_device(dev) |
| 618 | x1.to_device(dev) |
| 619 | |
| 620 | result = autograd.mean(x0, x1) |
| 621 | dy = tensor.from_numpy(np.ones((3, 2)).astype(np.float32)) |
| 622 | dy.to_device(dev) |
| 623 | dx0, dx1 = result.creator.backward(dy.data) |
| 624 | |
| 625 | np.testing.assert_array_almost_equal(tensor.to_numpy(result), |
| 626 | y, |
| 627 | decimal=5) |
| 628 | np.testing.assert_array_almost_equal(tensor.to_numpy( |
| 629 | tensor.from_raw_tensor(dx0)), |
| 630 | grad, |
| 631 | decimal=5) |
| 632 | np.testing.assert_array_almost_equal(tensor.to_numpy( |
| 633 | tensor.from_raw_tensor(dx1)), |
| 634 | grad, |
| 635 | decimal=5) |
| 636 | |
| 637 | def test_Mean_cpu(self): |
| 638 | self._Mean_helper(cpu_dev) |
no test coverage detected