Skip to content

Commit b3b4033

Browse files
ArmavicaricardoV94
authored andcommitted
Use a defaultdict in graph/fg
1 parent 8757f5f commit b3b4033

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

pytensor/graph/fg.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""A container for specifying and manipulating a graph with distinct inputs and outputs."""
22

33
import time
4-
from collections import OrderedDict
4+
from collections import OrderedDict, defaultdict
55
from collections.abc import Iterable, Sequence
66
from typing import TYPE_CHECKING, Any, Literal, Union, cast
77

@@ -109,7 +109,7 @@ def __init__(
109109
inputs = [cast(Variable, _memo[i]) for i in inputs]
110110

111111
self.execute_callbacks_time: float = 0.0
112-
self.execute_callbacks_times: dict[Feature, float] = {}
112+
self.execute_callbacks_times: dict[Feature, float] = defaultdict(float)
113113

114114
if features is None:
115115
features = []
@@ -673,7 +673,6 @@ def attach_feature(self, feature: Feature) -> None:
673673
attach(self)
674674
except AlreadyThere:
675675
return
676-
self.execute_callbacks_times.setdefault(feature, 0.0)
677676
# It would be nice if we could require a specific class instead of
678677
# a "workalike" so we could do actual error checking
679678
# if not isinstance(feature, Feature):

0 commit comments

Comments
 (0)