Fix argmin/argmax to return the forward (ravel) index#29
Merged
Conversation
The Hoon reference returns `+:(find ~[min/max] (ravel a))` — the forward index into the row-major ravel. ravel is `(snip (rip bloq data))`, i.e. least-significant element first, and the C jet reads the byte buffer least-significant first too, so x_bytes[i] == ravel[i]. But the jet stored `len_x - i - 1`, the reversed index, contradicting its own Hoon spec for any non-symmetric array. Store the forward index `i` instead, in argmin and argmax across all three jet files. Also widen the index from c3_w (32-bit) to c3_d, since it is assigned from a c3_d loop counter and passed to u3i_chub (truncation would only bite arrays above 2^32 elements, but the type is now correct). Add a property-based regression test: the element at the argmin/argmax index must equal the min/max value. Reasoned from source (ravel/rip ordering); should be confirmed against the Hoon reference in a Vere build. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Collaborator
Author
|
Replica of #22 fix. |
Closed
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.
Summary
The Hoon reference returns
+:(find ~[(get-item (min a) ...)] (ravel a))— the forward index into the row-major ravel.ravelis(snip (rip bloq data))(least-significant element first), and the C jet reads its byte buffer least-significant-first too, sox_bytes[i] == ravel[i]. But the jet storedmin_idx = len_x - i - 1(and likewisemax_idx), the reversed index — contradicting its own Hoon spec for any non-symmetric array.Fix
iinargmin/argmax, all four precisions, across the three jet files.c3_w(32-bit) toc3_d: it is assigned from ac3_dloop counter and passed tou3i_chub, so the 32-bit type was a latent truncation for arrays above 2³² elements.Strict
</>comparisons mean the first occurrence wins, matching Hoon'sfindtie-handling.Test
Added a property-based regression test that is robust to baum-ordering assumptions: the element fetched at the
argmin/argmaxindex must equal themin/maxvalue. A reversed index fetches the wrong element for the non-symmetric array[3,1,4,2].Note
This is reasoned from the
ravel/ripordering in source (I can't run Urbit here). It should be confirmed against the Hoon reference in a Vere build — the regression test will validate it there.🤖 Generated with Claude Code