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

Method reduceSum_test

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

Source from the content-addressed store, hash-verified

2744 self.dropout_test(gpu_dev)
2745
2746 def reduceSum_test(self, dev):
2747 shape = [3, 2, 2]
2748 cases = [(None, 1), ([1], 0), ([1], 1), ([-2], 1), ([1, 2], 1)]
2749 for axes, keepdims in cases:
2750 X = np.random.uniform(-10, 10, shape).astype(np.float32)
2751 _axes = tuple(axes) if axes is not None else None
2752 y = np.sum(X, axis=_axes, keepdims=keepdims == 1)
2753 dy = np.random.randn(*y.shape).astype(np.float32)
2754
2755 x = tensor.from_numpy(X)
2756 dy = tensor.from_numpy(dy)
2757 x.to_device(dev)
2758 dy.to_device(dev)
2759
2760 result = autograd.reduce_sum(x, axes, keepdims)
2761 dx = result.creator.backward(dy.data)
2762
2763 np.testing.assert_array_almost_equal(tensor.to_numpy(result),
2764 y,
2765 decimal=5)
2766 self.check_shape(dx.shape(), tuple(shape))
2767
2768 def test_reduceSum_cpu(self):
2769 self.reduceSum_test(cpu_dev)

Callers 2

test_reduceSum_cpuMethod · 0.95
test_reduceSum_gpuMethod · 0.95

Calls 6

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

Tested by

no test coverage detected