Skip to content

Commit

Permalink
Fix networkx issue (#268)
Browse files Browse the repository at this point in the history
* initial commit

* changed python version

* fixed matrix multiply
  • Loading branch information
nwlandry authored Jan 10, 2023
1 parent c6b6ef1 commit 745c906
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 24 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
python-version: ['3.8', '3.9', '3.10', '3.11']
steps:
- uses: actions/checkout@v2

Expand Down Expand Up @@ -57,7 +57,7 @@ jobs:
strategy:
matrix:
os: [ubuntu, macos, windows]
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
python-version: ['3.8', '3.9', '3.10', '3.11']
steps:
- uses: actions/checkout@v2

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Sign up for our [mailing list](http://eepurl.com/igE6ez) and follow XGI on [Twit
- [Other Resources](#other-resources)

## Installation
XGI runs on Python 3.7 or higher.
XGI runs on Python 3.8 or higher.

To install the latest version of XGI, run the following command:
```sh
Expand Down
2 changes: 1 addition & 1 deletion docs/source/about.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ If that command does not work, you may try the following instead
pip install -e .\[all\]
XGI was developed and tested for Python 3.7-3.10 on Mac OS, Windows, and Ubuntu.
XGI was developed and tested for Python 3.8-3.11 on Mac OS, Windows, and Ubuntu.


Academic References
Expand Down
2 changes: 1 addition & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ If that command does not work, you may try the following instead
pip install -e .\[all\]
XGI was developed and tested for Python 3.7-3.11 on Mac OS, Windows, and Ubuntu.
XGI was developed and tested for Python 3.8-3.11 on Mac OS, Windows, and Ubuntu.

Corresponding Data
==================
Expand Down
2 changes: 1 addition & 1 deletion long_description.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ and study of the structure, dynamics, and functions of complex systems with grou

Installation
------------
XGI runs on Python 3.7 or higher.
XGI runs on Python 3.8 or higher.

To install the latest version of XGI, run the following command::

Expand Down
2 changes: 1 addition & 1 deletion requirements/default.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
numpy>=1.19
scipy>=1.5
pandas>=1.0
networkx>=2.0,<3.0
networkx>=2.7
requests>=2.0
matplotlib>=3.3
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

__version__ = "0.5.2"

if sys.version_info < (3, 7):
sys.exit("XGI requires Python 3.7 or later.")
if sys.version_info < (3, 8):
sys.exit("XGI requires Python 3.8 or later.")

name = "xgi"

Expand Down
8 changes: 4 additions & 4 deletions tests/linalg/test_matrix.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np
import pytest
from scipy.sparse import csr_matrix
from scipy.sparse import csr_array
from scipy.sparse.linalg import norm as spnorm

import xgi
Expand Down Expand Up @@ -89,7 +89,7 @@ def test_incidence_matrix(edgelist1, edgelist3, edgelist4):
assert I6[node_dict6[8], edge_dict6[3]] == 1

data = xgi.incidence_matrix(H1)
assert type(data) == csr_matrix
assert type(data) == csr_array

H7 = xgi.empty_hypergraph()
H7.add_nodes_from(range(8)) # disconnected node 0
Expand Down Expand Up @@ -158,7 +158,7 @@ def test_adjacency_matrix(edgelist1, edgelist4):
node_dict2 = {k: v for v, k in node_dict.items()}

data = xgi.adjacency_matrix(H2)
assert type(data) == csr_matrix
assert type(data) == csr_array

for i in range(np.size(A1, axis=0)):
assert A1[i, i] == 0
Expand Down Expand Up @@ -390,7 +390,7 @@ def test_clique_motif_matrix(edgelist4):
node_dict1 = {k: v for v, k in node_dict.items()}

data = xgi.clique_motif_matrix(H1)
assert type(data) == csr_matrix
assert type(data) == csr_array

for i in range(np.size(W1, axis=0)):
assert W1[i, i] == 0
Expand Down
4 changes: 2 additions & 2 deletions xgi/algorithms/centrality.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ def node_edge_centrality(
check = np.inf

for iter in range(max_iter):
u = np.multiply(x, g(I * f(y)))
v = np.multiply(y, psi(I.T * phi(x)))
u = np.multiply(x, g(I @ f(y)))
v = np.multiply(y, psi(I.T @ phi(x)))
new_x = u / norm(u)
new_y = v / norm(v)

Expand Down
45 changes: 39 additions & 6 deletions xgi/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@
import pandas as pd
from networkx.algorithms import bipartite
from numpy import matrix, ndarray
from scipy.sparse import coo_matrix, csc_matrix, csr_matrix, lil_matrix
from scipy.sparse import (
coo_array,
coo_matrix,
csc_array,
csc_matrix,
csr_array,
csr_matrix,
lil_array,
lil_matrix,
)

from .classes import (
Hypergraph,
Expand Down Expand Up @@ -84,7 +93,19 @@ def convert_to_hypergraph(data, create_using=None):
from_hyperedge_dict(data, create_using)

elif isinstance(
data, (ndarray, matrix, csr_matrix, csc_matrix, coo_matrix, lil_matrix)
data,
(
ndarray,
matrix,
csr_array,
csc_array,
coo_array,
lil_array,
csr_matrix,
csc_matrix,
coo_matrix,
lil_matrix,
),
):
from_incidence_matrix(data, create_using)

Expand All @@ -108,7 +129,7 @@ def convert_to_graph(H):
"""

A = adjacency_matrix(H) # This is unweighted by design
G = nx.from_scipy_sparse_matrix(A)
G = nx.from_scipy_sparse_array(A)
G = nx.relabel_nodes(G, {i: node for i, node in enumerate(H.nodes)})
return G

Expand Down Expand Up @@ -161,7 +182,19 @@ def convert_to_simplicial_complex(data, create_using=None):
# edge dict in the form we need
raise XGIError("Cannot generate SimplicialComplex from simplex dictionary")
elif isinstance(
data, (ndarray, matrix, csr_matrix, csc_matrix, coo_matrix, lil_matrix)
data,
(
ndarray,
matrix,
csr_array,
csc_array,
coo_array,
lil_array,
csr_matrix,
csc_matrix,
coo_matrix,
lil_matrix,
),
):
# incidence matrix
raise XGIError(
Expand Down Expand Up @@ -382,7 +415,7 @@ def from_incidence_matrix(d, create_using=None, nodelabels=None, edgelabels=None
incidence_matrix
to_incidence_matrix
"""
I = coo_matrix(d)
I = coo_array(d)
n, m = I.shape

if nodelabels is None:
Expand Down Expand Up @@ -447,7 +480,7 @@ def to_incidence_matrix(H, sparse=True, index=False):
Returns
-------
numpy.ndarray or scipy csr_matrix
numpy.ndarray or scipy csr_array
The incidence matrix
dict
The dictionary mapping indices to node IDs, if index is True
Expand Down
6 changes: 3 additions & 3 deletions xgi/linalg/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from warnings import warn

import numpy as np
from scipy.sparse import csr_matrix, diags
from scipy.sparse import csr_array, diags

__all__ = [
"incidence_matrix",
Expand Down Expand Up @@ -40,7 +40,7 @@ def incidence_matrix(
Returns
-------
I: numpy.ndarray or scipy csr_matrix
I: numpy.ndarray or scipy csr_array
The incidence matrix, has dimension (n_nodes, n_edges)
rowdict: dict
The dictionary mapping indices to node IDs, if index is True
Expand Down Expand Up @@ -85,7 +85,7 @@ def incidence_matrix(
data.append(0)
rows.append(node_dict[node])
cols.append(edge_dict[edge])
I = csr_matrix((data, (rows, cols)))
I = csr_array((data, (rows, cols)))
else:
# Create an np.matrix
I = np.zeros((num_nodes, num_edges), dtype=int)
Expand Down

0 comments on commit 745c906

Please sign in to comment.