提交 1a4a1c96 authored 作者: Arnaud Bergeron's avatar Arnaud Bergeron

Make test_binomial yield for sub-tests to ease identifying the very long test.

上级 73072ca5
...@@ -613,18 +613,15 @@ def test_binomial(): ...@@ -613,18 +613,15 @@ def test_binomial():
# test empty size (scalar) # test empty size (scalar)
((), (), [], []), ((), (), [], []),
]: ]:
yield (t_binomial, mean, size, const_size, var_input, input,
steps, rtol)
# print ''
# print 'ON CPU with size=(%s) and mean(%d):' % (str(size), mean) def t_binomial(mean, size, const_size, var_input, input, steps, rtol):
R = MRG_RandomStreams(234, use_cuda=False) R = MRG_RandomStreams(234, use_cuda=False)
# Note: we specify `nstreams` to avoid a warning. u = R.binomial(size=size, p=mean)
u = R.binomial(size=size, p=mean,
nstreams=rng_mrg.guess_n_streams(size, warn=False))
f = theano.function(var_input, u, mode=mode) f = theano.function(var_input, u, mode=mode)
# theano.printing.debugprint(f)
out = f(*input) out = f(*input)
# print 'random?[:10]\n', out[0, 0:10]
# print 'random?[-1,-10:]\n', out[-1, -10:]
# Increase the number of steps if sizes implies only a few samples # Increase the number of steps if sizes implies only a few samples
if numpy.prod(const_size) < 10: if numpy.prod(const_size) < 10:
...@@ -636,30 +633,21 @@ def test_binomial(): ...@@ -636,30 +633,21 @@ def test_binomial():
target_avg=mean, mean_rtol=rtol) target_avg=mean, mean_rtol=rtol)
if mode != 'FAST_COMPILE' and cuda_available: if mode != 'FAST_COMPILE' and cuda_available:
# print ''
# print 'ON GPU with size=(%s) and mean(%d):' % (str(size), mean)
R = MRG_RandomStreams(234, use_cuda=True) R = MRG_RandomStreams(234, use_cuda=True)
u = R.binomial(size=size, p=mean, dtype='float32', u = R.binomial(size=size, p=mean, dtype='float32')
nstreams=rng_mrg.guess_n_streams(size,
warn=False))
# well, it's really that this test w GPU doesn't make sense otw # well, it's really that this test w GPU doesn't make sense otw
assert u.dtype == 'float32' assert u.dtype == 'float32'
f = theano.function(var_input, theano.Out( f = theano.function(var_input, theano.Out(
theano.sandbox.cuda.basic_ops.gpu_from_host(u), theano.sandbox.cuda.basic_ops.gpu_from_host(u),
borrow=True), mode=mode_with_gpu) borrow=True), mode=mode_with_gpu)
# theano.printing.debugprint(f)
gpu_out = numpy.asarray(f(*input)) gpu_out = numpy.asarray(f(*input))
# print 'random?[:10]\n', gpu_out[0, 0:10]
# print 'random?[-1,-10:]\n', gpu_out[-1, -10:]
basictest(f, steps_, const_size, prefix='mrg gpu', basictest(f, steps_, const_size, prefix='mrg gpu',
inputs=input, allow_01=True, inputs=input, allow_01=True,
target_avg=mean, mean_rtol=rtol) target_avg=mean, mean_rtol=rtol)
numpy.testing.assert_array_almost_equal(out, gpu_out, numpy.testing.assert_array_almost_equal(out, gpu_out,
decimal=6) decimal=6)
# print ''
# print 'ON CPU w NUMPY with size=(%s) and mean(%d):' % (str(size),
# mean)
RR = theano.tensor.shared_randomstreams.RandomStreams(234) RR = theano.tensor.shared_randomstreams.RandomStreams(234)
uu = RR.binomial(size=size, p=mean) uu = RR.binomial(size=size, p=mean)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论