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

Method _ELu_helper

test/python/test_onnx.py:799–820  ·  view source on GitHub ↗
(self, dev)

Source from the content-addressed store, hash-verified

797 self._SeLu_helper(gpu_dev)
798
799 def _ELu_helper(self, dev):
800 x = np.array([-0.9, -0.3, -0.1, 0.1, 0.5,
801 0.9]).reshape(3, 2).astype(np.float32)
802 #y = gamma * (alpha * e^x - alpha) for x <= 0, y = gamma * x for x > 0
803 a = 1.
804 x = tensor.from_numpy(x)
805 x.to_device(dev)
806
807 y = autograd.elu(x, a)
808
809 # frontend
810 model = sonnx.to_onnx([x], [y])
811 # print('The model is:\n{}'.format(model))
812
813 # backend
814 sg_ir = sonnx.prepare(model, device=dev)
815 sg_ir.is_graph = True
816 y_t = sg_ir.run([x])
817
818 np.testing.assert_array_almost_equal(tensor.to_numpy(y),
819 tensor.to_numpy(y_t[0]),
820 decimal=5)
821
822 def test_ELu_cpu(self):
823 self._ELu_helper(cpu_dev)

Callers 2

test_ELu_cpuMethod · 0.95
test_ELu_gpuMethod · 0.95

Calls 4

prepareMethod · 0.80
reshapeMethod · 0.45
to_deviceMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected