Skip to content

Commit

Permalink
fix sparse matrix error
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaelicke committed Jun 26, 2024
1 parent 6d8a846 commit fbd428e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions skgstat/MetricSpace.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,14 +777,16 @@ def dists(self):
# from https://stackoverflow.com/questions/28677162/ignoring-duplicate-entries-in-sparse-matrix

# Stable solution but a bit slow
# c, eq, d = zip(*set(zip(c, eq, d)))
# dists = sparse.csr_matrix((d, (c, eq)), shape=(len(self.coords), len(self.coords)))
c, eq, d = zip(*set(zip(c, eq, d)))
dists = sparse.csr_matrix((d, (c, eq)), shape=(len(self.coords), len(self.coords)))

# comment mmaelicke: We need to fall back to the slower solution as dok._update is not supported in scipy 1.0 anymore
#
# Solution 5+ times faster than the preceding, but relies on _update() which might change in scipy (which
# only has an implemented method for summing duplicates, and not ignoring them yet)
dok = sparse.dok_matrix((len(self.coords), len(self.coords)))
dok._update(zip(zip(c, eq), d))
dists = dok.tocsr()
# dok = sparse.dok_matrix((len(self.coords), len(self.coords)))
# dok._update(zip(zip(c, eq), d))
# dists = dok.tocsr()

self._dists = dists

Expand Down
2 changes: 1 addition & 1 deletion skgstat/tests/test_variogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ def test_harmonize_model(self):

assert_array_almost_equal(
V.transform(x),
[np.NaN, 0.57, 1.01, 1.12, 1.15, 1.15, 1.15, 1.15, 1.21, 1.65],
[np.nan, 0.57, 1.01, 1.12, 1.15, 1.15, 1.15, 1.15, 1.21, 1.65],
decimal=2
)

Expand Down

0 comments on commit fbd428e

Please sign in to comment.