Commit c3b3a8d
committed
Fix type instability for
Fixes #525
The issue was that when `end` is used for the last dimension, `lastindex(VA, d)`
returns `RaggedEnd(0, lastindex(VA.u))` as a sentinel for an already-resolved index.
However, the `getindex` dispatch path couldn't infer the return type because
`cols.dim == 0` is a runtime check.
This PR adds:
1. A specialized `getindex(A, i::Int, re::RaggedEnd)` method that handles the
common case `vec[i, end]` directly with type stability
2. A helper function `_ragged_getindex_int_col` as a function barrier for the
Int column case
3. An early check in `_ragged_getindex` for the `RaggedEnd` sentinel case
The fix ensures that `@code_warntype` shows the proper return type (Float64)
instead of Any.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>vec[1, end] indexing1 parent 6519ecf commit c3b3a8d
2 files changed
+39
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
564 | 564 | | |
565 | 565 | | |
566 | 566 | | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
567 | 583 | | |
568 | 584 | | |
569 | 585 | | |
| |||
767 | 783 | | |
768 | 784 | | |
769 | 785 | | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
770 | 798 | | |
771 | 799 | | |
772 | 800 | | |
| |||
842 | 870 | | |
843 | 871 | | |
844 | 872 | | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
845 | 877 | | |
846 | | - | |
847 | | - | |
848 | | - | |
849 | | - | |
850 | | - | |
851 | | - | |
852 | | - | |
| 878 | + | |
853 | 879 | | |
854 | 880 | | |
855 | 881 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
69 | 75 | | |
70 | 76 | | |
71 | 77 | | |
| |||
0 commit comments