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

Flake8 for tests/test_basic_ops.py

上级 b19b92e0
import unittest import unittest
from theano.compat import izip from theano.compat import izip
from copy import copy, deepcopy
from six import iteritems from six import iteritems
...@@ -13,16 +12,31 @@ from theano.tensor.basic import alloc ...@@ -13,16 +12,31 @@ from theano.tensor.basic import alloc
# Don't import test classes otherwise they get tested as part of the file # Don't import test classes otherwise they get tested as part of the file
from theano.tensor.tests import test_basic from theano.tensor.tests import test_basic
from theano.tensor.tests.test_basic import rand, safe_make_node from theano.tensor.tests.test_basic import rand, safe_make_node
from theano.tests import unittest_tools as utt
from theano.tests.unittest_tools import SkipTest from theano.tests.unittest_tools import SkipTest
import theano.sandbox.gpuarray import theano.sandbox.gpuarray
from ..type import (GpuArrayType,
gpuarray_shared_constructor)
from ..basic_ops import (
host_from_gpu, gpu_from_host, HostFromGpu, GpuFromHost, GpuReshape,
gpu_alloc, GpuAlloc, GpuAllocEmpty, GpuContiguous,
gpu_join, GpuJoin, GpuSplit, GpuEye, gpu_contiguous)
from ..subtensor import GpuSubtensor
import theano.sandbox.cuda as cuda_ndarray
try:
from pygpu import gpuarray
except:
pass
if theano.sandbox.gpuarray.pygpu is None: if theano.sandbox.gpuarray.pygpu is None:
raise SkipTest("pygpu not installed") raise SkipTest("pygpu not installed")
# If you are writing a new test file, don't copy this code, but rather # If you are writing a new test file, don't copy this code, but rather
# import stuff from this file (like mode_with_gpu) to reuse it. # import stuff from this file (like mode_with_gpu) to reuse it.
import theano.sandbox.cuda as cuda_ndarray
if cuda_ndarray.cuda_available and not theano.sandbox.gpuarray.pygpu_activated: if cuda_ndarray.cuda_available and not theano.sandbox.gpuarray.pygpu_activated:
if not cuda_ndarray.use.device_number: if not cuda_ndarray.use.device_number:
# We should not enable all the use like the flag device=gpu, # We should not enable all the use like the flag device=gpu,
...@@ -36,24 +50,9 @@ if cuda_ndarray.cuda_available and not theano.sandbox.gpuarray.pygpu_activated: ...@@ -36,24 +50,9 @@ if cuda_ndarray.cuda_available and not theano.sandbox.gpuarray.pygpu_activated:
if not theano.sandbox.gpuarray.pygpu_activated: if not theano.sandbox.gpuarray.pygpu_activated:
raise SkipTest("pygpu disabled") raise SkipTest("pygpu disabled")
from ..type import (GpuArrayType,
gpuarray_shared_constructor)
from ..basic_ops import (
host_from_gpu, gpu_from_host,
gpu_alloc, GpuAlloc,
GpuAllocEmpty,
HostFromGpu,
GpuContiguous,
GpuFromHost, GpuReshape,
gpu_join, GpuJoin, GpuSplit, GpuEye, gpu_contiguous)
from ..subtensor import GpuSubtensor
from theano.tests import unittest_tools as utt
utt.seed_rng() utt.seed_rng()
rng = numpy.random.RandomState(seed=utt.fetch_seed()) rng = numpy.random.RandomState(seed=utt.fetch_seed())
from pygpu import gpuarray
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')
mode_without_gpu = theano.compile.mode.get_mode('FAST_RUN').excluding('gpuarray') mode_without_gpu = theano.compile.mode.get_mode('FAST_RUN').excluding('gpuarray')
...@@ -62,22 +61,6 @@ else: ...@@ -62,22 +61,6 @@ else:
mode_without_gpu = theano.compile.mode.get_default_mode().excluding('gpuarray') mode_without_gpu = theano.compile.mode.get_default_mode().excluding('gpuarray')
def may_fail(msg, EClass):
"""Mark a test that requires very specific conditions to work to
mask a specific exception class."""
def test_decorator(f):
def wrapper():
try:
f()
except Exception as e:
if isinstance(e, EClass):
raise SkipTest(msg, e)
raise
wrapper.__name__ = f.__name__
return wrapper
return test_decorator
def inplace_func(inputs, outputs, mode=None, allow_input_downcast=False, def inplace_func(inputs, outputs, mode=None, allow_input_downcast=False,
on_unused_input='raise', name=None): on_unused_input='raise', name=None):
if mode is None: if mode is None:
...@@ -182,9 +165,9 @@ def makeTester(name, op, gpu_op, cases, checks=None, mode_gpu=mode_with_gpu, ...@@ -182,9 +165,9 @@ def makeTester(name, op, gpu_op, cases, checks=None, mode_gpu=mode_with_gpu,
else: else:
err_msg = ("Test %s::%s: exception raised during test " err_msg = ("Test %s::%s: exception raised during test "
"call was not the same as the reference " "call was not the same as the reference "
"call (got: %s, expected %s)") % \ "call (got: %s, expected %s)" %
(self.gpu_op, testname, type(exc), (self.gpu_op, testname, type(exc),
type(ref_e)) type(ref_e)))
exc.args += (err_msg,) exc.args += (err_msg,)
raise raise
...@@ -196,9 +179,9 @@ def makeTester(name, op, gpu_op, cases, checks=None, mode_gpu=mode_with_gpu, ...@@ -196,9 +179,9 @@ def makeTester(name, op, gpu_op, cases, checks=None, mode_gpu=mode_with_gpu,
expected): expected):
self.fail(("Test %s::%s: Output %s gave the wrong " self.fail(("Test %s::%s: Output %s gave the wrong "
"value. With inputs %s, expected %s " "value. With inputs %s, expected %s "
"(dtype %s), got %s (dtype %s).") % ( "(dtype %s), got %s (dtype %s)." %
self.op, testname, i, inputs, expected, (self.op, testname, i, inputs, expected,
expected.dtype, variable, variable.dtype)) expected.dtype, variable, variable.dtype)))
for description, check in iteritems(self.checks): for description, check in iteritems(self.checks):
if not check(inputs, variables): if not check(inputs, variables):
...@@ -260,8 +243,8 @@ GpuAllocTester = makeTester( ...@@ -260,8 +243,8 @@ GpuAllocTester = makeTester(
gpu_op=gpu_alloc, gpu_op=gpu_alloc,
cases=dict( cases=dict(
correct01=(rand(), numpy.int32(7)), correct01=(rand(), numpy.int32(7)),
# just gives a DeepCopyOp with possibly wrong results on the CPU # just gives a DeepCopyOp with possibly wrong results on the CPU
# correct01_bcast=(rand(1), numpy.int32(7)), # correct01_bcast=(rand(1), numpy.int32(7)),
correct02=(rand(), numpy.int32(4), numpy.int32(7)), correct02=(rand(), numpy.int32(4), numpy.int32(7)),
correct12=(rand(7), numpy.int32(4), numpy.int32(7)), correct12=(rand(7), numpy.int32(4), numpy.int32(7)),
correct13=(rand(7), numpy.int32(2), numpy.int32(4), correct13=(rand(7), numpy.int32(2), numpy.int32(4),
...@@ -455,8 +438,6 @@ def test_hostfromgpu_shape_i(): ...@@ -455,8 +438,6 @@ def test_hostfromgpu_shape_i():
cv = gpuarray.asarray(numpy.random.rand(5, 4), cv = gpuarray.asarray(numpy.random.rand(5, 4),
dtype='float32') dtype='float32')
gpu_from_host = theano.sandbox.gpuarray.basic_ops.gpu_from_host
host_from_gpu = theano.sandbox.gpuarray.basic_ops.host_from_gpu
f = theano.function([a], gpu_from_host(a), mode=m) f = theano.function([a], gpu_from_host(a), mode=m)
assert gpu_from_host in [x.op assert gpu_from_host in [x.op
for x in f.maker.fgraph.toposort()] for x in f.maker.fgraph.toposort()]
......
...@@ -167,7 +167,6 @@ whitelist_flake8 = [ ...@@ -167,7 +167,6 @@ whitelist_flake8 = [
"sandbox/gpuarray/tests/test_blas.py", "sandbox/gpuarray/tests/test_blas.py",
"sandbox/gpuarray/tests/test_elemwise.py", "sandbox/gpuarray/tests/test_elemwise.py",
"sandbox/gpuarray/tests/test_nnet.py", "sandbox/gpuarray/tests/test_nnet.py",
"sandbox/gpuarray/tests/test_basic_ops.py",
"scan_module/scan_utils.py", "scan_module/scan_utils.py",
"scan_module/scan_views.py", "scan_module/scan_views.py",
"scan_module/scan.py", "scan_module/scan.py",
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论