(self, dev)
| 1492 | self._mul_helper(gpu_dev) |
| 1493 | |
| 1494 | def _reshape_helper(self, dev): |
| 1495 | x = np.array([0.1, -1.0, 0.4, 4.0, -0.9, |
| 1496 | 9.0]).reshape(3, 2).astype(np.float32) |
| 1497 | y = x.reshape(2, 3) |
| 1498 | dy = np.array([1, 2, 3, 4, 5, 6]).reshape(2, 3).astype(np.float32) |
| 1499 | grad = dy.reshape(3, 2) |
| 1500 | |
| 1501 | x = tensor.from_numpy(x) |
| 1502 | dy = tensor.from_numpy(dy) |
| 1503 | x.to_device(dev) |
| 1504 | dy.to_device(dev) |
| 1505 | |
| 1506 | result = autograd.reshape(x, (2, 3)) |
| 1507 | dx = result.creator.backward(dy.data) |
| 1508 | |
| 1509 | np.testing.assert_array_almost_equal(tensor.to_numpy(result), |
| 1510 | y, |
| 1511 | decimal=5) |
| 1512 | np.testing.assert_array_almost_equal(tensor.to_numpy( |
| 1513 | tensor.from_raw_tensor(dx)), |
| 1514 | grad, |
| 1515 | decimal=5) |
| 1516 | |
| 1517 | def test_reshape_cpu(self): |
| 1518 | self._reshape_helper(cpu_dev) |
no test coverage detected