Skip to content

Commit 79ce510

Browse files
ArmavicaricardoV94
authored andcommitted
Remove OrderedDict from tests/scan/test_basic
1 parent 643199e commit 79ce510

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

tests/scan/test_basic.py

+11-14
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import pickle
1414
import shutil
1515
import sys
16-
from collections import OrderedDict
1716
from tempfile import mkdtemp
1817

1918
import numpy as np
@@ -764,11 +763,9 @@ def test_output_padding(self):
764763
b = shared(np.random.default_rng(utt.fetch_seed()).random((5, 4)))
765764

766765
def inner_func(a):
767-
return a + 1, OrderedDict([(b, 2 * b)])
766+
return a + 1, {b: 2 * b}
768767

769-
out, updates = scan(
770-
inner_func, outputs_info=[OrderedDict([("initial", init_a)])], n_steps=1
771-
)
768+
out, updates = scan(inner_func, outputs_info=[{"initial": init_a}], n_steps=1)
772769
out = out[-1]
773770
assert out.type.ndim == a.type.ndim
774771
assert updates[b].type.ndim == b.type.ndim
@@ -934,7 +931,7 @@ def test_only_shared_no_input_no_output(self):
934931
state = shared(v_state, "vstate")
935932

936933
def f_2():
937-
return OrderedDict([(state, 2 * state)])
934+
return {state: 2 * state}
938935

939936
n_steps = iscalar("nstep")
940937
output, updates = scan(
@@ -968,7 +965,7 @@ def test_shared_updates(self):
968965
X = shared(np.array(1))
969966

970967
out, updates = scan(
971-
lambda: OrderedDict([(X, (X + 1))]),
968+
lambda: {X: (X + 1)},
972969
outputs_info=[],
973970
non_sequences=[],
974971
sequences=[],
@@ -984,7 +981,7 @@ def test_shared_memory_aliasing_updates(self):
984981
y = shared(np.array(1))
985982

986983
out, updates = scan(
987-
lambda: OrderedDict([(x, x + 1), (y, x)]),
984+
lambda: {x: x + 1, y: x},
988985
outputs_info=[],
989986
non_sequences=[],
990987
sequences=[],
@@ -1914,7 +1911,7 @@ def test_grad_numeric_shared(self):
19141911
shared_var = shared(np.float32(1.0))
19151912

19161913
def inner_fn():
1917-
return [], OrderedDict([(shared_var, shared_var + np.float32(1.0))])
1914+
return [], {shared_var: shared_var + np.float32(1.0)}
19181915

19191916
_, updates = scan(
19201917
inner_fn, n_steps=10, truncate_gradient=-1, go_backwards=False
@@ -2746,7 +2743,7 @@ def one_step(x_t, h_tm1, W):
27462743

27472744
v1 = shared(np.ones(5, dtype=config.floatX))
27482745
v2 = shared(np.ones((5, 5), dtype=config.floatX))
2749-
shapef = function([W], expr, givens=OrderedDict([(initial, v1), (inpt, v2)]))
2746+
shapef = function([W], expr, givens={initial: v1, inpt: v2})
27502747
# First execution to cache n_steps
27512748
shapef(np.ones((5, 5), dtype=config.floatX))
27522749

@@ -2755,7 +2752,7 @@ def one_step(x_t, h_tm1, W):
27552752
f = function(
27562753
[W, inpt],
27572754
d_cost_wrt_W,
2758-
givens=OrderedDict([(initial, shared(np.zeros(5)))]),
2755+
givens={initial: shared(np.zeros(5))},
27592756
)
27602757

27612758
rval = np.asarray([[5187989] * 5] * 5, dtype=config.floatX)
@@ -2956,7 +2953,7 @@ def onestep(x, x_tm4):
29562953

29572954
seq = matrix()
29582955
initial_value = shared(np.zeros((4, 1), dtype=config.floatX))
2959-
outputs_info = [OrderedDict([("initial", initial_value), ("taps", [-4])]), None]
2956+
outputs_info = [{"initial": initial_value, "taps": [-4]}, None]
29602957
results, updates = scan(fn=onestep, sequences=seq, outputs_info=outputs_info)
29612958

29622959
f = function([seq], results[1])
@@ -2979,10 +2976,10 @@ def onestep(x, x_tm4):
29792976

29802977
seq = matrix()
29812978
initial_value = shared(np.zeros((4, 1), dtype=config.floatX))
2982-
outputs_info = [OrderedDict([("initial", initial_value), ("taps", [-4])]), None]
2979+
outputs_info = [{"initial": initial_value, "taps": [-4]}, None]
29832980
results, _ = scan(fn=onestep, sequences=seq, outputs_info=outputs_info)
29842981
sharedvar = shared(np.zeros((1, 1), dtype=config.floatX))
2985-
updates = OrderedDict([(sharedvar, results[0][-1:])])
2982+
updates = {sharedvar: results[0][-1:]}
29862983

29872984
f = function([seq], results[1], updates=updates)
29882985

0 commit comments

Comments
 (0)