(self, dev)
| 1332 | self._unsqueeze_helper(gpu_dev) |
| 1333 | |
| 1334 | def _Sqrt_helper(self, dev): |
| 1335 | X = np.array([0.1, 1.0, 0.4, 4.0, 0.9, |
| 1336 | 9.0]).reshape(3, 2).astype(np.float32) |
| 1337 | XT = np.sqrt(X) |
| 1338 | DY = np.ones((3, 2), dtype=np.float32) |
| 1339 | |
| 1340 | x = tensor.from_numpy(X) |
| 1341 | dy = tensor.from_numpy(DY) |
| 1342 | x.to_device(dev) |
| 1343 | dy.to_device(dev) |
| 1344 | |
| 1345 | result = autograd.sqrt(x) |
| 1346 | dx = result.creator.backward(dy.data) |
| 1347 | |
| 1348 | G = 0.5 * np.power(X, -0.5) |
| 1349 | DX = np.multiply(G, DY) |
| 1350 | |
| 1351 | np.testing.assert_array_almost_equal(tensor.to_numpy(result), |
| 1352 | XT, |
| 1353 | decimal=5) |
| 1354 | np.testing.assert_array_almost_equal(tensor.to_numpy( |
| 1355 | tensor.from_raw_tensor(dx)), |
| 1356 | DX, |
| 1357 | decimal=5) |
| 1358 | |
| 1359 | def test_Sqrt_cpu(self): |
| 1360 | self._Sqrt_helper(cpu_dev) |
no test coverage detected