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

dsl: Add functionality to intersect SubDimensions #2222

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

EdCaunt
Copy link
Contributor

@EdCaunt EdCaunt commented Oct 5, 2023

Introduce the ability to form a new SubDimension as the intersection of multiple SubDimensions

@codecov
Copy link

codecov bot commented Oct 5, 2023

Codecov Report

Merging #2222 (c020cf3) into master (a1e4d90) will decrease coverage by 0.06%.
Report is 4 commits behind head on master.
The diff coverage is 6.66%.

@@            Coverage Diff             @@
##           master    #2222      +/-   ##
==========================================
- Coverage   87.11%   87.05%   -0.06%     
==========================================
  Files         228      228              
  Lines       40810    40840      +30     
  Branches     7471     7486      +15     
==========================================
+ Hits        35551    35553       +2     
- Misses       4653     4681      +28     
  Partials      606      606              
Files Coverage Δ
devito/types/dimension.py 90.16% <6.66%> (-3.33%) ⬇️

@mloubout mloubout added the API api (symbolics, types, ...) label Oct 5, 2023
Copy link
Contributor

@mloubout mloubout left a comment

Choose a reason for hiding this comment

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

Some comments, can discuss.

This needs bunch of tests including with MPI. Do we wanna define union as well?

@@ -607,6 +607,65 @@ def middle(cls, name, parent, thickness_left, thickness_right, local=False):
thickness=((lst, thickness_left), (rst, thickness_right)),
local=local)

@classmethod
def intersection(cls, sdims):
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should not be a class method, similar to Set that defines intersection as set().intersectio not Set.intersection.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it wants to be a class method since you could conceivably want the intersection of several SubDimensions, so it would want to be intersect(subdimensions) rather than intersect(self, other) imo

Copy link
Contributor

Choose a reason for hiding this comment

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

You can still have multiple ones, again similar to a set set(a).intersection(a,b,c,d,e,f) there is nothing that prevents it. to have more than one without being a class method

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True, but then you have to arbitrarily pick one to be the "important" one with which you are intersecting all the others

def intersection(cls, sdims):
# Check all SubDimensions supplied overlap
# NOTE: Think the test for overlap isn't strict enough?
if not all([sdims[0].overlap(sdim) for sdim in sdims[1:]]):
Copy link
Contributor

Choose a reason for hiding this comment

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

Would make it easier here to with just self.overlap ...

if not all([sdims[0].overlap(sdim) for sdim in sdims[1:]]):
raise ValueError("SubDimensions do not all overlap")

name = '_n_'.join([sdim.name for sdim in sdims])
Copy link
Contributor

Choose a reason for hiding this comment

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

_i_ ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Was thinking it looks like the set intersection symbol if you squint at it?


name = '_n_'.join([sdim.name for sdim in sdims])
try:
[parent] = set([sdim.parent for sdim in sdims])
Copy link
Contributor

Choose a reason for hiding this comment

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

{self.parent}.union(*[sdim.parent for sdim in sdims])

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that this is both getting the parent and checking they all share a parent, since the unpack will fail with ValueError if the set does not contain one item


if all([sdim.is_left for sdim in sdims]):
# Only left SubDimensions results in left SubDimension
thickness = sympy.Min(*[sdim.thickness.left[1]
Copy link
Contributor

Choose a reason for hiding this comment

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

use our Min not sympy

local=local)
elif all([sdim.is_right for sdim in sdims]):
# Only right SubDimensions results in right SubDimension
thickness = sympy.Min(*[sdim.thickness.right[1]
Copy link
Contributor

Choose a reason for hiding this comment

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

same, devito.Min

# will always be middle
width = parent.symbolic_max - parent.symbolic_min + 1

def get_left_thickness(sdim):
Copy link
Contributor

Choose a reason for hiding this comment

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

define as instance attribute outside, and then just self/sdim.right_thickness , no need for "get"

@EdCaunt
Copy link
Contributor Author

EdCaunt commented Oct 5, 2023

This needs bunch of tests including with MPI. Do we wanna define union as well?

Tests to come. Union is more complex and less urgent so was going to leave for now

Copy link
Contributor

@FabioLuporini FabioLuporini left a comment

Choose a reason for hiding this comment

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

add tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API api (symbolics, types, ...)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants