提交 50572e99 authored 作者: Frederic Bastien's avatar Frederic Bastien

Move to a separate test file gpuarray tests that must always run, even when pygpu isn't available

上级 768fb73d
"""Some pickle test when pygpu isn't there. The test when pygpu is
available are in test_type.py.
This is needed as we skip all the test file when pygpu isn't there in
regular test file.
"""
import os
from nose.plugins.skip import SkipTest
from nose.tools import assert_raises
import numpy
import theano.sandbox.gpuarray
from theano.compat import PY3
from theano import config
from theano.misc.pkl_utils import CompatUnpickler
if not theano.sandbox.gpuarray.pygpu_activated:
import theano.sandbox.cuda as cuda_ndarray
if cuda_ndarray.cuda_available:
cuda_ndarray.use('gpu', default_to_move_computation_to_gpu=False,
move_shared_float32_to_gpu=False,
enable_cuda=False)
theano.sandbox.gpuarray.init_dev('cuda')
from .. import pygpu_activated # noqa
def test_unpickle_gpuarray_as_numpy_ndarray_flag1():
"""Only test when pygpu isn't
available. test_unpickle_gpuarray_as_numpy_ndarray_flag0 in
test_type.py test it when pygpu is there.
"""
if pygpu_activated:
raise SkipTest("pygpu disabled")
oldflag = config.experimental.unpickle_gpu_on_cpu
config.experimental.unpickle_gpu_on_cpu = False
try:
testfile_dir = os.path.dirname(os.path.realpath(__file__))
fname = 'GpuArray.pkl'
with open(os.path.join(testfile_dir, fname), 'rb') as fp:
if PY3:
u = CompatUnpickler(fp, encoding="latin1")
else:
u = CompatUnpickler(fp)
assert_raises(ImportError, u.load)
finally:
config.experimental.unpickle_gpu_on_cpu = oldflag
def test_unpickle_gpuarray_as_numpy_ndarray_flag2():
oldflag = config.experimental.unpickle_gpu_on_cpu
config.experimental.unpickle_gpu_on_cpu = True
try:
testfile_dir = os.path.dirname(os.path.realpath(__file__))
fname = 'GpuArray.pkl'
with open(os.path.join(testfile_dir, fname), 'rb') as fp:
if PY3:
u = CompatUnpickler(fp, encoding="latin1")
else:
u = CompatUnpickler(fp)
mat = u.load()
assert isinstance(mat, numpy.ndarray)
assert mat[0] == -42.0
finally:
config.experimental.unpickle_gpu_on_cpu = oldflag
import os
from nose.tools import assert_raises
import numpy
import theano
......@@ -11,12 +10,9 @@ from theano.misc.pkl_utils import CompatUnpickler
from .config import test_ctx_name
from .test_basic_ops import rand_gpuarray
from ..type import GpuArrayType
from .. import pygpu_activated
if pygpu_activated:
import pygpu
import pygpu
def test_deep_copy():
......@@ -56,32 +52,10 @@ def test_filter_float():
def test_unpickle_gpuarray_as_numpy_ndarray_flag0():
""" Test when pygpu isn't there for unpickle are in test_pickle.py"""
oldflag = config.experimental.unpickle_gpu_on_cpu
config.experimental.unpickle_gpu_on_cpu = False
try:
testfile_dir = os.path.dirname(os.path.realpath(__file__))
fname = 'GpuArray.pkl'
with open(os.path.join(testfile_dir, fname), 'rb') as fp:
if PY3:
u = CompatUnpickler(fp, encoding="latin1")
else:
u = CompatUnpickler(fp)
if pygpu_activated:
mat = u.load()
assert isinstance(mat, pygpu.gpuarray.GpuArray)
assert numpy.asarray(mat)[0] == -42.0
else:
assert_raises(ImportError, u.load)
finally:
config.experimental.unpickle_gpu_on_cpu = oldflag
def test_unpickle_gpuarray_as_numpy_ndarray_flag1():
oldflag = config.experimental.unpickle_gpu_on_cpu
config.experimental.unpickle_gpu_on_cpu = True
try:
testfile_dir = os.path.dirname(os.path.realpath(__file__))
fname = 'GpuArray.pkl'
......@@ -92,9 +66,7 @@ def test_unpickle_gpuarray_as_numpy_ndarray_flag1():
else:
u = CompatUnpickler(fp)
mat = u.load()
assert isinstance(mat, numpy.ndarray)
assert mat[0] == -42.0
assert isinstance(mat, pygpu.gpuarray.GpuArray)
assert numpy.asarray(mat)[0] == -42.0
finally:
config.experimental.unpickle_gpu_on_cpu = oldflag
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论