-
Notifications
You must be signed in to change notification settings - Fork 222
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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): | ||
# 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:]]): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would make it easier here to with just |
||
raise ValueError("SubDimensions do not all overlap") | ||
|
||
name = '_n_'.join([sdim.name for sdim in sdims]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||
try: | ||
[parent] = set([sdim.parent for sdim in sdims]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. {self.parent}.union(*[sdim.parent for sdim in sdims]) There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
except ValueError: | ||
raise ValueError("Inconsistent SubDimension parents") | ||
|
||
local = any([sdim.local for sdim in sdims]) | ||
|
||
if all([sdim.is_left for sdim in sdims]): | ||
# Only left SubDimensions results in left SubDimension | ||
thickness = sympy.Min(*[sdim.thickness.left[1] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use our |
||
for sdim in sdims]) | ||
return cls.left(name, parent, | ||
thickness, | ||
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] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same, |
||
for sdim in sdims]) | ||
return cls.right(name, parent, | ||
thickness, | ||
local=local) | ||
else: | ||
# Intersection of different types of subdimension or two middle | ||
# will always be middle | ||
width = parent.symbolic_max - parent.symbolic_min + 1 | ||
|
||
def get_left_thickness(sdim): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. define as instance attribute outside, and then just |
||
if sdim.is_left: | ||
return 0 | ||
elif sdim.is_right: | ||
return width - sdim.thickness.right[1] | ||
else: | ||
return sdim.thickness.left[1] | ||
|
||
def get_right_thickness(sdim): | ||
if sdim.is_left: | ||
return width - sdim.thickness.left[1] | ||
elif sdim.is_right: | ||
return 0 | ||
else: | ||
return sdim.thickness.right[1] | ||
|
||
thickness_left = sympy.Max(*[get_left_thickness(sdim) | ||
for sdim in sdims]) | ||
thickness_right = sympy.Max(*[get_right_thickness(sdim) | ||
for sdim in sdims]) | ||
return cls.middle(name, parent, | ||
thickness_left, | ||
thickness_right, | ||
local=local) | ||
|
||
@cached_property | ||
def symbolic_min(self): | ||
return self._interval.left | ||
|
There was a problem hiding this comment.
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 asset().intersectio
notSet.intersection
.There was a problem hiding this comment.
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
SubDimension
s, so it would want to beintersect(subdimensions)
rather thanintersect(self, other)
imoThere was a problem hiding this comment.
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 methodThere was a problem hiding this comment.
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