MCPcopy Create free account
hub / github.com/apache/singa / _Sqrt_helper

Method _Sqrt_helper

test/python/test_operation.py:1334–1357  ·  view source on GitHub ↗
(self, dev)

Source from the content-addressed store, hash-verified

1332 self._unsqueeze_helper(gpu_dev)
1333
1334 def _Sqrt_helper(self, dev):
1335 X = np.array([0.1, 1.0, 0.4, 4.0, 0.9,
1336 9.0]).reshape(3, 2).astype(np.float32)
1337 XT = np.sqrt(X)
1338 DY = np.ones((3, 2), dtype=np.float32)
1339
1340 x = tensor.from_numpy(X)
1341 dy = tensor.from_numpy(DY)
1342 x.to_device(dev)
1343 dy.to_device(dev)
1344
1345 result = autograd.sqrt(x)
1346 dx = result.creator.backward(dy.data)
1347
1348 G = 0.5 * np.power(X, -0.5)
1349 DX = np.multiply(G, DY)
1350
1351 np.testing.assert_array_almost_equal(tensor.to_numpy(result),
1352 XT,
1353 decimal=5)
1354 np.testing.assert_array_almost_equal(tensor.to_numpy(
1355 tensor.from_raw_tensor(dx)),
1356 DX,
1357 decimal=5)
1358
1359 def test_Sqrt_cpu(self):
1360 self._Sqrt_helper(cpu_dev)

Callers 2

test_Sqrt_cpuMethod · 0.95
test_Sqrt_gpuMethod · 0.95

Calls 3

reshapeMethod · 0.45
to_deviceMethod · 0.45
backwardMethod · 0.45

Tested by

no test coverage detected