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

Comparison operators for PwAff #115

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Comparison operators for PwAff #115

wants to merge 1 commit into from

Conversation

isuruf
Copy link
Contributor

@isuruf isuruf commented Sep 11, 2023

No description provided.

:return: self <= other
"""
if isinstance(other, int):
return self.le_set(self * 0 + other)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There must be a better way to do this.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    zero = Aff.zero_on_domain(LocalSpace.from_space(space))
    result[0] = PwAff.from_aff(zero)

Comment on lines +734 to +737
PwAff.__le__ = pw_le
PwAff.__lt__ = pw_lt
PwAff.__ge__ = pw_ge
PwAff.__gt__ = pw_gt
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One issue with this is that it can't extend to == and !=. I wonder whether that invalidates the idea...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. This is a problem for eg: SymPy where == and != are structural equivalence and Eq gives an expression. Numpy however is consistent and implements == and != and returns a numpy array of bools.

PwAff.__lt__ = pw_lt
PwAff.__ge__ = pw_ge
PwAff.__gt__ = pw_gt
PwAff.__bool__ = pw_bool
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to override __bool__ on Set.

:return: self <= other
"""
if isinstance(other, int):
return self.le_set(self * 0 + other)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    zero = Aff.zero_on_domain(LocalSpace.from_space(space))
    result[0] = PwAff.from_aff(zero)

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.

None yet

2 participants