-
Notifications
You must be signed in to change notification settings - Fork 15
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
feat: Generalize edge type polymorphism. #170
feat: Generalize edge type polymorphism. #170
Conversation
Codecov ReportAttention: Patch coverage is
@@ Coverage Diff @@
## main #170 +/- ##
==========================================
+ Coverage 88.79% 88.81% +0.01%
==========================================
Files 61 61
Lines 15931 15964 +33
==========================================
+ Hits 14146 14178 +32
- Misses 1785 1786 +1
|
mithril/framework/common.py
Outdated
# ) | ||
def __post_init__(self) -> None: | ||
# Convert to generic Tensor type if Tensor type is provided. | ||
if self.type is Tensor: |
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.
could we remove post_init and handle Tensor in set_type
@@ -192,29 +189,36 @@ def edge_type_constraint( | |||
) -> ConstrainResultType: | |||
updates = Updates() | |||
status = False | |||
tensor_exists: bool = False | |||
tensor_output: bool = output.is_tensor | |||
for input in inputs: |
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.
Small thing, but I think we can do tensor_exists
check similar to status check in line 221.
tensor_exists = any(input.is_tensor for input in inputs)
# If no ToBeDetermined edge_type exists, return True. | ||
if ToBeDetermined not in input_edge_types: | ||
# If no polymorphic edge_type exists, return True. | ||
if all({not input.is_polymorphic for input in inputs}): |
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.
-
all
andany
supports comprehension directly. So we do not need to put it in aset
first -
Since we are setting status in there already, I think there is no need to setting status occasionally inside the function. It seems to me it would be correct if we return as follows:
return all(not input.is_polymorphic for input in inputs), updates
# if physical_data.edge_type not in (Tensor, ToBeDetermined): | ||
if not ( | ||
physical_data.is_tensor | ||
or physical_data.edge_type is ToBeDetermined |
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.
could this check be as follows?
if not physically_data.is_tensor or phsical_data.is_polymorphic
for s_types in (subtypes_1, subtypes_2): | ||
other_set = subtypes_2 if s_types == subtypes_1 else subtypes_1 | ||
for orig_type in (list, tuple, range): | ||
if orig_type in s_types: |
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.
Not critical but, instead of using
if orig_type in s_types:
if orig_type not in s_types:
continue
could be used, which will look better.
Description
Closes #168
User can define polymorphic type declarations other than ToBeDetermined like Tensor[int | float] | int | float.
What is Changed
Include the changes introduced in this PR.
Checklist: