Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace pyrsistent.PMap, immutables.Map, immutabledict with constantdict #884

Merged
merged 16 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions loopy/kernel/function_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,8 @@ def __init__(self,
try:
hash(arg_id_to_dtype)
except TypeError:
if arg_id_to_dtype is None:
arg_id_to_dtype = {}
Copy link
Collaborator Author

@matthiasdiener matthiasdiener Jan 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure whether this is the intended behavior here (or whether arg_id_to_dtype should just be set to None). This bug seems to have come in with 70cc100#diff-c2536267212ab595d8fbafdc40257bf749f171cc1e23c6c5113fcf2e41546b02 (seems like typing with immutabledict is not strict enough so that mypy did not catch this earlier)

Same below.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can just be assert arg_id_to_dtype is not None (since None is hashable, we should not end up in this branch).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed in ba93a2f

arg_id_to_dtype = constantdict(arg_id_to_dtype)
warn("arg_id_to_dtype passed to InKernelCallable was not hashable. "
"This usage is deprecated and will stop working in 2026.",
Expand All @@ -356,6 +358,8 @@ def __init__(self,
try:
hash(arg_id_to_descr)
except TypeError:
if arg_id_to_descr is None:
arg_id_to_descr = {}
arg_id_to_descr = constantdict(arg_id_to_descr)
warn("arg_id_to_descr passed to InKernelCallable was not hashable. "
"This usage is deprecated and will stop working in 2026.",
Expand Down
2 changes: 1 addition & 1 deletion loopy/schedule/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
from functools import cached_property, reduce
from typing import Generic, TypeVar

from constantdict import constantdict as Map
from constantdict import constantdict as Map # noqa: N812

from pytools import memoize_method

Expand Down
10 changes: 5 additions & 5 deletions loopy/translation_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,14 +302,14 @@ def with_kernel(self, kernel: LoopKernel) -> Self:
# update the callable kernel
new_in_knl_callable = self.callables_table[kernel.name].copy(
subkernel=kernel)
new_callables = self.callables_table.delete(kernel.name).set(
kernel.name, new_in_knl_callable)
return self.copy(callables_table=new_callables)
new_callables = self.callables_table.mutate()
new_callables[kernel.name] = new_in_knl_callable
return self.copy(callables_table=new_callables.finish())
else:
# add a new callable kernel
clbl = CallableKernel(kernel)
new_callables = self.callables_table.set(kernel.name, clbl)
return self.copy(callables_table=new_callables)
return self.copy(
callables_table=self.callables_table.set(kernel.name, clbl))

def __getitem__(self, name) -> LoopKernel:
"""
Expand Down
Loading