提交 58f01d1b authored 作者: nouiz's avatar nouiz

Merge pull request #263 from delallea/win_py24

Some test fixes
...@@ -283,10 +283,11 @@ class TestComputeTestValue(unittest.TestCase): ...@@ -283,10 +283,11 @@ class TestComputeTestValue(unittest.TestCase):
n_steps=k) n_steps=k)
assert False assert False
except ValueError, e: except ValueError, e:
# The first message is for numpy before 1.6 # The first message is for numpy before 1.6.
# The second is a new message in numpy 1.6 # The second is a new message in numpy 1.6.
assert (e.message.startswith("shape mismatch") or assert (str(e).startswith("shape mismatch") or
e.message.startswith("operands could not be broadcast together with shapes")) str(e).startswith("operands could not be broadcast "
"together with shapes"))
finally: finally:
theano.config.compute_test_value = orig_compute_test_value theano.config.compute_test_value = orig_compute_test_value
......
...@@ -514,7 +514,7 @@ complexs128 = _multi(complex128) ...@@ -514,7 +514,7 @@ complexs128 = _multi(complex128)
# Using a class instead of a function makes it possible to deep-copy it in # Using a class instead of a function makes it possible to deep-copy it in
# Python 2.4. # Python 2.4.
# Note that currently only upcast_out uses this mechanism, because it is # Note that currently only a few functions use this mechanism, because it is
# enough to make the test-suite pass with Python 2.4. However, it may prove # enough to make the test-suite pass with Python 2.4. However, it may prove
# necessary to use this same mechanism in other places as well in the future. # necessary to use this same mechanism in other places as well in the future.
class upcast_out(object): class upcast_out(object):
...@@ -522,16 +522,30 @@ class upcast_out(object): ...@@ -522,16 +522,30 @@ class upcast_out(object):
return Scalar(dtype=Scalar.upcast(*types)), return Scalar(dtype=Scalar.upcast(*types)),
class upgrade_to_float(object):
def __new__(self, *types):
"""
Upgrade any int types to float32 or float64 to avoid losing precision.
"""
conv = {int8: float32,
int16: float32,
int32: float64,
int64: float64}
return Scalar(Scalar.upcast(*[conv.get(type, type)
for type in types])),
class same_out(object):
def __new__(self, type):
return type,
def upcast_out_no_complex(*types): def upcast_out_no_complex(*types):
if any([type in complex_types for type in types]): if any([type in complex_types for type in types]):
raise TypeError('complex type are not supported') raise TypeError('complex type are not supported')
return Scalar(dtype=Scalar.upcast(*types)), return Scalar(dtype=Scalar.upcast(*types)),
def same_out(type):
return type,
def same_out_float_only(type): def same_out_float_only(type):
if type not in float_types: if type not in float_types:
raise TypeError('only float type are supported') raise TypeError('only float type are supported')
...@@ -586,17 +600,6 @@ def float_out(*types): ...@@ -586,17 +600,6 @@ def float_out(*types):
return float64, return float64,
def upgrade_to_float(*types):
"""
Upgrade any int types to float32 or float64 to avoid losing any precision.
"""
conv = {int8: float32,
int16: float32,
int32: float64,
int64: float64}
return Scalar(Scalar.upcast(*[conv.get(type, type) for type in types])),
def upgrade_to_float_no_complex(*types): def upgrade_to_float_no_complex(*types):
""" """
don't accept complex, otherwise call upgrade_to_float(). don't accept complex, otherwise call upgrade_to_float().
......
...@@ -12,18 +12,20 @@ __authors__ = ("Razvan Pascanu " ...@@ -12,18 +12,20 @@ __authors__ = ("Razvan Pascanu "
__copyright__ = "(c) 2010, Universite de Montreal" __copyright__ = "(c) 2010, Universite de Montreal"
__contact__ = "Razvan Pascanu <r.pascanu@gmail>" __contact__ = "Razvan Pascanu <r.pascanu@gmail>"
import copy import copy
import logging import logging
import numpy import numpy
import theano
from theano.compile.pfunc import rebuild_collect_shared from theano.compile.pfunc import rebuild_collect_shared
from theano import gof from theano import gof
from theano import tensor, scalar from theano import tensor, scalar
from theano.gof.python25 import all
from theano.tensor.basic import get_constant_value from theano.tensor.basic import get_constant_value
import theano
################ Utility Functions and Classes ####################### ################ Utility Functions and Classes #######################
# Logging function for sending warning or info # Logging function for sending warning or info
......
...@@ -10,8 +10,9 @@ from numpy.testing import dec ...@@ -10,8 +10,9 @@ from numpy.testing import dec
import theano import theano
import theano.sandbox.rng_mrg import theano.sandbox.rng_mrg
from theano import tensor from theano import tensor
from theano.tests import unittest_tools as utt
from theano.compile.pfunc import rebuild_collect_shared from theano.compile.pfunc import rebuild_collect_shared
from theano.gof.python25 import any
from theano.tests import unittest_tools as utt
from numpy.testing.noseclasses import KnownFailureTest from numpy.testing.noseclasses import KnownFailureTest
...@@ -215,8 +216,16 @@ class T_Scan(unittest.TestCase): ...@@ -215,8 +216,16 @@ class T_Scan(unittest.TestCase):
tmpdir = mkdtemp() tmpdir = mkdtemp()
os.chdir(tmpdir) os.chdir(tmpdir)
cPickle.dump(_my_f, open('tmp_scan_test_pickle.pkl','wb'),-1) f_out = open('tmp_scan_test_pickle.pkl', 'wb')
my_f = cPickle.load(open('tmp_scan_test_pickle.pkl')) try:
cPickle.dump(_my_f, f_out, protocol=-1)
finally:
f_out.close()
f_in = open('tmp_scan_test_pickle.pkl', 'rb')
try:
my_f = cPickle.load(f_in)
finally:
f_in.close()
finally: finally:
# Get back to the orinal dir, and delete temporary one. # Get back to the orinal dir, and delete temporary one.
os.chdir(origdir) os.chdir(origdir)
......
...@@ -2929,10 +2929,13 @@ def transpose(x, **kwargs): ...@@ -2929,10 +2929,13 @@ def transpose(x, **kwargs):
class AdvancedIndexingError(TypeError): class AdvancedIndexingError(TypeError):
"""A class raised as an exception when Subtensor """
is asked to perform advanced indexing """ Raised when Subtensor is asked to perform advanced indexing.
"""
def __init__(self, *args): def __init__(self, *args):
super(AdvancedIndexingError, self).__init__(*args) TypeError.__init__( self, *args)
class Subtensor(Op): class Subtensor(Op):
"""Return a subtensor view """Return a subtensor view
......
...@@ -50,6 +50,10 @@ def test_pydotprint_cond_highlight(): ...@@ -50,6 +50,10 @@ def test_pydotprint_cond_highlight():
def test_pydotprint_profile(): def test_pydotprint_profile():
"""Just check that pydotprint does not crash with ProfileMode.""" """Just check that pydotprint does not crash with ProfileMode."""
# Skip test if pydot is not available.
if not theano.printing.pydot_imported:
raise SkipTest('pydot not available')
A = tensor.matrix() A = tensor.matrix()
f = theano.function([A], A + 1, mode='ProfileMode') f = theano.function([A], A + 1, mode='ProfileMode')
theano.printing.pydotprint(f, print_output_file=False) theano.printing.pydotprint(f, print_output_file=False)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论