提交 bc578962 authored 作者: Razvan Pascanu's avatar Razvan Pascanu

Merge pull request #385 from delallea/minor

Minor stuff Thanks Olivier :) Is great to have someone like you involved in the project, that is able to notice and fix all the small details.
...@@ -110,7 +110,7 @@ def get_updates_and_outputs(ls): ...@@ -110,7 +110,7 @@ def get_updates_and_outputs(ls):
raise ValueError(('Scan can not parse the return value' raise ValueError(('Scan can not parse the return value'
' of your constructive function given to scan')) ' of your constructive function given to scan'))
ls = list(ls) ls = list(ls)
deprication_msg = ('The return value of the lambda function' deprecation_msg = ('The return value of the lambda function'
' has been restricted. you have to always return first the' ' has been restricted. you have to always return first the'
' outputs (if any), afterwards the updates (if any) and' ' outputs (if any), afterwards the updates (if any) and'
' at the end the condition') ' at the end the condition')
...@@ -126,7 +126,7 @@ def get_updates_and_outputs(ls): ...@@ -126,7 +126,7 @@ def get_updates_and_outputs(ls):
raise ValueError(error_msg) raise ValueError(error_msg)
elif is_updates(ls[0]): elif is_updates(ls[0]):
if is_outputs(ls[1]): if is_outputs(ls[1]):
raise ValueError(deprication_msg) raise ValueError(deprecation_msg)
elif is_condition(ls[1]): elif is_condition(ls[1]):
return (ls[1].condition, [], dict(ls[0])) return (ls[1].condition, [], dict(ls[0]))
else: else:
......
...@@ -135,7 +135,7 @@ class TestScan(unittest.TestCase): ...@@ -135,7 +135,7 @@ class TestScan(unittest.TestCase):
else: else:
shared_outs = [sh * 5 for sh in shared_vars] shared_outs = [sh * 5 for sh in shared_vars]
states_out = [x for x in states_out] states_out = [x for x in states_out]
pure_outs = [ 2 for x in xrange(n_outputs)] pure_outs = [2 for x in xrange(n_outputs)]
return states_out + pure_outs, dict(zip(shared_vars, return states_out + pure_outs, dict(zip(shared_vars,
shared_outs)) shared_outs))
...@@ -249,7 +249,7 @@ class TestScan(unittest.TestCase): ...@@ -249,7 +249,7 @@ class TestScan(unittest.TestCase):
if n_steps is not None and abs(n_steps) == 1: if n_steps is not None and abs(n_steps) == 1:
all_nodes = my_f.maker.env.toposort() all_nodes = my_f.maker.env.toposort()
assert len([x for x in all_nodes assert len([x for x in all_nodes
if isinstance(x.op,ScanOp)]) == 0 if isinstance(x.op, ScanOp)]) == 0
print >>sys.stderr, ' n_steps', n_steps print >>sys.stderr, ' n_steps', n_steps
print >>sys.stderr, ' go_backwards', go_backwards print >>sys.stderr, ' go_backwards', go_backwards
...@@ -300,12 +300,14 @@ class TestScan(unittest.TestCase): ...@@ -300,12 +300,14 @@ class TestScan(unittest.TestCase):
try: try:
assert numpy.allclose(th_out, num_out) assert numpy.allclose(th_out, num_out)
except: except:
import ipdb; ipdb.set_trace() #import ipdb; ipdb.set_trace()
raise
for th_out, num_out in zip(shared_vars, numpy_shared): for th_out, num_out in zip(shared_vars, numpy_shared):
try: try:
assert numpy.allclose(th_out.get_value(), num_out) assert numpy.allclose(th_out.get_value(), num_out)
except: except:
import ipdb; ipdb.set_trace() #import ipdb; ipdb.set_trace()
raise
# Scenario 2 : Loose fit (sequences longer then required) # Scenario 2 : Loose fit (sequences longer then required)
print >>sys.stderr, ' Scenario 2. Loose shapes' print >>sys.stderr, ' Scenario 2. Loose shapes'
input_values = [] input_values = []
...@@ -319,7 +321,8 @@ class TestScan(unittest.TestCase): ...@@ -319,7 +321,8 @@ class TestScan(unittest.TestCase):
if n_steps is not None: if n_steps is not None:
# loose inputs make sense only when n_steps is # loose inputs make sense only when n_steps is
# defined # defined
data = rng.uniform(size=(abs(_n_steps) + offset + pos + 1, 4)) data = rng.uniform(
size=(abs(_n_steps) + offset + pos + 1, 4))
else: else:
data = rng.uniform(size=(abs(_n_steps) + offset, 4)) data = rng.uniform(size=(abs(_n_steps) + offset, 4))
input_values.append(data) input_values.append(data)
...@@ -400,9 +403,9 @@ class TestScan(unittest.TestCase): ...@@ -400,9 +403,9 @@ class TestScan(unittest.TestCase):
[dict(tap=-2, use=True), [dict(tap=-2, use=True),
dict(tap=3, use=True)]] dict(tap=3, use=True)]]
test_nb = 0 test_nb = 0
for n_ins in [1,2]: for n_ins in [1, 2]:
# Randomly pick up 4*n_ins combinations of arguments # Randomly pick up 4*n_ins combinations of arguments
for k in xrange(4*n_ins): for k in xrange(4 * n_ins):
inp = [] inp = []
for inp_nb in xrange(n_ins): for inp_nb in xrange(n_ins):
...@@ -424,9 +427,9 @@ class TestScan(unittest.TestCase): ...@@ -424,9 +427,9 @@ class TestScan(unittest.TestCase):
dict(tap=-2, use=True)], dict(tap=-2, use=True)],
[dict(tap=-4, use=False), [dict(tap=-4, use=False),
dict(tap=-2, use=True)]] dict(tap=-2, use=True)]]
for n_ins in [1,2]: for n_ins in [1, 2]:
# Randomly pick up 4*n_ins combinations of arguments # Randomly pick up 4*n_ins combinations of arguments
for k in xrange(4*n_ins): for k in xrange(4 * n_ins):
state = [] state = []
for state_nb in xrange(n_ins): for state_nb in xrange(n_ins):
pos = rng.randint(len(possible_taps_use_pairs)) pos = rng.randint(len(possible_taps_use_pairs))
...@@ -442,8 +445,8 @@ class TestScan(unittest.TestCase): ...@@ -442,8 +445,8 @@ class TestScan(unittest.TestCase):
# The test will also have to be changesd following some further # The test will also have to be changesd following some further
# restriction of scan and reduction of the number of corner cases # restriction of scan and reduction of the number of corner cases
return return
for n_outputs in [0,1,2]: for n_outputs in [0, 1, 2]:
for n_shared_updates in [0,1, 2]: for n_shared_updates in [0, 1, 2]:
for n_random_combinations in xrange(1): for n_random_combinations in xrange(1):
pos_inp = rng.randint(len(all_inputs_info)) pos_inp = rng.randint(len(all_inputs_info))
pos_st = rng.randint(len(all_states_info)) pos_st = rng.randint(len(all_states_info))
...@@ -463,14 +466,14 @@ class TestScan(unittest.TestCase): ...@@ -463,14 +466,14 @@ class TestScan(unittest.TestCase):
n_outputs=n_outputs, n_outputs=n_outputs,
n_shared_updates=n_shared_updates) n_shared_updates=n_shared_updates)
def test002_generator_one_scalar_output(self): def test002_generator_one_scalar_output(self):
# The test fails, because the `work-in-progress` ScanOp always runs in # The test fails, because the `work-in-progress` ScanOp always runs in
# place (even when told not to by DebugMode). As this op will change # place (even when told not to by DebugMode). As this op will change
# soon, and it is in the sandbox and not for user consumption, the # soon, and it is in the sandbox and not for user consumption, the
# error is marked as KnownFailure # error is marked as KnownFailure
raise KnownFailureTest raise KnownFailureTest('Work-in-progress sandbox ScanOp is not fully '
'functional yet')
def f_pow2(x_tm1): def f_pow2(x_tm1):
return 2 * x_tm1 return 2 * x_tm1
...@@ -505,7 +508,10 @@ class TestScan(unittest.TestCase): ...@@ -505,7 +508,10 @@ class TestScan(unittest.TestCase):
# place (even when told not to by DebugMode). As this op will change # place (even when told not to by DebugMode). As this op will change
# soon, and it is in the sandbox and not for user consumption, the # soon, and it is in the sandbox and not for user consumption, the
# error is marked as KnownFailure # error is marked as KnownFailure
raise KnownFailureTest
raise KnownFailureTest('Work-in-progress sandbox ScanOp is not fully '
'functional yet')
def f_rnn(u_t, x_tm1, W_in, W): def f_rnn(u_t, x_tm1, W_in, W):
return u_t * W_in + x_tm1 * W return u_t * W_in + x_tm1 * W
u = theano.tensor.vector('u') u = theano.tensor.vector('u')
......
...@@ -225,7 +225,7 @@ def get_updates_and_outputs(ls): ...@@ -225,7 +225,7 @@ def get_updates_and_outputs(ls):
if not isinstance(ls, (list, tuple)): if not isinstance(ls, (list, tuple)):
raise ValueError(error_msg) raise ValueError(error_msg)
ls = list(ls) ls = list(ls)
deprication_msg = ('The return value of the lambda function' deprecation_msg = ('The return value of the lambda function'
' has been restricted. you have to always return first the' ' has been restricted. you have to always return first the'
' outputs (if any), afterwards the updates (if any) and' ' outputs (if any), afterwards the updates (if any) and'
' at the end the conclusion') ' at the end the conclusion')
...@@ -239,7 +239,7 @@ def get_updates_and_outputs(ls): ...@@ -239,7 +239,7 @@ def get_updates_and_outputs(ls):
raise ValueError(error_msg) raise ValueError(error_msg)
elif is_updates(ls[0]): elif is_updates(ls[0]):
if is_outputs(ls[1]): if is_outputs(ls[1]):
raise ValueError(deprication_msg) raise ValueError(deprecation_msg)
elif is_condition(ls[1]): elif is_condition(ls[1]):
return (ls[1].condition, [], dict(ls[0])) return (ls[1].condition, [], dict(ls[0]))
else: else:
......
...@@ -2896,11 +2896,11 @@ class T_Scan(unittest.TestCase): ...@@ -2896,11 +2896,11 @@ class T_Scan(unittest.TestCase):
rng = numpy.random.RandomState(utt.fetch_seed()) rng = numpy.random.RandomState(utt.fetch_seed())
# If numbers are small, the gradients with respect to x are small # If numbers are small, the gradients with respect to x are small
# and the numeric differentiation becomes unstable. # and the numeric differentiation becomes unstable.
# To fix this issue I unsure we are sampling numbers larger in # To fix this issue I ensure we are sampling numbers larger in
# absolute value than 1 # absolute value than 1.
v_x = numpy.array(rng.uniform(size=(5, 2, 2), low=1., high=3.), v_x = numpy.array(rng.uniform(size=(5, 2, 2), low=1., high=3.),
dtype=theano.config.floatX) dtype=theano.config.floatX)
# making some entries to be negative # Making some entries to be negative.
pos = rng.uniform(size=(5, 2, 2), low=0., high=1) < .5 pos = rng.uniform(size=(5, 2, 2), low=0., high=1) < .5
v_x[pos] = -1 * v_x[pos] v_x[pos] = -1 * v_x[pos]
v_w = numpy.array(rng.uniform(size=(2, 2), low=1., high=3.), v_w = numpy.array(rng.uniform(size=(2, 2), low=1., high=3.),
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论