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

Method _sum_helper

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

Source from the content-addressed store, hash-verified

425 self._reshape_helper(gpu_dev)
426
427 def _sum_helper(self, dev):
428 x = np.array([0.1, -1.0, 0.4, 4.0, -0.9,
429 9.0]).reshape(3, 2).astype(np.float32)
430 x1 = np.array([0.1, 1.0, 0.4, 4.0, 0.9,
431 9.0]).reshape(3, 2).astype(np.float32)
432 x = tensor.from_numpy(x)
433 x1 = tensor.from_numpy(x1)
434 y = autograd.Sum()(x, x1)[0]
435
436 # frontend
437 model = sonnx.to_onnx([x, x1], [y])
438 # print('The model is:\n{}'.format(model))
439
440 # backend
441 sg_ir = sonnx.prepare(model, device=dev)
442 sg_ir.is_graph = True
443 y_t = sg_ir.run([x, x1])
444
445 np.testing.assert_array_almost_equal(tensor.to_numpy(y),
446 tensor.to_numpy(y_t[0]),
447 decimal=5)
448
449 def test_sum_cpu(self):
450 self._sum_helper(cpu_dev)

Callers 2

test_sum_cpuMethod · 0.95
test_sum_gpuMethod · 0.95

Calls 3

prepareMethod · 0.80
reshapeMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected