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

Method _onehot_helper

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

Source from the content-addressed store, hash-verified

1933 self._cast_helper(gpu_dev)
1934
1935 def _onehot_helper(self, dev):
1936 axisValue = 1
1937 on_value = 3
1938 off_value = 1
1939 output_type = np.float32
1940 indices = np.array([[1, 9], [2, 4]], dtype=np.float32)
1941 depth = np.array([10], dtype=np.float32)
1942 values = np.array([off_value, on_value], dtype=output_type)
1943
1944 x = tensor.from_numpy(indices)
1945 x.to_device(dev)
1946 y = autograd.onehot(axisValue, x, depth, values)
1947
1948 # frontend
1949 model = sonnx.to_onnx([x], [y])
1950 # print('The model is:\n{}'.format(model))
1951
1952 # backend
1953 sg_ir = sonnx.prepare(model, device=dev)
1954 sg_ir.is_graph = True
1955 y_t = sg_ir.run([x])
1956
1957 self.check_shape(
1958 tensor.to_numpy(y).shape,
1959 tensor.to_numpy(y_t[0]).shape)
1960
1961 def test_onehot_cpu(self):
1962 self._onehot_helper(cpu_dev)

Callers 2

test_onehot_cpuMethod · 0.95
test_onehot_gpuMethod · 0.95

Calls 4

check_shapeMethod · 0.95
prepareMethod · 0.80
to_deviceMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected