<s> import os . path <EOL> from nose . plugins . skip import SkipTest <EOL> from nose . tools import assert_raises <EOL> import numpy <EOL> from theano import config <EOL> from theano . compat import PY3 <EOL> from theano . misc . pkl_utils import CompatUnpickler <EOL> from theano . sandbox . cuda import cuda_available <EOL> if not cuda_available : <EOL> raise SkipTest ( '<STR_LIT>' ) <EOL> else : <EOL> from theano . sandbox . cuda import CudaNdarray <EOL> def test_unpickle_flag_is_false_by_default ( ) : <EOL> assert not config . experimental . unpickle_gpu_on_cpu , ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> def test_unpickle_cudandarray_as_numpy_ndarray_flag0 ( ) : <EOL> oldflag = config . experimental . unpickle_gpu_on_cpu <EOL> config . experimental . unpickle_gpu_on_cpu = False <EOL> try : <EOL> testfile_dir = os . path . dirname ( os . path . realpath ( __file__ ) ) <EOL> fname = '<STR_LIT>' <EOL> with open ( os . path . join ( testfile_dir , fname ) , '<STR_LIT:rb>' ) as fp : <EOL> if PY3 : <EOL> u = CompatUnpickler ( fp , encoding = "<STR_LIT>" ) <EOL> else : <EOL> u = CompatUnpickler ( fp ) <EOL> if cuda_available : <EOL> mat = u . load ( ) <EOL> assert isinstance ( mat , CudaNdarray ) <EOL> assert numpy . asarray ( mat ) [ <NUM_LIT:0> ] == - <NUM_LIT> <EOL> else : <EOL> assert_raises ( ImportError , u . load ) <EOL> finally : <EOL> config . experimental . unpickle_gpu_on_cpu = oldflag <EOL> def test_unpickle_cudandarray_as_numpy_ndarray_flag1 ( ) : <EOL> oldflag = config . experimental . unpickle_gpu_on_cpu <EOL> config . experimental . unpickle_gpu_on_cpu = True <EOL> try : <EOL> testfile_dir = os . path . dirname ( os . path . realpath ( __file__ ) ) <EOL> fname = '<STR_LIT>' <EOL> with open ( os . path . join ( testfile_dir , fname ) , '<STR_LIT:rb>' ) as fp : <EOL> if PY3 : <EOL> u = CompatUnpickler ( fp , encoding = "<STR_LIT>" ) <EOL> else : <EOL> u = CompatUnpickler ( fp ) <EOL> mat = u . load ( ) <EOL> assert isinstance ( mat , numpy . ndarray ) <EOL> assert mat [ <NUM_LIT:0> ] == - <NUM_LIT> <EOL> finally : <EOL> config . experimental . unpickle_gpu_on_cpu = oldflag </s>
