(self, dev)
| 1301 | self._SoftPlus_helper(gpu_dev) |
| 1302 | |
| 1303 | def _unsqueeze_helper(self, dev): |
| 1304 | data = [0.1, -1.0, 0.4, 4.0, -0.9, 9.0] |
| 1305 | |
| 1306 | x = np.array(data).reshape(1, 2, 3).astype(np.float32) |
| 1307 | y = x.reshape(1, 1, 2, 3, 1) |
| 1308 | dy = np.ones((1, 1, 2, 3, 1), dtype=np.float32) |
| 1309 | grad = dy.reshape(1, 2, 3) |
| 1310 | |
| 1311 | x = tensor.from_numpy(x) |
| 1312 | dy = tensor.from_numpy(dy) |
| 1313 | x.to_device(dev) |
| 1314 | dy.to_device(dev) |
| 1315 | |
| 1316 | result = autograd.unsqueeze(x, [0, 4]) |
| 1317 | dx = result.creator.backward(dy.data) |
| 1318 | |
| 1319 | np.testing.assert_array_almost_equal(tensor.to_numpy(result), |
| 1320 | y, |
| 1321 | decimal=5) |
| 1322 | np.testing.assert_array_almost_equal(tensor.to_numpy( |
| 1323 | tensor.from_raw_tensor(dx)), |
| 1324 | grad, |
| 1325 | decimal=5) |
| 1326 | |
| 1327 | def test_unsqueeze_cpu(self): |
| 1328 | self._unsqueeze_helper(cpu_dev) |
no test coverage detected