|
|
|
|
@ -6,12 +6,13 @@ import numpy
|
|
|
|
|
|
|
|
|
|
class GaussianRandomTest(unittest.TestCase):
|
|
|
|
|
def test_cpu(self):
|
|
|
|
|
self.test_gaussian_random(place=core.CPUPlace())
|
|
|
|
|
self.gaussian_random_test(place=core.CPUPlace())
|
|
|
|
|
|
|
|
|
|
def test_gpu(self):
|
|
|
|
|
self.test_gaussian_random(place=core.GPUPlace(0))
|
|
|
|
|
if core.is_compile_gpu():
|
|
|
|
|
self.gaussian_random_test(place=core.GPUPlace(0))
|
|
|
|
|
|
|
|
|
|
def test_gaussian_random(self, place):
|
|
|
|
|
def gaussian_random_test(self, place):
|
|
|
|
|
scope = core.Scope()
|
|
|
|
|
scope.new_var("Out").get_tensor()
|
|
|
|
|
|
|
|
|
|
@ -27,8 +28,8 @@ class GaussianRandomTest(unittest.TestCase):
|
|
|
|
|
context = core.DeviceContext.create(place)
|
|
|
|
|
op.run(scope, context)
|
|
|
|
|
tensor = numpy.array(scope.find_var("Out").get_tensor())
|
|
|
|
|
self.assertAlmostEqual(numpy.mean(tensor), .0, places=3)
|
|
|
|
|
self.assertAlmostEqual(numpy.std(tensor), 1., places=3)
|
|
|
|
|
self.assertAlmostEqual(numpy.mean(tensor), .0, delta=0.1)
|
|
|
|
|
self.assertAlmostEqual(numpy.std(tensor), 1., delta=0.1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
|