diff --git a/.github/workflows/benchmarks.yml b/.github/workflows/benchmarks.yml new file mode 100644 index 00000000..1a39e203 --- /dev/null +++ b/.github/workflows/benchmarks.yml @@ -0,0 +1,32 @@ +name: Benchmarks + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + benchmark: + runs-on: ubuntu-latest + steps: + - uses: actions/setup-python@v4 + with: + python-version: "3.12" + - uses: actions/checkout@v3 + - name: Install packages + run: | + git fetch origin $GITHUB_BASE_REF:base $GITHUB_REF:pr + python -m pip install --upgrade pip wheel setuptools + pip install -r requirements/default.txt -r requirements/benchmarks.txt + pip install virtualenv + pip install setuptools + pip install . + python -m pip list + - name: Benchmark against main + run: | + cd benchmarks/ + asv machine --yes + asv continuous base pr -e diff --git a/requirements/benchmarks.txt b/requirements/benchmarks.txt index 5ec68690..45b3b497 100644 --- a/requirements/benchmarks.txt +++ b/requirements/benchmarks.txt @@ -1,2 +1,2 @@ hypernetx>=1.0 -asv>=0.5 \ No newline at end of file +asv>=0.5, <0.6 \ No newline at end of file diff --git a/xgi/algorithms/centrality.py b/xgi/algorithms/centrality.py index da0204c3..b661636b 100644 --- a/xgi/algorithms/centrality.py +++ b/xgi/algorithms/centrality.py @@ -58,8 +58,11 @@ def clique_eigenvector_centrality(H, tol=1e-6): if not is_connected(H): return {n: np.nan for n in H.nodes} W, node_dict = clique_motif_matrix(H, index=True) - _, v = eigsh(W.asfptype(), k=1, which="LM", tol=tol) - + try: + _, v = eigsh(W.astype(float), k=1, which="LM", tol=tol) + except AttributeError: + _, v = eigsh(W.asfptype(), k=1, which="LM", tol=tol) + # multiply by the sign to try and enforce positivity v = np.sign(v[0]) * v / norm(v, 1) return {node_dict[n]: v[n].item() for n in node_dict}