(self, dev)
| 250 | self._pooling_same_pad(gpu_dev, "SAME_UPPER", False) |
| 251 | |
| 252 | def _sum_helper(self, dev): |
| 253 | x = np.array([0.1, -1.0, 0.4, 4.0, -0.9, |
| 254 | 9.0]).reshape(3, 2).astype(np.float32) |
| 255 | x1 = np.array([0.1, 1.0, 0.4, 4.0, 0.9, |
| 256 | 9.0]).reshape(3, 2).astype(np.float32) |
| 257 | y = x + x1 |
| 258 | dy = np.ones((3, 2), dtype=np.float32) |
| 259 | grad0 = dy |
| 260 | grad1 = dy |
| 261 | x = tensor.from_numpy(x) |
| 262 | x1 = tensor.from_numpy(x1) |
| 263 | dy = tensor.from_numpy(dy) |
| 264 | x.to_device(dev) |
| 265 | x1.to_device(dev) |
| 266 | dy.to_device(dev) |
| 267 | |
| 268 | result = autograd.sum(x, x1) |
| 269 | dx0, dx1 = result.creator.backward(dy.data) |
| 270 | |
| 271 | np.testing.assert_array_almost_equal(tensor.to_numpy(result), |
| 272 | y, |
| 273 | decimal=5) |
| 274 | np.testing.assert_array_almost_equal(tensor.to_numpy( |
| 275 | tensor.from_raw_tensor(dx0)), |
| 276 | grad0, |
| 277 | decimal=5) |
| 278 | np.testing.assert_array_almost_equal(tensor.to_numpy( |
| 279 | tensor.from_raw_tensor(dx1)), |
| 280 | grad1, |
| 281 | decimal=5) |
| 282 | |
| 283 | def test_sum_cpu(self): |
| 284 | self._sum_helper(cpu_dev) |
no test coverage detected