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

Method _cast_helper

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

Source from the content-addressed store, hash-verified

1907 self._nonzero_helper(gpu_dev)
1908
1909 def _cast_helper(self, dev):
1910 X = np.array([[1, 0], [1, 1]]).astype(np.float32)
1911 x = tensor.from_numpy(X)
1912 x.to_device(dev)
1913 y = autograd.cast(x, tensor.int32)
1914
1915 # frontend
1916 model = sonnx.to_onnx([x], [y])
1917 # print('The model is:\n{}'.format(model))
1918
1919 # backend
1920 sg_ir = sonnx.prepare(model, device=dev)
1921 sg_ir.is_graph = True
1922 y_t = sg_ir.run([x])
1923
1924 np.testing.assert_array_almost_equal(
1925 tensor.to_numpy(y).shape,
1926 tensor.to_numpy(y_t[0]).shape)
1927
1928 def test_cast_cpu(self):
1929 self._cast_helper(cpu_dev)

Callers 2

test_cast_cpuMethod · 0.95
test_cast_gpuMethod · 0.95

Calls 4

prepareMethod · 0.80
to_deviceMethod · 0.45
castMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected