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

compiler: Expose Bundle's properties correctly #2487

Merged
merged 2 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 5 additions & 2 deletions devito/types/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,8 @@ def __args_setup__(cls, *args, **kwargs):
raise ValueError("Component type must be subclass of AbstractFunction")
if len({i.__padding_dtype__ for i in components}) != 1:
raise ValueError("Components must have the same padding dtype")
if len({i.properties for i in components}) != 1:
raise ValueError("Components must have the same properties")
Copy link
Contributor

Choose a reason for hiding this comment

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

looks more like "counting" rather than "comparing", should you say, the same number of properties?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's not counting properties it's check the set length one, i.e all properties are the same


return args, kwargs

Expand Down Expand Up @@ -441,12 +443,13 @@ def initvalue(self):

# Overrides defaulting to self.c0's behaviour

for i in ['_mem_internal_eager', '_mem_internal_lazy', '_mem_local',
for i in ('_mem_internal_eager', '_mem_internal_lazy', '_mem_local',
'_mem_mapped', '_mem_host', '_mem_stack', '_mem_constant',
'_mem_shared', '__padding_dtype__', '_size_domain', '_size_halo',
'_size_owned', '_size_padding', '_size_nopad', '_size_nodomain',
'_offset_domain', '_offset_halo', '_offset_owned', '_dist_dimensions',
'_C_get_field', 'grid', 'symbolic_shape']:
'_C_get_field', 'grid', 'symbolic_shape',
*AbstractFunction.__properties__):
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: ('_mem_internal_eager', '_mem_internal_lazy', ...) + AbstractFunction.__properties__ might be tidier imo

Copy link
Contributor

Choose a reason for hiding this comment

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

a + b creates two tuples a, b then a new third one to merge them while current one only creates one directly.

locals()[i] = property(lambda self, v=i: getattr(self.c0, v))

@property
Expand Down
8 changes: 6 additions & 2 deletions devito/types/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,8 @@ class AbstractFunction(sympy.Function, Basic, Pickable, Evaluable):
__rkwargs__ = ('name', 'dtype', 'grid', 'halo', 'padding', 'ghost',
'alias', 'space', 'function', 'is_transient', 'avg_mode')

__properties__ = ('is_const', 'is_transient')

def __new__(cls, *args, **kwargs):
# Preprocess arguments
args, kwargs = cls.__args_setup__(*args, **kwargs)
Expand Down Expand Up @@ -970,8 +972,6 @@ def __init_finalize__(self, *args, **kwargs):
# A `Distributor` to handle domain decomposition
self._distributor = self.__distributor_setup__(**kwargs)

# Symbol properties

# "Aliasing" another AbstractFunction means that `self` logically
# represents another object. For example, `self` might be used as the
# formal parameter of a routine generated by the compiler, where the
Expand Down Expand Up @@ -1274,6 +1274,10 @@ def is_const(self):
def is_transient(self):
return self._is_transient

@cached_property
def properties(self):
return frozendict([(i, getattr(self, i)) for i in self.__properties__])

@property
def avg_mode(self):
return self._avg_mode
Expand Down
Loading