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

Method erf_helper

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

Source from the content-addressed store, hash-verified

3624 np.testing.assert_array_almost_equal(tensor.to_numpy(sloss), np_loss)
3625
3626 def erf_helper(self, dev):
3627 X = np.array([
3628 0.1, 0.5, 0.9, 1.2, 1.5, 1.8, 2.3, 2.5, 2.7, -1.1, -1.5, -1.9, -2.2,
3629 -2.5, -2.8
3630 ]).astype(np.float32)
3631 x = tensor.from_numpy(X)
3632 x.to_device(dev)
3633
3634 import math
3635
3636 y_t = np.vectorize(math.erf)(X)
3637 dy = tensor.from_numpy(y_t)
3638 dy.to_device(dev)
3639 dx_t = 2. / np.pi**0.5 * np.exp(-np.power(y_t, 2))
3640
3641 y = autograd.erf(x)
3642 dx = y.creator.backward(dy.data)
3643 np.testing.assert_array_almost_equal(tensor.to_numpy(y), y_t)
3644 np.testing.assert_array_almost_equal(
3645 tensor.to_numpy(tensor.from_raw_tensor(dx)), dx_t)
3646
3647 def test_erf_cpu(self):
3648 self.erf_helper(cpu_dev)

Callers 2

test_erf_cpuMethod · 0.95
test_erf_gpuMethod · 0.95

Calls 2

to_deviceMethod · 0.45
backwardMethod · 0.45

Tested by

no test coverage detected