Skip to content

Commit

Permalink
make arg check private and add note about init
Browse files Browse the repository at this point in the history
  • Loading branch information
jcmgray committed May 12, 2020
1 parent a329e24 commit 95ca010
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion opt_einsum/path_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def setup(self, inputs, output, size_dict):
raise NotImplementedError

def __call__(self, inputs, output, size_dict, memory_limit):
self.check_args_against_first_call(inputs, output, size_dict)
self._check_args_against_first_call(inputs, output, size_dict)

# start a timer?
if self.max_time is not None:
Expand Down
5 changes: 3 additions & 2 deletions opt_einsum/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@ def __call__(self, inputs, output, size_dict, memory_limit=None):
where ``path`` is a list of int-tuples specifiying a contraction order.
"""

def check_args_against_first_call(self, inputs, output, size_dict):
def _check_args_against_first_call(self, inputs, output, size_dict):
"""Utility that stateful optimizers can use to ensure they are not
called with different contractions across separate runs.
"""
args = (inputs, output, size_dict)
if not hasattr(self, '_first_call_args'):
# simply set the attribute as currently there is no global PathOptimizer init
self._first_call_args = args
elif args != self._first_call_args:
raise ValueError("The arguments specifiying the contraction that this path optimizer "
Expand Down Expand Up @@ -348,7 +349,7 @@ def __call__(self, inputs, output, size_dict, memory_limit=None):
>>> optimal(isets, oset, idx_sizes, 5000)
[(0, 2), (0, 1)]
"""
self.check_args_against_first_call(inputs, output, size_dict)
self._check_args_against_first_call(inputs, output, size_dict)

inputs = tuple(map(frozenset, inputs))
output = frozenset(output)
Expand Down

0 comments on commit 95ca010

Please sign in to comment.