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

Method reduceMean_test

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

Source from the content-addressed store, hash-verified

2773 self.reduceSum_test(gpu_dev)
2774
2775 def reduceMean_test(self, dev):
2776 shape = [3, 2, 2]
2777 cases = [(None, 1), ([1], 0), ([1], 1), ([-2], 1), ([1, 2], 1)]
2778 for axes, keepdims in cases:
2779 X = np.random.uniform(-10, 10, shape).astype(np.float32)
2780 _axes = tuple(axes) if axes is not None else None
2781 y = np.mean(X, axis=_axes, keepdims=keepdims == 1)
2782 dy = np.random.randn(*y.shape).astype(np.float32)
2783
2784 x = tensor.from_numpy(X)
2785 dy = tensor.from_numpy(dy)
2786 x.to_device(dev)
2787 dy.to_device(dev)
2788
2789 result = autograd.reduce_mean(x, axes, keepdims)
2790 dx = result.creator.backward(dy.data)
2791
2792 np.testing.assert_array_almost_equal(tensor.to_numpy(result),
2793 y,
2794 decimal=5)
2795 self.check_shape(dx.shape(), tuple(shape))
2796
2797 def test_reduceMean_cpu(self):
2798 self.reduceMean_test(cpu_dev)

Callers 2

test_reduceMean_cpuMethod · 0.95
test_reduceMean_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