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

Method _Sign_helper

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

Source from the content-addressed store, hash-verified

1392 self._transpose_helper(gpu_dev)
1393
1394 def _Sign_helper(self, dev):
1395 X = np.array([0.8, -1.2, 3.3, -3.6, -0.5,
1396 0.5]).reshape(3, 2).astype(np.float32)
1397 XT = np.sign(X)
1398 DY = np.ones((3, 2), dtype=np.float32)
1399
1400 x = tensor.from_numpy(X)
1401 dy = tensor.from_numpy(DY)
1402 x.to_device(dev)
1403 dy.to_device(dev)
1404 result = autograd.sign(x)
1405 dx = result.creator.backward(dy.data)
1406 DX = np.multiply(DY, 0)
1407
1408 np.testing.assert_array_almost_equal(tensor.to_numpy(result),
1409 XT,
1410 decimal=5)
1411 np.testing.assert_array_almost_equal(tensor.to_numpy(
1412 tensor.from_raw_tensor(dx)),
1413 DX,
1414 decimal=5)
1415
1416 def test_Sign_cpu(self):
1417 self._Sign_helper(cpu_dev)

Callers 2

test_Sign_cpuMethod · 0.95
test_Sign_gpuMethod · 0.95

Calls 3

reshapeMethod · 0.45
to_deviceMethod · 0.45
backwardMethod · 0.45

Tested by

no test coverage detected