Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Basic graph generation using hypothesis, compare outputs with NX#18

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
MridulS wants to merge2 commits intopython-graphblas:main
base:main
Choose a base branch
Loading
fromMridulS:hypo_test
Open
Show file tree
Hide file tree
Changes fromall 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
2 changes: 1 addition & 1 deletion.github/workflows/test.yml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -31,7 +31,7 @@ jobs:
- name: Install dependencies
run: |
conda install -c conda-forge python-graphblas scipy pandas \
pytest-cov pytest-randomly black flake8-comprehensions flake8-bugbear
pytest-cov pytest-randomly black flake8-comprehensions flake8-bugbear hypothesis
# matplotlib lxml pygraphviz pydot sympy # Extra networkx deps we don't need yet
pip install git+https://github.com/networkx/networkx.git@main --no-deps
pip install -e . --no-deps
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
import pytest
from hypothesis import given, settings

from graphblas_algorithms import pagerank
from graphblas_algorithms.utils import custom_graph_generators


@settings(deadline=None, max_examples=500)
@given(custom_graph_generators())
def test_pagerank_gen(graph):
assert pagerank(graph) == pytest.approx(nx.pagerank(graph))


from networkx.algorithms.link_analysis.tests.test_pagerank import * # isort:skip
19 changes: 19 additions & 0 deletionsgraphblas_algorithms/algorithms/tests/test_reciprocity.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
from graphblas_algorithms import overall_reciprocity, reciprocity
import pytest
from hypothesis import given, settings
from graphblas_algorithms.utils import custom_graph_generators


@settings(deadline=None, max_examples=500)
@given(custom_graph_generators())
def test_overall_reciprocity_gen(graph):
# TODO: Fix the graph gen to not produce empty graphs and control directions
if len(graph) > 0 and graph.is_directed():
assert overall_reciprocity(graph) == pytest.approx(nx.overall_reciprocity(graph))


@settings(deadline=None, max_examples=500)
@given(custom_graph_generators())
def test_reciprocity_gen(graph):
if len(graph) > 0 and graph.is_directed():
assert reciprocity(graph) == pytest.approx(nx.reciprocity(graph))


from networkx.algorithms.tests.test_reciprocity import * # isort:skip
1 change: 1 addition & 0 deletionsgraphblas_algorithms/utils/__init__.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
from ._misc import *
from .decorators import *
from .graph_gen import *
30 changes: 30 additions & 0 deletionsgraphblas_algorithms/utils/graph_gen.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
import networkx as nx
from hypothesis.strategies import booleans, composite, integers, lists, tuples


@composite
def custom_graph_generators(
draw,
directed=booleans(),
self_loops=booleans(),
sym_digraph=booleans(),
edges=tuples(integers(0, 100), integers(0, 100), integers(-100, 100)),
edge_data=booleans(),
):
G = nx.DiGraph() if draw(directed) else nx.Graph()
self_loop = draw(self_loops)
edges = draw(lists(edges, max_size=1000))
edge_data = draw(edge_data)
for u, v, d in edges:
if not self_loop and u == v:
continue
if edge_data:
G.add_edge(u, v, data=d)
else:
G.add_edge(u, v)
if G.is_directed():
sym_digraph = draw(sym_digraph)
if sym_digraph:
G = G.to_undirected()
G = G.to_directed()
return G

[8]ページ先頭

©2009-2025 Movatter.jp