提交 30d9450a authored 作者: Francesco's avatar Francesco

Merge pull request #4190 from taesupkim/issue_4185

flake8 misc/tests/*.py
import numpy
import theano
from theano.misc.cudamat_utils import cudamat_available
if not cudamat_available:
if not cudamat_available: # noqa
from nose.plugins.skip import SkipTest
raise SkipTest("gnumpy not installed. Skip test of theano op with pycuda code.")
raise SkipTest("gnumpy not installed. Skip test of theano op with pycuda "
"code.")
from theano.misc.cudamat_utils import cudandarray_to_cudamat, cudamat_to_cudandarray
from theano.misc.cudamat_utils import (cudandarray_to_cudamat,
cudamat_to_cudandarray)
def test(shape=(3, 4)):
"""
Make sure that the cudamat conversion is exact.
"""
Make sure that the cudamat conversion is exact.
"""
gpu = theano.sandbox.cuda.basic_ops.gpu_from_host
U = gpu(theano.tensor.fmatrix('U'))
ii = theano.function([U], gpu(U+1))
ii = theano.function([U], gpu(U + 1))
A_cpu = numpy.asarray(numpy.random.rand(*shape), dtype="float32")
A_cnd = theano.sandbox.cuda.CudaNdarray(A_cpu)
......@@ -31,5 +32,5 @@ Make sure that the cudamat conversion is exact.
v = numpy.asarray(B_cnd)
w = A_cmat.add(1).asarray()
assert abs(u-v).max() == 0
assert abs(u-w.T.reshape(u.shape)).max() == 0
assert abs(u - v).max() == 0
assert abs(u - w.T.reshape(u.shape)).max() == 0
......@@ -3,7 +3,7 @@ import numpy
import theano
from theano.misc.gnumpy_utils import gnumpy_available
if not gnumpy_available:
if not gnumpy_available: # noqa
from nose.plugins.skip import SkipTest
raise SkipTest("gnumpy not installed. Skip test related to it.")
......@@ -46,7 +46,7 @@ def test2(shape=(3, 4, 5)):
"""
gpu = theano.sandbox.cuda.basic_ops.gpu_from_host
U = gpu(theano.tensor.ftensor3('U'))
ii = theano.function([U], gpu(U + 1))
theano.function([U], gpu(U + 1))
A = numpy.random.rand(*shape).astype('float32')
A_cnd = theano.sandbox.cuda.CudaNdarray(A)
......
"""
test the tensor and sparse type. The CudaNdarray type is tested in sandbox/cuda/tests/test_tensor_op.py.test_may_share_memory_cuda
test the tensor and sparse type. The CudaNdarray type is tested in
sandbox/cuda/tests/test_tensor_op.py.test_may_share_memory_cuda
"""
import numpy
import theano
try:
......@@ -26,12 +25,12 @@ def test_may_share_memory():
tb = b.T
for a_, b_, rep in [(a, a, True), (b, b, True), (a, b, False),
(a, a[0], True), (a, a[:, 0], True), (a, a.T, True),
(a, (0,), False), (a, 1, False), (a, None, False),
(a, va, True), (b, vb, True), (va, b, False), (a, vb, False),
(a, ra, True), (b, rb, True), (ra, b, False), (a, rb, False),
(a, ta, True), (b, tb, True), (ta, b, False), (a, tb, False),
]:
(a, a[0], True), (a, a[:, 0], True), (a, a.T, True),
(a, (0,), False), (a, 1, False), (a, None, False),
(a, va, True), (b, vb, True), (va, b, False),
(a, vb, False), (a, ra, True), (b, rb, True),
(ra, b, False), (a, rb, False), (a, ta, True),
(b, tb, True), (ta, b, False), (a, tb, False)]:
assert may_share_memory(a_, b_, False) == rep
assert may_share_memory(b_, a_, False) == rep
......@@ -55,14 +54,20 @@ if scipy_imported:
def test_may_share_memory_scipy():
a = scipy.sparse.csc_matrix(scipy.sparse.eye(5, 3))
b = scipy.sparse.csc_matrix(scipy.sparse.eye(4, 3))
as_ar = lambda a: theano._asarray(a, dtype='int32')
def as_ar(a):
return theano._asarray(a, dtype='int32')
for a_, b_, rep in [(a, a, True), (b, b, True), (a, b, False),
(a, a.data, True), (a, a.indptr, True), (a, a.indices, True), (a, as_ar(a.shape), False),
(a.data, a, True), (a.indptr, a, True), (a.indices, a, True), (as_ar(a.shape), a, False),
(b, b.data, True), (b, b.indptr, True), (b, b.indices, True), (b, as_ar(b.shape), False),
(b.data, b, True), (b.indptr, b, True), (b.indices, b, True), (as_ar(b.shape), b, False),
(b.data, a, False), (b.indptr, a, False), (b.indices, a, False), (as_ar(b.shape), a, False),
]:
(a, a.data, True), (a, a.indptr, True),
(a, a.indices, True), (a, as_ar(a.shape), False),
(a.data, a, True), (a.indptr, a, True),
(a.indices, a, True), (as_ar(a.shape), a, False),
(b, b.data, True), (b, b.indptr, True),
(b, b.indices, True), (b, as_ar(b.shape), False),
(b.data, b, True), (b.indptr, b, True),
(b.indices, b, True), (as_ar(b.shape), b, False),
(b.data, a, False), (b.indptr, a, False),
(b.indices, a, False), (as_ar(b.shape), a, False)]:
assert may_share_memory(a_, b_) == rep
assert may_share_memory(b_, a_) == rep
......
......@@ -4,19 +4,18 @@ import numpy
import theano
import theano.misc.pycuda_init
if not theano.misc.pycuda_init.pycuda_available:
if not theano.misc.pycuda_init.pycuda_available: # noqa
from nose.plugins.skip import SkipTest
raise SkipTest("Pycuda not installed. Skip test of theano op"
" with pycuda code.")
import theano.sandbox.cuda as cuda_ndarray
if not cuda_ndarray.cuda_available:
if not cuda_ndarray.cuda_available: # noqa
from nose.plugins.skip import SkipTest
raise SkipTest('Optional package cuda disabled')
import theano.tensor as T
from theano.misc.pycuda_example import (PycudaElemwiseSourceModuleOp,
# PycudaElemwiseKernelOp,
PycudaElemwiseSourceModuleMakeThunkOp)
if theano.config.mode == 'FAST_COMPILE':
......
......@@ -14,12 +14,12 @@ import theano
import theano.sandbox.cuda as cuda_ndarray
import theano.misc.pycuda_init
if not theano.misc.pycuda_init.pycuda_available:
if not theano.misc.pycuda_init.pycuda_available: # noqa
from nose.plugins.skip import SkipTest
raise SkipTest("Pycuda not installed."
" We skip tests of Theano Ops with pycuda code.")
if cuda_ndarray.cuda_available == False:
if cuda_ndarray.cuda_available is False: # noqa
from nose.plugins.skip import SkipTest
raise SkipTest('Optional theano package cuda disabled')
......
......@@ -3,11 +3,12 @@ import numpy
import theano.sandbox.cuda as cuda
import theano.misc.pycuda_init
if not theano.misc.pycuda_init.pycuda_available:
if not theano.misc.pycuda_init.pycuda_available: # noqa
from nose.plugins.skip import SkipTest
raise SkipTest("Pycuda not installed. Skip test of theano op with pycuda code.")
raise SkipTest("Pycuda not installed. Skip test of theano op with pycuda "
"code.")
if cuda.cuda_available == False:
if cuda.cuda_available is False: # noqa
from nose.plugins.skip import SkipTest
raise SkipTest('Optional theano package cuda disabled')
......
......@@ -149,12 +149,6 @@ whitelist_flake8 = [
"scan_module/__init__.py",
"scan_module/tests/test_scan.py",
"scan_module/tests/test_scan_opt.py",
"misc/tests/test_may_share_memory.py",
"misc/tests/test_pycuda_theano_simple.py",
"misc/tests/test_gnumpy_utils.py",
"misc/tests/test_pycuda_utils.py",
"misc/tests/test_cudamat_utils.py",
"misc/tests/test_pycuda_example.py",
"misc/hooks/reindent.py",
"misc/hooks/check_whitespace.py",
"sparse/__init__.py",
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论