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

Method gather_test

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

Source from the content-addressed store, hash-verified

3012 self.split_test(gpu_dev)
3013
3014 def gather_test(self, dev):
3015 config = [([0, 1, 3], 0), ([0, 1, 3], 1), ([[0, 1], [1, 2], [2, 3]], 1),
3016 ([0, -1, -2], 0)] # (indices, axis)
3017 for indices, _axis in config:
3018 X = np.random.randn(5, 4, 3, 2).astype(np.float32)
3019 y = np.take(X, indices, axis=_axis)
3020 DY = np.ones(y.shape, dtype=np.float32)
3021
3022 x = tensor.from_numpy(X)
3023 dy = tensor.from_numpy(DY)
3024 x.to_device(dev)
3025 dy.to_device(dev)
3026
3027 result = autograd.gather(x, _axis, indices)
3028 dx = result.creator.backward(dy.data)
3029
3030 np.testing.assert_array_almost_equal(tensor.to_numpy(result),
3031 y,
3032 decimal=5)
3033 self.check_shape(dx.shape(), tuple(X.shape))
3034
3035 def test_gather_cpu(self):
3036 self.gather_test(cpu_dev)

Callers 2

test_gather_cpuMethod · 0.95
test_gather_gpuMethod · 0.95

Calls 5

check_shapeMethod · 0.95
shapeMethod · 0.80
tupleFunction · 0.50
to_deviceMethod · 0.45
backwardMethod · 0.45

Tested by

no test coverage detected