1
1
"""Defines Updates object for storing a (SharedVariable, new_value) mapping."""
2
2
3
3
import logging
4
- import warnings
5
- from collections import OrderedDict
6
4
7
5
from pytensor .compile .sharedvalue import SharedVariable
8
6
12
10
logger = logging .getLogger ("pytensor.updates" )
13
11
14
12
15
- # Must be an OrderedDict or updates will be applied in a non-deterministic
16
- # order.
17
- class OrderedUpdates (OrderedDict ):
13
+ # Relies on the fact that dict is ordered, otherwise updates will be applied
14
+ # in a non-deterministic order.
15
+ class OrderedUpdates (dict ):
18
16
"""
19
17
Dict-like mapping from SharedVariable keys to their new values.
20
18
21
19
This mapping supports the use of the "+" operator for the union of updates.
22
20
"""
23
21
24
22
def __init__ (self , * key , ** kwargs ):
25
- if (
26
- len (key ) >= 1
27
- and isinstance (key [0 ], dict )
28
- and len (key [0 ]) > 1
29
- and not isinstance (key [0 ], OrderedDict )
30
- ):
31
- # Warn when using as input a non-ordered dictionary.
32
- warnings .warn (
33
- "Initializing an `OrderedUpdates` from a "
34
- "non-ordered dictionary with 2+ elements could "
35
- "make your code non-deterministic. You can use "
36
- "an OrderedDict that is available at "
37
- "collections.OrderedDict for python 2.6+."
38
- )
39
23
super ().__init__ (* key , ** kwargs )
40
24
for key in self :
41
25
if not isinstance (key , SharedVariable ):
@@ -56,19 +40,7 @@ def __setitem__(self, key, value):
56
40
def update (self , other = None ):
57
41
if other is None :
58
42
return
59
- if (
60
- isinstance (other , dict )
61
- and len (other ) > 1
62
- and not isinstance (other , OrderedDict )
63
- ):
64
- # Warn about non-determinism.
65
- warnings .warn (
66
- "Updating an `OrderedUpdates` with a "
67
- "non-ordered dictionary with 2+ elements could "
68
- "make your code non-deterministic" ,
69
- stacklevel = 2 ,
70
- )
71
- for key , val in OrderedDict (other ).items ():
43
+ for key , val in dict (other ).items ():
72
44
if key in self :
73
45
if self [key ] == val :
74
46
continue
0 commit comments