Conversation
0ed120a to
0c73b20
Compare
dd6d54f to
2ff245d
Compare
|
@inducer Should be ready for a look. I think the mypy errors are unrelated, they're occurring on main too. |
2ff245d to
f8c2c68
Compare
f8c2c68 to
58c8dbf
Compare
4519ce2 to
913d3d1
Compare
312e8ff to
72ce101
Compare
|
Uh-oh. The recent typing apocalypse has made a bit of a mess of this. I've started resolving conflicts, but I got bogged down in |
b8cbbc5 to
e57fe22
Compare
|
#571 should address the mypy issue. |
e57fe22 to
a4b609c
Compare
pytato/transform/__init__.py
Outdated
| try: | ||
| method = self.map_function_definition # type: ignore[attr-defined] | ||
| except AttributeError: | ||
| return cast("FunctionResultT", self.map_foreign(expr, *args, **kwargs)) |
pytato/transform/__init__.py
Outdated
| f"{type(self).__name__} cannot handle expressions of type {type(expr)}") | ||
|
|
||
| def map_foreign(self, expr: Any, *args: P.args, **kwargs: P.kwargs) -> ResultT: | ||
| def map_foreign(self, expr: Any, *args: P.args, **kwargs: P.kwargs) -> Any: |
There was a problem hiding this comment.
I think we can get rid of map_foreign.
There was a problem hiding this comment.
Reprifier appears to override map_foreign to handle stringifying non-array fields. Seems like it needs to stay?
There was a problem hiding this comment.
Let's move it to Reprifier then. I don't think it needs to be a feature of the generic machinery.
pytato/transform/__init__.py
Outdated
| else: | ||
| function_cache = {} | ||
|
|
||
| self._function_cache: dict[Hashable, FunctionResultT] = function_cache |
pytato/transform/__init__.py
Outdated
| # Why multiple inheriting? | ||
| CachedMapper[ArrayOrNames, FunctionDefinition, P], | ||
| Mapper[ArrayOrNames, FunctionDefinition, P] |
There was a problem hiding this comment.
| # Why multiple inheriting? | |
| CachedMapper[ArrayOrNames, FunctionDefinition, P], | |
| Mapper[ArrayOrNames, FunctionDefinition, P] | |
| CachedMapper[ArrayOrNames, FunctionDefinition, P], |
I don't think it should be.
There was a problem hiding this comment.
Seems to work fine without it.
pytato/transform/__init__.py
Outdated
|
|
||
| .. automethod:: clone_for_callee | ||
| """ | ||
| # FIXME: This inflates recursion depth |
There was a problem hiding this comment.
if TYPE_CHECKING:
... (same)
else:
@property
def rec_ary(self):
return self.rec
pytato/transform/__init__.py
Outdated
|
|
||
| .. automethod:: clone_for_callee | ||
| """ | ||
| # FIXME: This inflates recursion depth |
There was a problem hiding this comment.
def is_array(expr: ArrayOrNames) -> Array:
assert isinstance(expr, Array)
return expr
(This is probably the saner way.)
There was a problem hiding this comment.
Something like ca4f336?
(The other way appears to work too: majosm@34af8ef)
pytato/transform/__init__.py
Outdated
| # Don't need to pass function cache as argument here, because unlike | ||
| # CachedMapper we're not creating a new mapper for each call | ||
| self.function_cache: dict[FunctionDefinition, FunctionResultT] = {} |
There was a problem hiding this comment.
I think the behavior should be consistent across mapper types.
There was a problem hiding this comment.
Added _function_cache to the __init__ args like the others. I didn't go the whole way and add clone_for_callee, etc., yet because I'm worried that's going to make a mess of my downstream changes.
pytato/transform/__init__.py
Outdated
| else: | ||
| visited_functions = set() | ||
|
|
||
| self._visited_functions: set[Any] = visited_functions |
pytato/target/loopy/codegen.py
Outdated
| # {{{ codegen mapper | ||
|
|
||
| class CodeGenMapper(Mapper[ImplementedResult, [CodeGenState]]): | ||
| class CodeGenMapper(Mapper[ImplementedResult, None, [CodeGenState]]): |
There was a problem hiding this comment.
| class CodeGenMapper(Mapper[ImplementedResult, None, [CodeGenState]]): | |
| class CodeGenMapper(Mapper[ImplementedResult, Never, [CodeGenState]]): |
There was a problem hiding this comment.
Added here and in a few other places.
610d413 to
5d4b0e2
Compare
…t don't support functions
doesn't appear to be needed
the latter inflates recursion depth
5d4b0e2 to
1890af8
Compare
|
Ready for another look I think @inducer. |
inducer
left a comment
There was a problem hiding this comment.
Thanks! A few questions/comments below.
| def __init__( | ||
| self, | ||
| count_duplicates: bool = False, | ||
| _visited_functions: set[Any] | None = None, |
There was a problem hiding this comment.
Can something more precise than Any be said here? (Also for other _visited_functions annotations.)
There was a problem hiding this comment.
Looks like I did that to match _visited_arrays_or_names in CachedWalkMapper, which also uses Any. I guess I could change both to Hashable?
pytato/target/python/numpy_like.py
Outdated
|
|
||
|
|
||
| class NumpyCodegenMapper(CachedMapper[str, []]): | ||
| class NumpyCodegenMapper(CachedMapper[str, FunctionDefinition, []]): |
There was a problem hiding this comment.
Is this annotation right? Does the numpy target generate appropriate code for functions?
There was a problem hiding this comment.
NumpyCodegenMapper doesn't support functions, so I guess this should be Never. Same for FancyDotWriter. Fixed these.
pytato/transform/calls.py
Outdated
| """ | ||
|
|
||
| def __init__(self, substitutions: Mapping[str, Array]) -> None: | ||
| # Ignoring function cache, not needed |
There was a problem hiding this comment.
How come? Not using the function cache may lead to large amounts of redundant work?
(I'm OK with not acting on this right now, but maybe this comment should be a FIXME?)
There was a problem hiding this comment.
PlaceholderSubstitutor should only be called on function bodies that don't have functions nested in them (since the placeholder names can overlap). I've disabled PlaceholderSubstitutor.map_named_call_result to make that more explicit.
|
I changed |
inducer
left a comment
There was a problem hiding this comment.
Thanks! This looks great. In it goes.
Caches the results of mapping
FunctionDefinitions. Caching is done globally to avoid re-traversing functions in different call stack frames.Depends on
#503(merged) and#530(merged).