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

Method _HardSigmoid_helper

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

Source from the content-addressed store, hash-verified

1042 self._Greater_helper(gpu_dev)
1043
1044 def _HardSigmoid_helper(self, dev):
1045 x = np.array([-0.9, -0.3, -0.1, 0.1, 0.5,
1046 0.9]).reshape(3, 2).astype(np.float32)
1047 a = 0.2
1048 g = 0.5
1049
1050 x = tensor.from_numpy(x)
1051 x.to_device(dev)
1052 y = autograd.hardsigmoid(x, a, g)
1053
1054 # frontend
1055 model = sonnx.to_onnx([x], [y])
1056 # print('The model is:\n{}'.format(model))
1057
1058 # backend
1059 sg_ir = sonnx.prepare(model, device=dev)
1060 sg_ir.is_graph = True
1061 y_t = sg_ir.run([x])
1062
1063 np.testing.assert_array_almost_equal(tensor.to_numpy(y),
1064 tensor.to_numpy(y_t[0]),
1065 decimal=5)
1066
1067 def test_HardSigmoid_cpu(self):
1068 self._HardSigmoid_helper(cpu_dev)

Callers 2

test_HardSigmoid_cpuMethod · 0.95
test_HardSigmoid_gpuMethod · 0.95

Calls 4

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

Tested by

no test coverage detected