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

Method _SoftSign_helper

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

Source from the content-addressed store, hash-verified

1235 self._Pow_helper(gpu_dev)
1236
1237 def _SoftSign_helper(self, dev):
1238 # y = x / (1 + np.abs(x))
1239 X = np.array([0.8, -1.2, 3.3, -3.6, -0.5,
1240 0.5]).reshape(3, 2).astype(np.float32)
1241 XT = X / (1 + np.absolute(X))
1242 DY = np.ones((3, 2), dtype=np.float32)
1243
1244 x = tensor.from_numpy(X)
1245 dy = tensor.from_numpy(DY)
1246 x.to_device(dev)
1247 dy.to_device(dev)
1248
1249 result = autograd.softsign(x)
1250 dx = result.creator.backward(dy.data)
1251
1252 G = 1.0 / np.square(np.absolute(X) + 1.0)
1253 DX = np.multiply(G, DY)
1254
1255 np.testing.assert_array_almost_equal(tensor.to_numpy(result),
1256 XT,
1257 decimal=5)
1258 np.testing.assert_array_almost_equal(tensor.to_numpy(
1259 tensor.from_raw_tensor(dx)),
1260 DX,
1261 decimal=5)
1262
1263 def test_SoftSign_cpu(self):
1264 self._SoftSign_helper(cpu_dev)

Callers 2

test_SoftSign_cpuMethod · 0.95
test_SoftSign_gpuMethod · 0.95

Calls 3

reshapeMethod · 0.45
to_deviceMethod · 0.45
backwardMethod · 0.45

Tested by

no test coverage detected