Skip to content

Commit

Permalink
use a class for CachedMapper caches instead of using a dict directly
Browse files Browse the repository at this point in the history
  • Loading branch information
majosm committed Sep 24, 2024
1 parent 82ce846 commit a34936a
Show file tree
Hide file tree
Showing 5 changed files with 222 additions and 95 deletions.
5 changes: 3 additions & 2 deletions pytato/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"""

import dataclasses
from typing import Any, Hashable, Mapping, Tuple
from typing import Any, Mapping, Tuple, TypeAlias

from immutabledict import immutabledict

Expand Down Expand Up @@ -117,12 +117,13 @@ class CodeGenPreprocessor(ToIndexLambdaMixin, CopyMapper): # type: ignore[misc]
:class:`~pytato.array.Stack` :class:`~pytato.array.IndexLambda`
====================================== =====================================
"""
_FunctionCacheT: TypeAlias = CopyMapper._FunctionCacheT

def __init__(
self,
target: Target,
kernels_seen: dict[str, lp.LoopKernel] | None = None,
_function_cache: dict[Hashable, FunctionDefinition] | None = None
_function_cache: _FunctionCacheT | None = None
) -> None:
super().__init__(_function_cache=_function_cache)
self.bound_arguments: dict[str, DataInterface] = {}
Expand Down
8 changes: 5 additions & 3 deletions pytato/distributed/partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
Iterator,
Mapping,
Sequence,
TypeAlias,
TypeVar,
cast,
)
Expand Down Expand Up @@ -287,12 +288,13 @@ class _DistributedInputReplacer(CopyMapper):
instances for their assigned names. Also gathers names for
user-supplied inputs needed by the part
"""
_FunctionCacheT: TypeAlias = CopyMapper._FunctionCacheT

def __init__(self,
recvd_ary_to_name: Mapping[Array, str],
sptpo_ary_to_name: Mapping[Array, str],
name_to_output: Mapping[str, Array],
_function_cache: dict[Hashable, FunctionDefinition] | None = None,
_function_cache: _FunctionCacheT | None = None,
) -> None:
super().__init__(_function_cache=_function_cache)

Expand Down Expand Up @@ -342,9 +344,9 @@ def map_distributed_send(self, expr: DistributedSend) -> DistributedSend:

# type ignore because no args, kwargs
def rec(self, expr: ArrayOrNames) -> ArrayOrNames: # type: ignore[override]
key = self.get_cache_key(expr)
key = self._cache.get_key(expr)
try:
return self._cache[key]
return self._cache.retrieve(expr, key=key)
except KeyError:
pass

Expand Down
Loading

0 comments on commit a34936a

Please sign in to comment.