(self, dev)
| 1452 | self._Log_helper(gpu_dev) |
| 1453 | |
| 1454 | def _mul_helper(self, dev): |
| 1455 | x = np.array([0.1, -1.0, 0.4, 4.0, -0.9, |
| 1456 | 9.0]).reshape(3, 2).astype(np.float32) |
| 1457 | x1 = np.array([0.1, 1.0, 0.4, 4.0, 0.9, |
| 1458 | 9.0]).reshape(3, 2).astype(np.float32) |
| 1459 | y = x * x1 |
| 1460 | dy = np.array([0.1, 1.0, 0.4, 4.0, 0.9, |
| 1461 | 9.0]).reshape(3, 2).astype(np.float32) |
| 1462 | grad0 = x1 * dy |
| 1463 | grad1 = x * dy |
| 1464 | |
| 1465 | x = tensor.from_numpy(x) |
| 1466 | slope = tensor.from_numpy(x1) |
| 1467 | dy = tensor.from_numpy(dy) |
| 1468 | x.to_device(dev) |
| 1469 | slope.to_device(dev) |
| 1470 | dy.to_device(dev) |
| 1471 | |
| 1472 | result = autograd.mul(x, slope) |
| 1473 | dx0, dx1 = result.creator.backward(dy.data) |
| 1474 | |
| 1475 | np.testing.assert_array_almost_equal(tensor.to_numpy(result), |
| 1476 | y, |
| 1477 | decimal=5) |
| 1478 | np.testing.assert_array_almost_equal(tensor.to_numpy( |
| 1479 | tensor.from_raw_tensor(dx0)), |
| 1480 | grad0, |
| 1481 | decimal=5) |
| 1482 | np.testing.assert_array_almost_equal(tensor.to_numpy( |
| 1483 | tensor.from_raw_tensor(dx1)), |
| 1484 | grad1, |
| 1485 | decimal=5) |
| 1486 | |
| 1487 | def test_mul_cpu(self): |
| 1488 | self._mul_helper(cpu_dev) |
no test coverage detected