(self, dev)
| 1364 | self._Sqrt_helper(gpu_dev) |
| 1365 | |
| 1366 | def _transpose_helper(self, dev): |
| 1367 | x = np.random.randn(3, 2, 1) |
| 1368 | y = x.transpose(1, 2, 0) |
| 1369 | dy = np.random.randn(*(y.shape)) |
| 1370 | grad = dy.transpose((2, 0, 1)) |
| 1371 | |
| 1372 | x = tensor.from_numpy(x) |
| 1373 | dy = tensor.from_numpy(dy) |
| 1374 | x.to_device(dev) |
| 1375 | dy.to_device(dev) |
| 1376 | |
| 1377 | result = autograd.transpose(x, (1, 2, 0)) |
| 1378 | dx = result.creator.backward(dy.data) |
| 1379 | np.testing.assert_array_almost_equal(tensor.to_numpy(result), |
| 1380 | y, |
| 1381 | decimal=5) |
| 1382 | np.testing.assert_array_almost_equal(tensor.to_numpy( |
| 1383 | tensor.from_raw_tensor(dx)), |
| 1384 | grad, |
| 1385 | decimal=5) |
| 1386 | |
| 1387 | def test_transpose_cpu(self): |
| 1388 | self._transpose_helper(cpu_dev) |
no test coverage detected