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

Method split_test

test/python/test_operation.py:2978–3005  ·  view source on GitHub ↗
(self, dev)

Source from the content-addressed store, hash-verified

2976 self._test_scatter_elements(gpu_dev)
2977
2978 def split_test(self, dev):
2979 X = np.array([1., 2., 3., 4., 5., 6.]).astype(np.float32)
2980 DY1 = np.ones((2), dtype=np.float32)
2981 DY2 = np.ones((4), dtype=np.float32)
2982 y = [
2983 np.array([1., 2.]).astype(np.float32),
2984 np.array([3., 4., 5., 6.]).astype(np.float32)
2985 ]
2986
2987 x = tensor.from_numpy(X)
2988 dy1 = tensor.from_numpy(DY1)
2989 dy2 = tensor.from_numpy(DY2)
2990 x.to_device(dev)
2991 dy1.to_device(dev)
2992 dy2.to_device(dev)
2993
2994 result = autograd.split(x, 0, (2, 4))
2995 dx = result[0].creator.backward(dy1.data, dy2.data)
2996 DX = np.ones((6), dtype=np.float32)
2997
2998 for idx, _r in enumerate(result):
2999 np.testing.assert_array_almost_equal(tensor.to_numpy(_r),
3000 y[idx],
3001 decimal=5)
3002 np.testing.assert_array_almost_equal(tensor.to_numpy(
3003 tensor.from_raw_tensor(dx)),
3004 DX,
3005 decimal=5)
3006
3007 def test_split_cpu(self):
3008 self.split_test(cpu_dev)

Callers 2

test_split_cpuMethod · 0.95
test_split_gpuMethod · 0.95

Calls 2

to_deviceMethod · 0.45
backwardMethod · 0.45

Tested by

no test coverage detected