-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
[stdlib] Use Intable
in getitem
and setitem
consistently
#2337
Comments
The python community already solved this issue of floating points :) See the This is what is called internally when doing Maybe it would be worth it to create a Some real world examples: |
I'd like to work on this if it's still available! |
@bgreni I don't think you need to ask permission to work on an issue. It's quite uncommon for two contributors to work on the same thing. If you don't see a PR open, it's likely that no one is working on it :) |
[External] [stdlib] Add Indexer trait First half of the split off from #2384. Partially addresses #2337 Introduces the `Indexer` trait and applies to `Int`, `IntLiteral`, `Bool`, and integral scalar `SIMD` types. --------- Co-authored-by: bgreni <42788181+bgreni@users.noreply.github.com> Closes #2685 MODULAR_ORIG_COMMIT_REV_ID: 224c700e9ff9b28abf9e7d72ff3b3271d7e9de09
[External] [stdlib] Add Indexer trait First half of the split off from modularml#2384. Partially addresses modularml#2337 Introduces the `Indexer` trait and applies to `Int`, `IntLiteral`, `Bool`, and integral scalar `SIMD` types. --------- Co-authored-by: bgreni <42788181+bgreni@users.noreply.github.com> Closes modularml#2685 MODULAR_ORIG_COMMIT_REV_ID: 224c700e9ff9b28abf9e7d72ff3b3271d7e9de09
[External] [stdlib] Add Indexer trait First half of the split off from modularml#2384. Partially addresses modularml#2337 Introduces the `Indexer` trait and applies to `Int`, `IntLiteral`, `Bool`, and integral scalar `SIMD` types. --------- Co-authored-by: bgreni <42788181+bgreni@users.noreply.github.com> Closes modularml#2685 MODULAR_ORIG_COMMIT_REV_ID: 224c700e9ff9b28abf9e7d72ff3b3271d7e9de09
[External] [stdlib] Add the `normalize_index` function This PR is some kind of mix between #2386 and #2384 which have issues (aborting) or have too many conflicts because the PR is too big. This PR solves part of #2251 and #2337 We try here to give the ground work for indexing correctly. This function added can then be used wherever we work with sequences. Two things I noticed during development: 1) The `debug_assert` does not run in unit tests. Is there any way to enable it? We currently have out-of-bounds bugs in our test suite. 2) The null terminator is causing pain, again, again, and again. Do we have any plans to make it optional when working with String? I opened #2678 to discuss this. To avoid to fix those issues in this PR, I used the `normalize_index` on the `__refitem__` of `InlineArray` which doesn't have widespread use yet and isn't impacted by out-of-bounds bugs. My recommendation would be to merge this PR then to rebase #2386 and #2384 on it. We should also afterwards fix the out of bounds bugs that can be triggered in the test suite by enabling debug_assert. The diff might seem big, but no worries, it's mostly the licenses and docstrings :) Co-authored-by: Gabriel de Marmiesse <gabriel.demarmiesse@datadoghq.com> Closes #2677 MODULAR_ORIG_COMMIT_REV_ID: 66e7121a6a333c16284eb33a89eb85c034c296c3
[External] [stdlib] Add Indexer trait First half of the split off from #2384. Partially addresses #2337 Introduces the `Indexer` trait and applies to `Int`, `IntLiteral`, `Bool`, and integral scalar `SIMD` types. --------- Co-authored-by: bgreni <42788181+bgreni@users.noreply.github.com> Closes #2685 MODULAR_ORIG_COMMIT_REV_ID: 224c700e9ff9b28abf9e7d72ff3b3271d7e9de09
[External] [stdlib] Add the `normalize_index` function This PR is some kind of mix between #2386 and #2384 which have issues (aborting) or have too many conflicts because the PR is too big. This PR solves part of #2251 and #2337 We try here to give the ground work for indexing correctly. This function added can then be used wherever we work with sequences. Two things I noticed during development: 1) The `debug_assert` does not run in unit tests. Is there any way to enable it? We currently have out-of-bounds bugs in our test suite. 2) The null terminator is causing pain, again, again, and again. Do we have any plans to make it optional when working with String? I opened #2678 to discuss this. To avoid to fix those issues in this PR, I used the `normalize_index` on the `__refitem__` of `InlineArray` which doesn't have widespread use yet and isn't impacted by out-of-bounds bugs. My recommendation would be to merge this PR then to rebase #2386 and #2384 on it. We should also afterwards fix the out of bounds bugs that can be triggered in the test suite by enabling debug_assert. The diff might seem big, but no worries, it's mostly the licenses and docstrings :) Co-authored-by: Gabriel de Marmiesse <gabriel.demarmiesse@datadoghq.com> Closes #2677 MODULAR_ORIG_COMMIT_REV_ID: 66e7121a6a333c16284eb33a89eb85c034c296c3
@JoeLoser I believe we turned around and now want everything to use Int consistently instead of Intable. Do you agree? If so, we should tidy up this issue to avoid confusion |
As mentioned at #2337 (comment), we've pivoted a bit and moved away from `Intable` for offsets in `__getitem__` implementations now that we have `Indexer`. Fix this last use of `__getitem__` that works on a `Intable` type to use `Int` explicitly. MODULAR_ORIG_COMMIT_REV_ID: 87e2eca61466072aa0e36741296cb1d8fbc0eaed
As mentioned at #2337 (comment), we've pivoted a bit and moved away from `Intable` for offsets in `__getitem__` implementations now that we have `Indexer`. Fix this last use of `__getitem__` that works on a `Intable` type to use `Int` explicitly. Do the same for `__setitem__` while we're here. MODULAR_ORIG_COMMIT_REV_ID: cf13a3daf2056b0eeffe879049f9e865a1595e94
As mentioned at modularml#2337 (comment), we've pivoted a bit and moved away from `Intable` for offsets in `__getitem__` implementations now that we have `Indexer`. Fix this last use of `__getitem__` that works on a `Intable` type to use `Int` explicitly. MODULAR_ORIG_COMMIT_REV_ID: 87e2eca61466072aa0e36741296cb1d8fbc0eaed Signed-off-by: martinvuyk <martin.vuyklop@gmail.com>
As mentioned at modularml#2337 (comment), we've pivoted a bit and moved away from `Intable` for offsets in `__getitem__` implementations now that we have `Indexer`. Fix this last use of `__getitem__` that works on a `Intable` type to use `Int` explicitly. Do the same for `__setitem__` while we're here. MODULAR_ORIG_COMMIT_REV_ID: cf13a3daf2056b0eeffe879049f9e865a1595e94 Signed-off-by: martinvuyk <martin.vuyklop@gmail.com>
As mentioned at #2337 (comment), we've pivoted a bit and moved away from `Intable` for offsets in `__getitem__` implementations now that we have `Indexer`. Fix this last use of `__getitem__` that works on a `Intable` type to use `Int` explicitly. MODULAR_ORIG_COMMIT_REV_ID: 87e2eca61466072aa0e36741296cb1d8fbc0eaed
As mentioned at #2337 (comment), we've pivoted a bit and moved away from `Intable` for offsets in `__getitem__` implementations now that we have `Indexer`. Fix this last use of `__getitem__` that works on a `Intable` type to use `Int` explicitly. Do the same for `__setitem__` while we're here. MODULAR_ORIG_COMMIT_REV_ID: cf13a3daf2056b0eeffe879049f9e865a1595e94
Many
__getitem__
and__setitem__
functions still take anInt
as an argument. This is OK, but forces call sites to explicitly construct anInt
viaint(my_value)
for example to call__getitem__
or__setitem__
. Instead, we can just make__getitem__
and__setitem__
take anIntable
thing that always does theint(value)
internally rather than pushing it onto all the callers.One thing to note is for floating point indices, like
x[0.1]
, this would erroneously callx[int(0.1)]
i.e.x[0]
. This is surprising and instead should be a hard error. But we can put that on hold and stage this in phases:__getitem__
and__setitem__
functions to work onIntable
and ignore the floating point indexing issue mentioned above.Integral
trait or something to ensure that callers can't pass a floating point value to these functions. Use that instead ofIntable
everywhere.Intable
in case they also have floating point indexing issues like mentioned above.FYI @itramble
The text was updated successfully, but these errors were encountered: