fix: make topk() return numerically-keyed tuple for consistency - #30
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR changes
topk()from returning string-keyed arrays (['values' => ..., 'indices' => ...]) to numerically-keyed arrays ([$values, $indices]) to match the convention used by every other multi-NDArray return in the library.Motivation and Context
topk()was the only method returning a string-keyed tuple (['values' => NDArray, 'indices' => NDArray]). All other multi-NDArray returns —svd(),qr(),eig(),eigh(),lstsq(),split(),vsplit(),hsplit(),meshgrid()— use numerical positional keys. This inconsistency meant callers had to remember different destructuring patterns depending on the method. The new signature matches NumPy and PyTorch semantics where destructuring is natural:[$values, $indices] = $arr->topk(3).What's Changed
topk()and its private helpers (topkAxisOp,topkFlatOp) now return[NDArray, NDArray]instead of['values' => NDArray, 'indices' => NDArray]@returnannotations fromarray{values: NDArray, indices: NDArray}toarray{0: NDArray, 1: NDArray}$topk[0]/$topk[1]instead of$topk['values']/$topk['indices'])Breaking Changes
Yes. Anyone relying on
$result['values']or$result['indices']to access topk results will need to update to$result[0]/$result[1]or destructure with[$values, $indices] = $arr->topk(...).