GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add a fast path for assigning a Python scalar under a mask by eriknw · Pull Request #648 · python-graphblas/python-graphblas

Conversation

@eriknw

@eriknw eriknw commented Oct 19, 2026

Copy link
Copy Markdown
Member

w(mask, replace) << x with x an exact-type Python bool, int (within INT64) or
float 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) << True goes from 6.98 to 1.9 us (best of 5), and bfs_edges on a
10k-node road ball from 5.1 to 4.25 ms (measured in graphblas-algorithms).

Two commits: the fast path, and importing lookup_dtype once 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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@eriknw
eriknw added this pull request to stack #650 October 19, 2026 07:50
@eriknw
eriknw force-pushed the 49-masked-literal-assign branch from 5fb311d to 1033bd9 Compare October 19, 2026 07:55
@codecov

codecov Bot commented Oct 19, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.95%. Comparing base (2a808fd) to head (aa6edb1).

Additional details and impacted files
@@                    Coverage Diff                     @@
##           46-networkx-udt-dtype     #648       +/-   ##
==========================================================
+ Coverage                  85.74%   98.95%   +13.20%     
==========================================================
  Files                        106      106               
  Lines                      32961    33042       +81     
  Branches                    3835     3841        +6     
==========================================================
+ Hits                       28262    32696     +4434     
+ Misses                      4387      212     -4175     
+ Partials                     312      134      -178     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@eriknw
eriknw force-pushed the 49-masked-literal-assign branch from 1033bd9 to 246c091 Compare October 20, 2026 22:28
@eriknw
eriknw force-pushed the 49-masked-literal-assign branch from 246c091 to 0d6cb67 Compare October 21, 2026 04:14
@eriknw
eriknw force-pushed the 49-masked-literal-assign branch from 0d6cb67 to 0ab03f4 Compare October 21, 2026 08:38
@eriknw
eriknw removed this pull request from stack #650 October 28, 2026 04:29
@eriknw
eriknw force-pushed the 49-masked-literal-assign branch from 0ab03f4 to 3451a70 Compare October 28, 2026 04:29
@eriknw
eriknw added this pull request to stack #653 October 28, 2026 04:30
@eriknw
eriknw removed this pull request from stack #653 October 28, 2026 04:31
@eriknw
eriknw added this pull request to stack #655 October 28, 2026 04:32
@eriknw
eriknw removed this pull request from stack #655 October 28, 2026 04:33
@eriknw
eriknw added this pull request to stack #657 October 28, 2026 04:33
@eriknw
eriknw force-pushed the 49-masked-literal-assign branch from 3451a70 to 6e58775 Compare October 28, 2026 13:21
@eriknw
eriknw force-pushed the 49-masked-literal-assign branch 2 times, most recently from df34b4c to 9c2dcb5 Compare November 3, 2026 05:53
@eriknw
eriknw force-pushed the 49-masked-literal-assign branch 2 times, most recently from 2550c0f to 39fb630 Compare November 3, 2026 16:44
@eriknw
eriknw removed this pull request from stack #657 November 3, 2026 16:44
@eriknw
eriknw added this pull request to stack #660 November 3, 2026 16:45
@eriknw
eriknw force-pushed the 49-masked-literal-assign branch from 39fb630 to 9c87a16 Compare November 3, 2026 20:07
@eriknw
eriknw force-pushed the 49-masked-literal-assign branch 2 times, most recently from 0cfd4f0 to 963d5f9 Compare November 10, 2026 16:47
@eriknw
eriknw force-pushed the 49-masked-literal-assign branch 15 times, most recently from ac44754 to f6b392d Compare November 11, 2026 05:42
@eriknw
eriknw removed this pull request from stack #666 November 12, 2026 06:13
@eriknw
eriknw changed the base branch from 19-scalar-fast-paths to main November 12, 2026 06:14
@eriknw
eriknw force-pushed the 49-masked-literal-assign branch from f6b392d to da7dbe7 Compare November 12, 2026 06:15
@eriknw
eriknw changed the base branch from main to 46-networkx-udt-dtype November 12, 2026 06:16
@eriknw
eriknw added this pull request to stack #670 November 12, 2026 06:17
@eriknw eriknw mentioned this pull request Nov 12, 2026
Add indexunary helpers, break per-call agg import, document from_string #604
Open
@eriknw
eriknw force-pushed the 49-masked-literal-assign branch 2 times, most recently from 4ea98df to aa6edb1 Compare November 12, 2026 17:36
eriknw added 3 commits November 12, 2026 14:32
@eriknw
Add a fast path for assigning a Python scalar under a mask
5436432
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.
@eriknw
Import lookup_dtype once for the masked literal assign
cd535ac
_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).
@eriknw
Test that the masked literal assign raises a GraphBLAS error as the f…
4d26728
…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
eriknw force-pushed the 49-masked-literal-assign branch from aa6edb1 to 4d26728 Compare November 12, 2026 20:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@eriknw
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.