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

Method _slice_helper

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

Source from the content-addressed store, hash-verified

1777 self._unsqueeze_helper(gpu_dev)
1778
1779 def _slice_helper(self, dev):
1780 X = np.random.randn(20, 10, 5).astype(np.float32)
1781 starts, ends, axes, steps = [0, 0], [3, 10], [0, 1], [1, 1]
1782 x = tensor.from_numpy(X)
1783 x.to_device(dev)
1784 y = autograd.slice(x, starts, ends, axes, steps)
1785
1786 # frontend
1787 model = sonnx.to_onnx([x], [y])
1788 # print('The model is:\n{}'.format(model))
1789
1790 # backend
1791 sg_ir = sonnx.prepare(model, device=dev)
1792 sg_ir.is_graph = True
1793 y_t = sg_ir.run([x])
1794
1795 np.testing.assert_array_almost_equal(
1796 tensor.to_numpy(y).shape,
1797 tensor.to_numpy(y_t[0]).shape)
1798
1799 def test_slice_cpu(self):
1800 self._slice_helper(cpu_dev)

Callers 2

test_slice_cpuMethod · 0.95
test_slice_gpuMethod · 0.95

Calls 3

prepareMethod · 0.80
to_deviceMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected