Repository navigation
Compact sparse-vector broadcast output on the device - #795
Merged
Merged
Conversation
maleadt
added this pull request to stack #797
September 25, 2026 14:56
This was referenced Sep 25, 2026
maleadt
removed this pull request from stack #797
October 21, 2026 13:00
maleadt
added this pull request to stack #832
October 21, 2026 13:00
Broadcasting several sparse vectors sorted an array of Pairs on the host through scalar indexing to move the rows without output entries to the end, which takes seconds on back-ends whose sort cannot handle Pairs (Metal). The rows are already in order, so number the rows that have an output entry with a prefix sum instead, and let the broadcast kernel write each entry to its position. The first and last stored index were also read with scalar indexing to narrow the row range, which threw a BoundsError for vectors without stored entries and left the dense-output kernel reading past the end of the offsets. Process every row instead, and find each argument's entry by binary search rather than a linear scan.
maleadt
force-pushed
the
tb/sparse-vector-broadcast
branch
2 times, most recently
from
October 22, 2026 10:54
55a9018 to
6d1f474
Compare
maleadt
removed this pull request from stack #832
October 23, 2026 08:18
maleadt
marked this pull request as ready for review
October 23, 2026 13:05
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.
Broadcasting over several sparse vectors sorted an array of
Pairs with@allowscalar sort!(offsets; by=first)to move the rows without an output entry to the end. Back-ends whose device sort cannot handlePairs fall back to Base's algorithm through scalar indexing: on Metal,x .* yfor two 4096-element vectors at 10% density took 7.3 s.The rows are already in order, so this numbers the rows that have an output entry with a prefix sum (
accumulate!) and lets the broadcast kernel write each entry to its position. It also drops the scalar reads of the first and last stored index that narrowed the row range: they threw aBoundsErrorfor vectors without stored entries, and left the dense-output kernel reading past the end of the offsets. Every row is processed instead, and each argument's entry is found by binary search rather than a linear scan.Tests: vectors without stored entries (which failed before), and a 10⁴-element case with several sparse arguments.
This is independent of the sparse redesign in #745 (stacked above it) and can go into 11.x on its own.