Skip to content

Make any/all rank-agnostic via the reduced ray's ravel head#34

Merged
sigilante merged 1 commit into
mainfrom
sigilante/any-all-rank-agnostic
May 30, 2026
Merged

Make any/all rank-agnostic via the reduced ray's ravel head#34
sigilante merged 1 commit into
mainfrom
sigilante/any-all-rank-agnostic

Conversation

@sigilante
Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #28/#33. The any/all reductions indexed min/max's scalar result with a zero index sized to the input rank:

?!(=((get-item (max a) (reap (lent shape.meta.a) 0)) 0))

That matches the Hoon min/max (which preserve rank via scalar-to-ray), but the min/max jets return a rank-2 scalar even for a 1-D input — so any/all crash on a plain vector under the jets. Verified on a live ship (~nec, old jets): a 1-D input bails in get-item-number, a 2-D input passes. The existing test was 2-D only, which is exactly what hid the assumption.

Fix

Read the reduced scalar as the head of its ravel, which flattens the data directly and is independent of min/max's output shape:

++  any  |=(a=ray ?!(=(-:(ravel (max a)) 0)))
++  all  |=(a=ray ?!(=(-:(ravel (min a)) 0)))

Works for any rank; also drops the reap/dex plumbing.

Validation

Ran on ~nec against base's min/max: the -:(ravel ...) form passes for both 1-D and 2-D all-true / mixed / all-false rays. Added a 1-D any/all test to the suite alongside the existing 2-D one.

🤖 Generated with Claude Code

The prior any/all indexed min/max's scalar result with a zero index
sized to the *input* rank: ?!(=((get-item (max a) (reap (lent shape) 0))
0)). That matches the Hoon min/max (which preserve rank via
scalar-to-ray), but the min/max jets return a rank-2 scalar even for a
1-D input, so any/all crash on a plain vector under the jets (verified
on a live ship: 1-D input bails in get-item-number, 2-D passes).

Read the reduced scalar as the head of its ravel instead:
  any = ?!(=(-:(ravel (max a)) 0))
  all = ?!(=(-:(ravel (min a)) 0))
ravel flattens the data directly, so this is independent of min/max's
output shape and works for any rank. Validated on a live ship for both
1-D and 2-D. Add a 1-D any/all test (the existing test was 2-D only,
which is exactly what hid the rank assumption).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@sigilante sigilante merged commit bd57294 into main May 30, 2026
@sigilante sigilante deleted the sigilante/any-all-rank-agnostic branch May 30, 2026 16:13
sigilante added a commit that referenced this pull request May 30, 2026
Regroup the suite from arity-based (single-args / double-args-elementwise
+ array-utils) to operation-category files: arithmetic, compare-reduce,
builders, rounding, linalg, unary, indexing. lagoon-fails and
lagoon-unsigned are unchanged.

Pure mechanical move: arm bodies are byte-identical and every new file
gets the same canonical preamble (the is-equal/is-close helpers and
^| |_ [atol rtol] that all three sources already shared). Done with a
script that asserts arm-count conservation and errors on any unrouted
arm; one category (indexing) was built and run on a live ship to confirm
the new structure compiles. Arm count conserved exactly (983 before and
after, including the test-any-all-1d added by #34).

File-reorg pass only; de-duplicating the cartesian-product arms is a
follow-up.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant