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

Method _reciprocal_helper

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

Source from the content-addressed store, hash-verified

1589 self._negative_helper(gpu_dev)
1590
1591 def _reciprocal_helper(self, dev):
1592 X = np.array([0.1, 0, 0.4, 1. - 4, 0.9,
1593 -2.0]).reshape(3, 2).astype(np.float32)
1594 x = tensor.from_numpy(X)
1595 x.to_device(cpu_dev)
1596
1597 y = autograd.reciprocal(x)
1598 # frontend
1599 model = sonnx.to_onnx([x], [y])
1600 # print('The model is:\n{}'.format(model))
1601
1602 # backend
1603 sg_ir = sonnx.prepare(model, device=dev)
1604 sg_ir.is_graph = True
1605 y_t = sg_ir.run([x])
1606
1607 np.testing.assert_array_almost_equal(tensor.to_numpy(y),
1608 tensor.to_numpy(y_t[0]),
1609 decimal=5)
1610
1611 def test_reciprocal_cpu(self):
1612 self._reciprocal_helper(cpu_dev)

Callers 2

test_reciprocal_cpuMethod · 0.95
test_reciprocal_gpuMethod · 0.95

Calls 4

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

Tested by

no test coverage detected