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

Make empty interval comparable by reference #4

Closed
justas- opened this issue Sep 6, 2018 · 6 comments
Closed

Make empty interval comparable by reference #4

justas- opened this issue Sep 6, 2018 · 6 comments

Comments

@justas-
Copy link

justas- commented Sep 6, 2018

As it is now we have to instantiate I.empty() to compare if the interval is empty:

i1 = I.empty()
i1 == I.empty()
True
i1 is I.empty()
False

In certain applications this can have a significant performance impact. Would it be possible to have a singleton for an empty interval, which would allow checking using "is" operator?

@AlexandreDecan
Copy link
Owner

It's quite unusual in Python to use identity operator (is) to support this kind of use case; e.g. with lists:

>>> m = []
>>> m is []
False

Why not use i1.is_empty() in your case?

@justas-
Copy link
Author

justas- commented Sep 6, 2018

Good point! I did not know about is_empty() and got used to using sympy's singleton EmptyInterval.

@AlexandreDecan
Copy link
Owner

I hope is_empty() will do the job performances-wise ;-)

I would be very interested to get your feedback on how python-intervals' performances are in practice. My use cases usually do not exceed tens of intervals, so I don't know if there are bottlenecks.

@justas-
Copy link
Author

justas- commented Sep 7, 2018

My use case involves simulation with a lot of time intervals. For each set of simulation parameters I calculate ~12 time intervals. Then I check if all of them are valid. If they are - then I calculate one intersection of them all and check again if it is valid (not empty). Compared to sympy I see ~30x improvement using python-intervals.

@AlexandreDecan
Copy link
Owner

Thank you! That's a good news ;-)

@AlexandreDecan
Copy link
Owner

I know this issue is quite old and a "workaround" has been found, but since 1.8.0, I.empty() always returns the same instance, so comparing some_interval == I.empty() should be nearly as fast than some_interval.is_empty(). Notice that is operator is still not supported (because not all empty intervals are created using I.empty(), so we cannot ensure that their id(...)'s will be the same!)

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

No branches or pull requests

2 participants