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

Method _constantOfShape_helper

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

Source from the content-addressed store, hash-verified

1616 self._reciprocal_helper(gpu_dev)
1617
1618 def _constantOfShape_helper(self, dev):
1619 X = np.array([4, 3, 2]).astype(np.int64)
1620 x = tensor.from_numpy(X)
1621 x.to_device(cpu_dev)
1622
1623 y = autograd.constant_of_shape(x, 1.)
1624 # frontend
1625 model = sonnx.to_onnx([x], [y])
1626 # print('The model is:\n{}'.format(model))
1627
1628 # backend
1629 sg_ir = sonnx.prepare(model, device=dev, init_inputs=[X])
1630 sg_ir.is_graph = True
1631 y_t = sg_ir.run([x])
1632
1633 np.testing.assert_array_almost_equal(tensor.to_numpy(y),
1634 tensor.to_numpy(y_t[0]),
1635 decimal=5)
1636
1637 def test_constantOfShape_cpu(self):
1638 self._constantOfShape_helper(cpu_dev)

Callers 2

Calls 3

prepareMethod · 0.80
to_deviceMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected