提交 643199e2 authored 作者: Virgile Andreani's avatar Virgile Andreani 提交者: Ricardo Vieira

Remove OrderedDict from updates.py

上级 12ad86b0
"""Defines Updates object for storing a (SharedVariable, new_value) mapping."""
import logging
import warnings
from collections import OrderedDict
from pytensor.compile.sharedvalue import SharedVariable
......@@ -12,9 +10,9 @@ __docformat__ = "restructuredtext en"
logger = logging.getLogger("pytensor.updates")
# Must be an OrderedDict or updates will be applied in a non-deterministic
# order.
class OrderedUpdates(OrderedDict):
# Relies on the fact that dict is ordered, otherwise updates will be applied
# in a non-deterministic order.
class OrderedUpdates(dict):
"""
Dict-like mapping from SharedVariable keys to their new values.
......@@ -22,20 +20,6 @@ class OrderedUpdates(OrderedDict):
"""
def __init__(self, *key, **kwargs):
if (
len(key) >= 1
and isinstance(key[0], dict)
and len(key[0]) > 1
and not isinstance(key[0], OrderedDict)
):
# Warn when using as input a non-ordered dictionary.
warnings.warn(
"Initializing an `OrderedUpdates` from a "
"non-ordered dictionary with 2+ elements could "
"make your code non-deterministic. You can use "
"an OrderedDict that is available at "
"collections.OrderedDict for python 2.6+."
)
super().__init__(*key, **kwargs)
for key in self:
if not isinstance(key, SharedVariable):
......@@ -56,19 +40,7 @@ class OrderedUpdates(OrderedDict):
def update(self, other=None):
if other is None:
return
if (
isinstance(other, dict)
and len(other) > 1
and not isinstance(other, OrderedDict)
):
# Warn about non-determinism.
warnings.warn(
"Updating an `OrderedUpdates` with a "
"non-ordered dictionary with 2+ elements could "
"make your code non-deterministic",
stacklevel=2,
)
for key, val in OrderedDict(other).items():
for key, val in dict(other).items():
if key in self:
if self[key] == val:
continue
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论