Skip to content

Commit

Permalink
Fix handling of COO matrices by ripser mirroring scikit-tda/ripser.py…
Browse files Browse the repository at this point in the history
  • Loading branch information
ulupo authored Aug 25, 2020
1 parent 4151453 commit 9d7ce62
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions gtda/externals/python/ripser_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,16 +207,27 @@ def ripser(X, maxdim=1, thresh=np.inf, coeff=2, metric="euclidean",
dm = sparse.coo_matrix(dm)

if sparse.issparse(dm):
coo = dm.tocoo()
if sparse.isspmatrix_coo(dm):
# If the matrix is already COO, we need to order the row and column
# indices lexicographically to avoid errors. See
# https://github.com/scikit-tda/ripser.py/issues/103
row, col, data = dm.row, dm.col, dm.data
lex_sort_idx = np.lexsort((col, row))
row, col, data = \
row[lex_sort_idx], col[lex_sort_idx], data[lex_sort_idx]
else:
# Lexicographic sorting is performed by scipy upon conversion
coo = dm.tocoo()
row, col, data = coo.row, coo.col, coo.data
res = DRFDMSparse(
coo.row.astype(dtype=np.int32, order="C"),
coo.col.astype(dtype=np.int32, order="C"),
np.array(coo.data, dtype=np.float32, order="C"),
row.astype(dtype=np.int32, order="C"),
col.astype(dtype=np.int32, order="C"),
np.array(data, dtype=np.float32, order="C"),
n_points,
maxdim,
thresh,
coeff,
)
)
else:
I, J = np.meshgrid(np.arange(n_points), np.arange(n_points))
DParam = np.array(dm[I > J], dtype=np.float32)
Expand Down

0 comments on commit 9d7ce62

Please sign in to comment.