Skip to content

Commit eae9831

Browse files
committed
Streamlining from_WSP
1 parent a24c33e commit eae9831

File tree

2 files changed

+7
-15
lines changed

2 files changed

+7
-15
lines changed

libpysal/weights/util.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
try:
2626
from shapely.geometry.base import BaseGeometry
27+
2728
HAS_SHAPELY = True
2829
except ImportError:
2930
HAS_SHAPELY = False
@@ -534,17 +535,17 @@ def higher_order_sp(
534535
)
535536

536537
if lower_order:
537-
wk = sum(map(lambda x: w ** x, range(2, k + 1)))
538+
wk = sum(map(lambda x: w**x, range(2, k + 1)))
538539
shortest_path = False
539540
else:
540-
wk = w ** k
541+
wk = w**k
541542

542543
rk, ck = wk.nonzero()
543544
sk = set(zip(rk, ck))
544545

545546
if shortest_path:
546547
for j in range(1, k):
547-
wj = w ** j
548+
wj = w**j
548549
rj, cj = wj.nonzero()
549550
sj = set(zip(rj, cj))
550551
sk.difference_update(sj)
@@ -826,14 +827,12 @@ def WSP2W(wsp, **kwargs):
826827
827828
828829
"""
829-
wsp.sparse
830-
indices = wsp.sparse.indices
831830
data = wsp.sparse.data
832831
indptr = wsp.sparse.indptr
833832
id_order = wsp.id_order
834833
if id_order:
835834
# replace indices with user IDs
836-
indices = [id_order[i] for i in indices]
835+
indices = [id_order[i] for i in wsp.sparse.indices]
837836
else:
838837
id_order = list(range(wsp.n))
839838
neighbors, weights = {}, {}
@@ -1086,12 +1085,7 @@ def get_points_array(iterable):
10861085
]
10871086
)
10881087
else:
1089-
data = np.vstack(
1090-
[
1091-
np.array(shape.centroid)
1092-
for shape in first_choice
1093-
]
1094-
)
1088+
data = np.vstack([np.array(shape.centroid) for shape in first_choice])
10951089
except AttributeError:
10961090
data = np.vstack([shape for shape in backup])
10971091
return data

libpysal/weights/weights.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,14 +272,12 @@ def from_WSP(cls, WSP, silence_warnings=True):
272272
>>> print(w.full()[0][0])
273273
[0 1 0 0 0 1 0 0 0 0]
274274
"""
275-
WSP.sparse
276-
indices = WSP.sparse.indices
277275
data = WSP.sparse.data
278276
indptr = WSP.sparse.indptr
279277
id_order = WSP.id_order
280278
if id_order:
281279
# replace indices with user IDs
282-
indices = [id_order[i] for i in indices]
280+
indices = [id_order[i] for i in WSP.sparse.indices]
283281
else:
284282
id_order = list(range(WSP.n))
285283
neighbors, weights = {}, {}

0 commit comments

Comments
 (0)