Skip to content

Support numpy operators on GraphArrayView#317

Merged
JoOkuma merged 1 commit into
royerlab:mainfrom
JoOkuma:fix-gav-numpy-operators
Jul 1, 2026
Merged

Support numpy operators on GraphArrayView#317
JoOkuma merged 1 commit into
royerlab:mainfrom
JoOkuma:fix-gav-numpy-operators

Conversation

@JoOkuma

@JoOkuma JoOkuma commented Jul 1, 2026

Copy link
Copy Markdown
Member

Operations between a GraphArrayView and numpy arrays/scalars didn't cast the view to its array content: view[t] == 0 silently returned Python's identity False, and view[t] + 1 / view[t] > 0 raised TypeError.

BaseReadOnlyArray now inherits NDArrayOperatorsMixin and implements __array_ufunc__, materializing read-only operands before delegating to the ufunc. out= is rejected (read-only) and identity hashing is preserved.

Added a test covering comparisons and arithmetic with arrays, scalars, and other views, e.g. array_view[t] == np.zeros(frame_shape).

Operations between a GraphArrayView and numpy arrays or scalars did not
cast the view to its array content: 'view[t] == 0' silently returned
Python's identity False, and 'view[t] + 1' / 'view[t] > 0' raised
TypeError. Array operands only worked through numpy's reflected ops.

Make BaseReadOnlyArray inherit NDArrayOperatorsMixin and implement
__array_ufunc__, materializing read-only array operands before
delegating to the ufunc. 'out=' is rejected (read-only) and identity
hashing is kept (the mixin's __eq__ would otherwise disable it,
breaking signal connections).
@JoOkuma JoOkuma merged commit d83d03b into royerlab:main Jul 1, 2026
7 checks passed
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