Repository navigation
Conversation
eriknw
force-pushed
the
49-masked-literal-assign
branch
from
October 19, 2026 07:55
5fb311d to
1033bd9
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 19-scalar-fast-paths #648 +/- ##
=======================================================
Coverage ? 98.63%
=======================================================
Files ? 106
Lines ? 31397
Branches ? 3636
=======================================================
Hits ? 30968
Misses ? 278
Partials ? 151 🚀 New features to boost your workflow:
|
eriknw
force-pushed
the
49-masked-literal-assign
branch
from
October 20, 2026 22:28
1033bd9 to
246c091
Compare
eriknw
force-pushed
the
49-masked-literal-assign
branch
from
October 21, 2026 04:14
246c091 to
0d6cb67
Compare
eriknw
force-pushed
the
49-masked-literal-assign
branch
from
October 21, 2026 08:38
0d6cb67 to
0ab03f4
Compare
eriknw
force-pushed
the
49-masked-literal-assign
branch
from
October 28, 2026 04:29
0ab03f4 to
3451a70
Compare
eriknw
force-pushed
the
49-masked-literal-assign
branch
from
October 28, 2026 13:21
3451a70 to
6e58775
Compare
w(mask, replace) << x with a Python bool, int or float x goes through
_update, a second Updater, an index resolver for `...`, a Scalar built
from x and _prep_for_assign before it reaches GrB_Vector_assign_<T> (or
GrB_Matrix_assign_<T>) over all indices. That is about 7 us of Python
for a call SuiteSparse finishes in about 0.5 us, and level-synchronous
traversals make it once per level: graphblas-algorithms marks each BFS
level visited with seen(q.S) << True.
Make that call directly when nothing needs the full path: x of type
bool, int (within INT64) or float, a non-UDT target, no accum, no opts,
no input_mask, a Mask (structural or value, complemented or not) of an
object of the target's own type and shape, or no mask without replace,
and no active Recorder. x takes the dtype the full path gives its
Scalar, and GraphBLAS casts it as before. Everything else, including
masks the full path converts or rejects, ints beyond INT64 and numpy
scalars, takes the full path unchanged.
Measured with no test suite running (load average about 5.3 from other
work), mlx, SuiteSparse 10.5.0, best of 5, two rounds each:
seen(q.S) << True, 10000-element Vector 7.7 us -> 2.3 to 2.4 us
bfs_edges, 10k-node road ball, 134 levels 5.1 ms -> 4.2 to 4.3 ms
bfs_edges, 50k-node road ball, 352 levels 16.5 to 16.9 ms -> 14.7 to 14.9 ms
with the same edges. The tests compare the fast path with the full path
(forced by an active Recorder) over 7 dtypes, 9 values (bool, 0, -1,
300, 2**40, 1.5, -0.0, nan), 5 mask kinds and replace for Vector, and a
smaller grid for Matrix, plus the errors of a wrong-kind or wrong-size
mask and an int beyond INT64. Breaking the fast path's replace,
complement, structure or value each fails between 216 and 423 cases.
_assign_literal imported lookup_dtype on every call. base.py can import it at module level (literals.py, which base.py imports, already does), and the import was about a sixth of what the fast path still costs: seen(q.S) << True on a 10000-element Vector, best of 5, goes from 2.28 us to 1.9 us (the GrB_Vector_assign_BOOL call itself is 0.42 us).
…ull path does _assign_literal checks the status of GrB_*_assign_<T> itself, and no test reached that check, since Python validates the mask and value first. A Vector whose data was exported with give_ownership=True has no GraphBLAS object left, so the assign fails: both the fast path and the full path (forced by a Recorder) raise NullPointer.
eriknw
force-pushed
the
49-masked-literal-assign
branch
from
October 29, 2026 02:01
6e58775 to
df34b4c
Compare
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.
w(mask, replace) << xwith x an exact-type Python bool, int (within INT64) orfloat now makes one GrB_*assign call over all indices instead of building
the general update. A UDT target, accum, opts, input_mask, any mask the full
path would convert or reject, and an active Recorder take the full path.
Level-synchronous traversals (BFS) pay this once per level:
seen(q.S) << Truegoes from 6.98 to 1.9 us (best of 5), and bfs_edges on a10k-node road ball from 5.1 to 4.25 ms (measured in graphblas-algorithms).
Two commits: the fast path, and importing
lookup_dtypeonce at module level(the per-call import cost 0.4 us of the 2.3).
Parity: 113,653 generated cases plus 34 edge cases compare the fast path with
the full path (forced by a Recorder): every built-in dtype including complex,
values including 300, 240, 263, 2**64 - 1, -0.0 and nan, every mask kind
and replace, Vector and both Matrix orders, wrong-size and wrong-kind masks,
UDT masks and targets, accum and opts; result, sign of zero, iso flag,
warnings, exception type and message all match, on both backends, without
numba and with C scalars.