From d85c728a20d9e92486479346402536a4e5f3ca68 Mon Sep 17 00:00:00 2001 From: Krzysztof Maziarz Date: Fri, 8 Sep 2023 13:37:43 +0000 Subject: [PATCH] refactor(node_evaluators): Move the empty list handling to the base class --- syntheseus/search/node_evaluation/base.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/syntheseus/search/node_evaluation/base.py b/syntheseus/search/node_evaluation/base.py index c2218c98..ce530bd9 100644 --- a/syntheseus/search/node_evaluation/base.py +++ b/syntheseus/search/node_evaluation/base.py @@ -75,6 +75,9 @@ def num_calls(self) -> int: def __call__( self, nodes: Sequence[NodeType], graph: Optional[RetrosynthesisSearchGraph] = None ) -> Sequence[float]: + if not nodes: # handle the case when there are no nodes to score + return [] + self._num_calls += len(nodes) return self._evaluate_nodes(nodes, graph) @@ -138,9 +141,6 @@ def _get_probability(self, node, graph) -> float: return metadata["probability"] # type: ignore def _evaluate_nodes(self, nodes, graph=None) -> Sequence[float]: - if not nodes: # handle the case when there are no nodes to score - return [] - probs = np.asarray([self._get_probability(n, graph) for n in nodes]) probs = np.clip(probs, a_min=self._clip_probability_min, a_max=self._clip_probability_max)