Skip to content

Commit

Permalink
Improve import times (python-graphblas#419)
Browse files Browse the repository at this point in the history
  • Loading branch information
eriknw authored Mar 29, 2023
1 parent 41fb71a commit 0139a83
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
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]

0 comments on commit 0139a83

Please sign in to comment.