(self, dev)
| 1268 | self._SoftSign_helper(gpu_dev) |
| 1269 | |
| 1270 | def _SoftPlus_helper(self, dev): |
| 1271 | #y = np.log(np.exp(x) + 1) |
| 1272 | X = np.array([0.8, -1.2, 3.3, -3.6, -0.5, |
| 1273 | 0.5]).reshape(3, 2).astype(np.float32) |
| 1274 | XT = np.log(np.exp(X) + 1) |
| 1275 | DY = np.ones((3, 2), dtype=np.float32) |
| 1276 | |
| 1277 | x = tensor.from_numpy(X) |
| 1278 | dy = tensor.from_numpy(DY) |
| 1279 | x.to_device(dev) |
| 1280 | dy.to_device(dev) |
| 1281 | |
| 1282 | result = autograd.softplus(x) |
| 1283 | dx = result.creator.backward(dy.data) |
| 1284 | |
| 1285 | G = 1.0 / (1.0 + np.exp(-X)) |
| 1286 | DX = np.multiply(G, DY) |
| 1287 | |
| 1288 | np.testing.assert_array_almost_equal(tensor.to_numpy(result), |
| 1289 | XT, |
| 1290 | decimal=5) |
| 1291 | np.testing.assert_array_almost_equal(tensor.to_numpy( |
| 1292 | tensor.from_raw_tensor(dx)), |
| 1293 | DX, |
| 1294 | decimal=5) |
| 1295 | |
| 1296 | def test_SoftPlus_cpu(self): |
| 1297 | self._SoftPlus_helper(cpu_dev) |
no test coverage detected