Skip to content

This recipe for smetric is the fastest #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 30, 2022
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
6 changes: 4 additions & 2 deletions graphblas_algorithms/algorithms/smetric.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from graphblas import binary

__all__ = ["s_metric"]


Expand All @@ -6,7 +8,7 @@ def s_metric(G):
degrees = G.get_property("total_degrees+")
else:
degrees = G.get_property("degrees+")
return (binary.first(degrees & G._A) @ degrees).reduce().get(0) / 2
# Alternatives
# return (degrees @ binary.second(G._A & degrees)).reduce().get(0) / 2
# return (binary.first(degrees & G._A) @ degrees).reduce().get(0) / 2
return degrees.outer(degrees).new(mask=G._A.S).reduce_scalar().get(0) / 2
# return degrees.outer(degrees).new(mask=G._A.S).reduce_scalar().get(0) / 2
7 changes: 3 additions & 4 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ exclude =
graphblas_algorithms/*/tests/,
graphblas_algorithms/*/*/tests/,
build/
ignore =
E203, # whitespace before ':'
E231, # Multiple spaces around ","
W503, # line break before binary operator
extend-ignore =
E203,
# E203 whitespace before ':' (to be compatible with black)
per-file-ignores =
__init__.py:F401,F403, # allow unused and star imports
test_*.py:F401,F403,
Expand Down