feature: ragged.sort and ragged.argsort #48
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I thought, "The ragged library is the most straightforward project we have, proceeding from a specification, statically typed everything, and pre-populated docstrings. If the the Glorified Autocomplete is good at anything, it should be good at filling in these
NotImplementedError("TODO")
stubs, right?"Well... even with a context window full of the already-implemented functions, it wrote
for
argsort
andfor
sort
.What's with the Fortran (
'F'
) and C-contiguous ('C'
) ordering? That's for memory layout, and none of the other functions have that. The confusion between "order" and "sorting" makes sense in the context of natural language, but they don't have anything to do with each other here. (Actually, NumPy sorting functions have anorder
, which refers to fields in a structured array—not memory-contiguousness!)I probably should have given it Awkward's
argsort
andsort
docstrings. It guessed the wrong interface.Maybe it was natural to branch and do both Awkward and NumPy implementations, but in ragged, the alternative of an Awkward Array is a NumPy or CuPy scalar, which doesn't make sense to sort.
Finally, it's true that NumPy doesn't have a
descending
flag. (ChatGPT must have known that from its training dataset. It's the sort of thing people would warn each other about on StackOverflow.) But it only seemed to know that on the second of two functions.Okay: coding (in the most straightforward instance I can find) is a bust. What about writing tests?
On the first two, the the
expected_sorted
has a different depth of nesting than thedata
, so it couldn't possibly be right. But maybe the problem is that the inputs and expected outputs are all written in aparametrize
decorator—do people actually do that? I find that it helps to have inputs and expected outputs near each other, clearly lined up, and if they're separate arguments to theparametrize
decorator, they can't be lined up.Speaking of which,
Really? You needed the explanation, instead of letting the assertion stand on its own? I suspect that this sort of thing comes from bad practices in the wild:
The third test looks right, but why not test the options in all tests? And how about different
axis
values? (I gave ChatGPT the statically typed, docstringed implementation of the functions it was supposed to test.)All in all, it's a bust. But it's funny to be complaining about LLMs not being able to write code for me when I was so blown away by them being able to produce anything meaningful just 10 years ago, in The Unreasonable Effectiveness of Recurrent Neural Networks. I suppose I'm spoiled.