Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions graphblas/core/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2741,19 +2741,6 @@ def _initialize(cls):
# Builtin monoids that are idempotent; i.e., `op(x, x) == x` for any x
for name in ["any", "band", "bor", "land", "lor", "max", "min"]:
getattr(monoid, name)._is_idempotent = True
for name in [
"bitwise_and",
"bitwise_or",
"fmax",
"fmin",
"gcd",
"logical_and",
"logical_or",
"maximum",
"minimum",
]:
getattr(monoid.numpy, name)._is_idempotent = True

# Allow some functions to work on UDTs
any_ = monoid.any
any_._identity = 0
Expand Down
17 changes: 16 additions & 1 deletion graphblas/monoid/numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,19 @@
# _graphblas_to_numpy = {val: key for key, val in _numpy_to_graphblas.items()} # Soon...
# Not included: maximum, minimum, gcd, hypot, logaddexp, logaddexp2

# True if ``monoid(x, x) == x`` for any x.
_idempotent = {
"bitwise_and",
"bitwise_or",
"fmax",
"fmin",
"gcd",
"logical_and",
"logical_or",
"maximum",
"minimum",
}


def __dir__():
return globals().keys() | _delayed.keys() | _monoid_identities.keys()
Expand All @@ -163,5 +176,7 @@ def __getattr__(name):
from ..core import operator

func = getattr(_binary.numpy, name)
operator.Monoid.register_new(f"numpy.{name}", func, _monoid_identities[name])
operator.Monoid.register_new(
f"numpy.{name}", func, _monoid_identities[name], is_idempotent=name in _idempotent
)
return globals()[name]