提交 5534d3ca authored 作者: Frederic's avatar Frederic

pep8

上级 eb49be66
...@@ -7,6 +7,9 @@ import theano.tensor as T ...@@ -7,6 +7,9 @@ import theano.tensor as T
import theano.tests.unittest_tools as utt import theano.tests.unittest_tools as utt
from theano.sandbox import gpuarray from theano.sandbox import gpuarray
from theano.sandbox.gpuarray.nnet import (
GpuCrossentropySoftmaxArgmax1HotWithBias,
GpuCrossentropySoftmax1HotWithBiasDx)
if theano.sandbox.gpuarray.pygpu is None: if theano.sandbox.gpuarray.pygpu is None:
raise SkipTest("pygpu not installed") raise SkipTest("pygpu not installed")
...@@ -25,8 +28,9 @@ if cuda_ndarray.cuda_available and not theano.sandbox.gpuarray.pygpu_activated: ...@@ -25,8 +28,9 @@ if cuda_ndarray.cuda_available and not theano.sandbox.gpuarray.pygpu_activated:
if not gpuarray.pygpu_activated: if not gpuarray.pygpu_activated:
raise SkipTest("pygpu disabled") raise SkipTest("pygpu disabled")
from theano.sandbox.gpuarray.nnet import (GpuCrossentropySoftmaxArgmax1HotWithBias, from theano.sandbox.gpuarray.nnet import (
GpuCrossentropySoftmax1HotWithBiasDx) GpuCrossentropySoftmaxArgmax1HotWithBias,
GpuCrossentropySoftmax1HotWithBiasDx)
if theano.config.mode == 'FAST_COMPILE': if theano.config.mode == 'FAST_COMPILE':
mode_with_gpu = theano.compile.mode.get_mode('FAST_RUN').including('gpuarray').excluding('gpu') mode_with_gpu = theano.compile.mode.get_mode('FAST_RUN').including('gpuarray').excluding('gpu')
...@@ -86,7 +90,7 @@ def test_GpuCrossentropySoftmaxArgmax1HotWithBias(): ...@@ -86,7 +90,7 @@ def test_GpuCrossentropySoftmaxArgmax1HotWithBias():
mode=mode_without_gpu) mode=mode_without_gpu)
classify_gpu = theano.function(inputs=[y, b, dot_result], classify_gpu = theano.function(inputs=[y, b, dot_result],
outputs=[loss, y_pred, dW], outputs=[loss, y_pred, dW],
mode=mode_with_gpu) mode=mode_with_gpu)
#theano.printing.debugprint(classify) #theano.printing.debugprint(classify)
#theano.printing.debugprint(classify_gpu) #theano.printing.debugprint(classify_gpu)
...@@ -94,7 +98,7 @@ def test_GpuCrossentropySoftmaxArgmax1HotWithBias(): ...@@ -94,7 +98,7 @@ def test_GpuCrossentropySoftmaxArgmax1HotWithBias():
T.nnet.CrossentropySoftmaxArgmax1HotWithBias) T.nnet.CrossentropySoftmaxArgmax1HotWithBias)
for node in classify.maker.fgraph.toposort()]) for node in classify.maker.fgraph.toposort()])
assert any([isinstance(node.op, assert any([isinstance(node.op,
gpuarray.nnet.GpuCrossentropySoftmaxArgmax1HotWithBias) GpuCrossentropySoftmaxArgmax1HotWithBias)
for node in classify_gpu.maker.fgraph.toposort()]) for node in classify_gpu.maker.fgraph.toposort()])
out = classify(yy, b_values, dot_value) out = classify(yy, b_values, dot_value)
...@@ -149,7 +153,7 @@ def test_GpuCrossentropySoftmax1HotWithBiasDx(): ...@@ -149,7 +153,7 @@ def test_GpuCrossentropySoftmax1HotWithBiasDx():
assert any([isinstance(node.op, T.nnet.CrossentropySoftmax1HotWithBiasDx) assert any([isinstance(node.op, T.nnet.CrossentropySoftmax1HotWithBiasDx)
for node in cpu_f.maker.fgraph.toposort()]) for node in cpu_f.maker.fgraph.toposort()])
assert any([isinstance(node.op, assert any([isinstance(node.op,
gpuarray.nnet.GpuCrossentropySoftmax1HotWithBiasDx) GpuCrossentropySoftmax1HotWithBiasDx)
for node in gpu_f.maker.fgraph.toposort()]) for node in gpu_f.maker.fgraph.toposort()])
cpu_out = cpu_f(softmax_output_value) cpu_out = cpu_f(softmax_output_value)
...@@ -163,7 +167,7 @@ def test_GpuCrossentropySoftmax1HotWithBiasDx(): ...@@ -163,7 +167,7 @@ def test_GpuCrossentropySoftmax1HotWithBiasDx():
max_i = scaled_err.argmax() max_i = scaled_err.argmax()
print 'max err index:', max_i, max_i / batch_size, print 'max err index:', max_i, max_i / batch_size,
print max_i % batch_size, max_i / n_out, max_i & n_out print max_i % batch_size, max_i / n_out, max_i & n_out
print 'At that index:' print 'At that index:'
print 'err:', scaled_err.flatten()[max_i] print 'err:', scaled_err.flatten()[max_i]
print 'absolute error:', abs_err.flatten()[max_i] print 'absolute error:', abs_err.flatten()[max_i]
...@@ -175,4 +179,4 @@ def test_GpuCrossentropySoftmax1HotWithBiasDx(): ...@@ -175,4 +179,4 @@ def test_GpuCrossentropySoftmax1HotWithBiasDx():
print 'y_idx_value:', y_idx_value[max_i / n_out] print 'y_idx_value:', y_idx_value[max_i / n_out]
assert False, "numpy.allclose(cpu_out, gpu_out, rtol=%s, atol=%s)" % ( assert False, "numpy.allclose(cpu_out, gpu_out, rtol=%s, atol=%s)" % (
rtol, atol) rtol, atol)
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论