提交 c41e0a4a authored 作者: Frederic Bastien's avatar Frederic Bastien

backport to python2.4

上级 cf7f9f7e
......@@ -4,8 +4,8 @@ __docformat__ = "restructuredtext en"
import sys
import numpy
from ...gof import Container
from ...tensor import raw_random
from theano.gof import Container
from theano.tensor import raw_random
from sharedvalue import SharedVariable, shared_constructor, shared
......@@ -64,7 +64,9 @@ class RandomStreams(object):
:rtype: None
"""
seed = self.default_instance_seed if seed is None else seed
if seed is None:
seed = self.default_instance_seed
seedgen = numpy.random.RandomState(seed)
for old_r, new_r in self.random_state_variables:
old_r_seed = seedgen.randint(2**30)
......
......@@ -141,13 +141,13 @@ class Test_pfunc(unittest.TestCase):
# by default, shared are not mutable unless doing an explicit update
f = pfunc([], [b_out], mode='FAST_RUN')
assert (f() == numpy.arange(5) * 2).all()
assert all( b.value == numpy.arange(5))
assert numpy.all( b.value == numpy.arange(5))
# using updates, b is now a mutable parameter
f = pfunc([], [b_out], updates=[(b, b_out)], mode='FAST_RUN')
assert (f() == numpy.arange(5)*2 ).all()
assert all( b.value == numpy.arange(5)*2) # because of the update
assert all( bval == numpy.arange(5)*2) # because of mutable=True
assert ( b.value == numpy.arange(5)*2).all() # because of the update
assert ( bval == numpy.arange(5)*2).all() # because of mutable=True
# do not depend on updates being in-place though!
bval = numpy.arange(5)
......@@ -156,7 +156,7 @@ class Test_pfunc(unittest.TestCase):
assert ( f() == numpy.arange(5)*2 ).all()
assert (b.value == ((numpy.arange(5)*2)+3)).all() # because of the update
# bval got modified to something...
assert not all(bval == numpy.arange(5))
assert not (bval == numpy.arange(5)).all()
# ... but not to b.value !
assert not (bval == b.value).all()
......
......@@ -36,7 +36,10 @@ class BROKEN_ON_PURPOSE_StructuredDotCSC(gof.Op):
copy = False)
# TODO: todense() is automatic in 0.7.0, just remove the following line:
z = a * b
out[0] = z+0.5 if self.py_offset else z #ERROR TO ADD THIS CRAPPY OFFSET
#ERROR TO ADD THIS CRAPPY OFFSET
if self.py_offset:
out[0] = z+0.5
else: out[0] = z
def c_code(self, node, name, (a_val, a_ind, a_ptr, a_nrows, b), (z,), sub):
return """
......
......@@ -42,7 +42,10 @@ class StochasticGradientDescent(module.FancyModule):
raise ValueError('stepsize must be a scalar', stepsize)
self.params = params
self.gparams = T.grad(cost, self.params) if gradients is None else gradients
if gradients is None:
self.gparams = T.grad(cost, self.params)
else:
self.gparams = gradients
self.updates = dict((p, p - self.stepsize * g) for p, g in zip(self.params, self.gparams))
......
......@@ -695,6 +695,12 @@ def test_method_implicit_ticket_384():
if not str(e).startswith('Tried to provide value for implicit input'):
raise
def get_mode():
if default_mode != 'DEBUG_MODE':
mode = default_mode
else: mode = 'FAST_RUN'
return mode
def test_pickle():
"""Test that a module can be pickled"""
M = Module()
......@@ -704,7 +710,7 @@ def test_pickle():
M.f = Method([a], a + M.x + M.y)
M.g = Method([a], a * M.x * M.y)
mode = default_mode if default_mode != 'DEBUG_MODE' else 'FAST_RUN'
mode = get_mode()
m = M.make(x=numpy.zeros((4,5)), y=numpy.ones((2,3)), mode=mode)
m_dup = cPickle.loads(cPickle.dumps(m))
......@@ -729,7 +735,7 @@ def test_pickle_aliased_memory():
M.f = Method([a], a + M.x + M.y)
M.g = Method([a], a * M.x * M.y)
mode = default_mode if default_mode != 'DEBUG_MODE' else 'FAST_RUN'
mode = get_mode()
m = M.make(x=numpy.zeros((4,5)), y=numpy.ones((2,3)), mode=mode)
m.y = m.x[:]
......
......@@ -57,7 +57,10 @@ class MyOp(Op):
def __hash__(self):
#return hash(self.x if self.x is not None else id(self)) ^ hash(self.name)
return hash(self.x if self.x is not None else id(self))
if self.x is not None:
return hash(self.x)
else:
return id(self)
op1 = MyOp('Op1')
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论