-
Notifications
You must be signed in to change notification settings - Fork 2
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(ir): add abstract ir data class and nodes #393
Conversation
d6f4e05
to
649cae7
Compare
def __init__(self, hidden_names: set[str]): | ||
self._hidden_names = hidden_names | ||
|
||
def __get__(self, instance, owner): |
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.
Add commentary that owner is necessary for python API and link to python docs for descriptor
def __get__(self, instance, owner): | ||
return _HidingDict(self._hidden_names, instance.data) | ||
|
||
def __set__(self, instance, value): |
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.
add type hints for instance and value. potential liskov violation. Prefer raising an error
self.data = data | ||
self._hidden_names = set(hidden_names) | ||
|
||
def __setitem__(self, key, value): |
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.
Add typehint hashable
def _is_hidden(self, name: str) -> bool: | ||
return name in self._hidden_names | ||
|
||
def __delitem__(self, key): |
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.
See above
del self.data[key] | ||
|
||
def __iter__(self): | ||
return filterfalse(self._is_hidden, iter(self.data)) |
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.
Make this clearer
for k in args: | ||
if k in set_transforms: | ||
args[k] = set_transforms[k](args[k]) | ||
return args |
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.
Either remove return value and add comment for inplace operation or explicitly save the args in line 83 (__turn_arguments_into_data_dict)
for k in args: | ||
if k in set_transforms: | ||
args[k] = set_transforms[k](args[k]) | ||
return args |
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.
Either remove return value and add comment for inplace operation or explicitly save the value in __turn_arguments_into_data_dict
return kwargs | ||
|
||
@classmethod | ||
def __transform_args_with_mandatory_fields( |
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.
Either
from .attribute import AttributeT | ||
|
||
|
||
class Node(AbstractIRData): |
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.
Maybe split mandatory fields class in transformable mandatory fields and mandatory fields
elasticai/creator/ir/node_test.py
Outdated
return cls._do_new(*args, **kwargs) | ||
|
||
n = NewNode.new(name="my_name", type="my_type", input_shape=3) | ||
assert n.input_shape == (3, 1) |
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.
Maybe add a test similar to set_transform for get_transform?
44d9d2e
to
88e0ca9
Compare
The purpose of this class is to provide a way to easily write new wrappers around dictionaries, that let us customize access, while still supporting static type annotations.
88e0ca9
to
bb81f0d
Compare
The purpose of this class is to provide a way to
easily write new wrappers around dictionaries,
that let us customize access, while still
supporting static type annotations.