-
Notifications
You must be signed in to change notification settings - Fork 3
Rework enum #8
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
Rework enum #8
Conversation
6d46ff3 to
39a4a52
Compare
rabah-khalek
left a comment
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.
Great work @Hartorn, quite an improvement and I particularly like the operators extension to the names.
I left some comments for the future, particularly the direction of using https://numpy.org/doc/stable/reference/maskedarray.generic.html to define a new "marks" class that already support masks (our facial_parts) with all the native ops and validations numpy.ma has.
| class FacialPart(NDArrayOperatorsMixin): | ||
| part: np.ndarray | ||
| name: str = "" | ||
|
|
||
| def __add__(self, o): | ||
| return FacialPart(np.unique(np.concatenate((self.part, o.part)))) | ||
|
|
||
| def __sub__(self, o): | ||
| return FacialPart(np.setxor1d(self.part, np.intersect1d(self.part, o.part))) | ||
|
|
||
| def __array__(self): | ||
| return self.part |
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.
Inheriting from NDArrayOperatorsMixin and having __array__ would avoid us having crop_mark
| def crop_mark(mark: np.ndarray, part: FacialPart, exclude=False): | ||
| idx = np.isin(FacialParts.entire, part) | ||
| if not exclude: | ||
| idx = ~idx | ||
| part = ~part | ||
| res = mark.copy() | ||
| res[idx, :] = np.nan | ||
| res[part.idx, :] = np.nan | ||
| return res |
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.
Reflecting on all this, I think https://numpy.org/doc/stable/reference/maskedarray.generic.html could be the most suited for our case.
No description provided.