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

Method _clip_helper

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

Source from the content-addressed store, hash-verified

1219 self._pow_helper(gpu_dev)
1220
1221 def _clip_helper(self, dev):
1222 x = np.array([-0.9, -0.3, -0.1, 0.1, 0.5,
1223 0.9]).reshape(3, 2).astype(np.float32)
1224
1225 x = tensor.from_numpy(x)
1226 min = -0.5
1227 max = 0.5
1228 x.to_device(dev)
1229
1230 y = autograd.clip(x, min, max)
1231
1232 # frontend
1233 model = sonnx.to_onnx([x, min, max], [y])
1234 # print('The model is:\n{}'.format(model))
1235
1236 # backend
1237 sg_ir = sonnx.prepare(model, device=dev)
1238 sg_ir.is_graph = True
1239 y_t = sg_ir.run([x]) # min, max has been stored in model
1240
1241 np.testing.assert_array_almost_equal(tensor.to_numpy(y),
1242 tensor.to_numpy(y_t[0]),
1243 decimal=5)
1244
1245 def test_clip_cpu(self):
1246 self._clip_helper(cpu_dev)

Callers 2

test_clip_cpuMethod · 0.95
test_clip_gpuMethod · 0.95

Calls 4

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

Tested by

no test coverage detected