(self, dev)
| 1421 | self._Sign_helper(gpu_dev) |
| 1422 | |
| 1423 | def _Log_helper(self, dev): |
| 1424 | X = np.array([0.1, 1.0, 0.4, 1.4, 0.9, |
| 1425 | 2.0]).reshape(3, 2).astype(np.float32) |
| 1426 | XT = np.log(X) |
| 1427 | DY = np.ones((3, 2), dtype=np.float32) |
| 1428 | |
| 1429 | x = tensor.from_numpy(X) |
| 1430 | dy = tensor.from_numpy(DY) |
| 1431 | x.to_device(dev) |
| 1432 | dy.to_device(dev) |
| 1433 | result = autograd.log(x) |
| 1434 | dx = result.creator.backward(dy.data) |
| 1435 | #dx = 1/x |
| 1436 | G = 1.0 / X |
| 1437 | DX = np.multiply(G, DY) |
| 1438 | |
| 1439 | np.testing.assert_array_almost_equal(tensor.to_numpy(result), |
| 1440 | XT, |
| 1441 | decimal=5) |
| 1442 | np.testing.assert_array_almost_equal(tensor.to_numpy( |
| 1443 | tensor.from_raw_tensor(dx)), |
| 1444 | DX, |
| 1445 | decimal=5) |
| 1446 | |
| 1447 | def test_Log_cpu(self): |
| 1448 | self._Log_helper(cpu_dev) |
no test coverage detected