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

Method _SoftPlus_helper

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

Source from the content-addressed store, hash-verified

1268 self._SoftSign_helper(gpu_dev)
1269
1270 def _SoftPlus_helper(self, dev):
1271 #y = np.log(np.exp(x) + 1)
1272 X = np.array([0.8, -1.2, 3.3, -3.6, -0.5,
1273 0.5]).reshape(3, 2).astype(np.float32)
1274 XT = np.log(np.exp(X) + 1)
1275 DY = np.ones((3, 2), dtype=np.float32)
1276
1277 x = tensor.from_numpy(X)
1278 dy = tensor.from_numpy(DY)
1279 x.to_device(dev)
1280 dy.to_device(dev)
1281
1282 result = autograd.softplus(x)
1283 dx = result.creator.backward(dy.data)
1284
1285 G = 1.0 / (1.0 + np.exp(-X))
1286 DX = np.multiply(G, DY)
1287
1288 np.testing.assert_array_almost_equal(tensor.to_numpy(result),
1289 XT,
1290 decimal=5)
1291 np.testing.assert_array_almost_equal(tensor.to_numpy(
1292 tensor.from_raw_tensor(dx)),
1293 DX,
1294 decimal=5)
1295
1296 def test_SoftPlus_cpu(self):
1297 self._SoftPlus_helper(cpu_dev)

Callers 2

test_SoftPlus_cpuMethod · 0.95
test_SoftPlus_gpuMethod · 0.95

Calls 3

reshapeMethod · 0.45
to_deviceMethod · 0.45
backwardMethod · 0.45

Tested by

no test coverage detected