-
Notifications
You must be signed in to change notification settings - Fork 85
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
Support for negative ranges #515
Comments
@harry-clarke indeed it is not supported, we only test use cases with positive indexes. |
Funnily, it's just because I've been making my way through the Advent of Code challenges, and I wanted a RangeSet for intersecting rows and columns with shapes. In its simplest form, I want to do: RangeSet(range(-5,7)) - RangeSet(range(1,3)) |
At least for now, can we provide a I don't mind creating a PR Ideally, it would be good to remove the dependency on string parsing for interpreting ranges, which should reduce complexity a bit. |
I checked and it is an unexpected change (or "regression") between 1.8.x and 1.9. In 1.9, we actually changed the way the inner set handles indices: we now rely on strings instead of integers. This allows With 1.8.4:
With 1.9:
For now, you could use 1.8.4, but I will see if we can restore functionality in 1.9.x and officially support negative ranges. I will post updates in this ticket. Thanks for the report! |
Support negative ranges in RangeSet, with as little impact as possible to the normal (positive range) codepath. Zero padding is not available with negative ranges at this time for this reason. In case of negative ranges, RangeSet will case the numbers to integer. Internal sorting then looks like this (eg. -5-6): ['-5', '-4', '-3', '-2', '-1', '0', '1', '2', '3', '4', '5', '6'] Apart from the internal sorting change, little modifications are needed in the parser and the folding method, so I guess it's worth it. Usage examples: >>> RangeSet(range(-5,7)) - RangeSet(range(1,3)) -5-0,3-6 >>> list((RangeSet(range(-5,7)) - RangeSet(range(1,3))).intiter()) [-5, -4, -3, -2, -1, 0, 3, 4, 5, 6] >>> list((RangeSet(range(-5,7)) - RangeSet(range(1,3))).contiguous()) [-5-0, 3-6] Hence, the following is now possible: $ cluset -f foo[-10-10] foo[-10-10] $ cluset -f foo[-100--90/2] foo[-100,-98,-96,-94,-92,-90] Closes cea-hpc#515.
Support negative ranges in RangeSet, with as little impact as possible to the normal (positive range) codepath. Zero padding is not available with negative ranges at this time for this reason. In case of negative ranges, RangeSet will case the numbers to integer. Internal sorting then looks like this (eg. -5-6): ['-5', '-4', '-3', '-2', '-1', '0', '1', '2', '3', '4', '5', '6'] Apart from the internal sorting change, little modifications are needed in the parser and the folding method, so I guess it's worth it. Usage examples: >>> RangeSet(range(-5,7)) - RangeSet(range(1,3)) -5-0,3-6 >>> list((RangeSet(range(-5,7)) - RangeSet(range(1,3))).intiter()) [-5, -4, -3, -2, -1, 0, 3, 4, 5, 6] >>> list((RangeSet(range(-5,7)) - RangeSet(range(1,3))).contiguous()) [-5-0, 3-6] Hence, the following is now possible: $ cluset -f foo[-10-10] foo[-10-10] $ cluset -f foo[-100--90/2] foo[-100,-98,-96,-94,-92,-90] Closes #515.
Hey there,
Am I missing something here?
Negative ranges don't seem to be supported, it seems in part due to string formatting issues (
-1-1
confuses the parser)Is there support for negative ranges, and if not, would others find this a useful addition?
The text was updated successfully, but these errors were encountered: