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

feat(ir): add abstract ir data class and nodes #393

Merged
merged 2 commits into from
Nov 26, 2024

Conversation

glencoe
Copy link
Contributor

@glencoe glencoe commented Nov 19, 2024

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.

@glencoe glencoe marked this pull request as draft November 19, 2024 10:33
@glencoe glencoe force-pushed the 390-add-node-data-structure branch 2 times, most recently from d6f4e05 to 649cae7 Compare November 21, 2024 15:19
@glencoe glencoe self-assigned this Nov 21, 2024
@glencoe glencoe marked this pull request as ready for review November 21, 2024 15:24
@glencoe glencoe requested review from LeoBuron and mokouMonday and removed request for mokouMonday and LeoBuron November 26, 2024 08:47
def __init__(self, hidden_names: set[str]):
self._hidden_names = hidden_names

def __get__(self, instance, owner):
Copy link
Member

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):
Copy link
Member

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):
Copy link
Member

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):
Copy link
Member

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))
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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(
Copy link
Member

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):
Copy link
Member

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

return cls._do_new(*args, **kwargs)

n = NewNode.new(name="my_name", type="my_type", input_shape=3)
assert n.input_shape == (3, 1)
Copy link
Member

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?

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.
@LeoBuron LeoBuron merged commit e95aab7 into develop Nov 26, 2024
2 checks passed
@LeoBuron LeoBuron deleted the 390-add-node-data-structure branch November 26, 2024 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants