@@ -119,24 +119,20 @@ def get_recip_degreesp(G, mask=None):
119
119
"""pair(A & A.T).reduce_rowwise()"""
120
120
A = G ._A
121
121
cache = G ._cache
122
- if "AT" in cache :
123
- AT = cache ["AT" ]
124
- else :
125
- AT = A .T
122
+ AT = cache .get ("AT" , A .T )
126
123
if mask is not None :
127
124
if "recip_degrees+" in cache :
128
125
return cache ["recip_degrees+" ].dup (mask = mask )
129
- elif cache .get ("has_self_edges" ) is False and "recip_degrees-" in cache :
126
+ if cache .get ("has_self_edges" ) is False and "recip_degrees-" in cache :
130
127
cache ["recip_degrees+" ] = cache ["recip_degrees-" ]
131
128
return cache ["recip_degrees-" ].dup (mask = mask )
132
- elif "recip_degrees-" in cache and "diag" in cache :
129
+ if "recip_degrees-" in cache and "diag" in cache :
133
130
return (unary .one (cache ["diag" ]) + cache ["recip_degrees-" ]).new (
134
131
mask = mask , name = "recip_degrees+"
135
132
)
136
- elif "recip_degrees-" in cache and not G .get_property ("has_self_edges" ):
133
+ if "recip_degrees-" in cache and not G .get_property ("has_self_edges" ):
137
134
return cache ["recip_degrees-" ].dup (mask = mask )
138
- else :
139
- return binary .pair (A & AT ).reduce_rowwise ().new (mask = mask , name = "recip_degrees+" )
135
+ return binary .pair (A & AT ).reduce_rowwise ().new (mask = mask , name = "recip_degrees+" )
140
136
if "recip_degrees+" not in cache :
141
137
if cache .get ("has_self_edges" ) is False and "recip_degrees-" in cache :
142
138
cache ["recip_degrees+" ] = cache ["recip_degrees-" ]
@@ -174,34 +170,33 @@ def get_recip_degreesm(G, mask=None):
174
170
if mask is not None :
175
171
if "recip_degrees-" in cache :
176
172
return cache ["recip_degrees-" ].dup (mask = mask )
177
- elif cache .get ("has_self_edges" ) is False and "recip_degrees+" in cache :
173
+ if cache .get ("has_self_edges" ) is False and "recip_degrees+" in cache :
178
174
cache ["recip_degrees-" ] = cache ["recip_degrees+" ]
179
175
return cache ["recip_degrees-" ].dup (mask = mask )
180
- elif "recip_degrees+" in cache and "diag" in cache :
176
+ if "recip_degrees+" in cache and "diag" in cache :
181
177
rv = binary .minus (cache ["recip_degrees+" ] | unary .one (cache ["diag" ])).new (
182
178
mask = mask , name = "recip_degrees-"
183
179
)
184
180
rv (rv .V , replace ) << rv # drop 0s
185
181
return rv
186
- elif not G .get_property ("has_self_edges" ):
182
+ if not G .get_property ("has_self_edges" ):
187
183
return G .get_property ("recip_degrees+" , mask = mask )
188
- elif "offdiag" in cache :
184
+ if "offdiag" in cache :
189
185
return (
190
186
binary .pair (cache ["offdiag" ] & AT )
191
187
.reduce_rowwise ()
192
188
.new (mask = mask , name = "recip_degrees-" )
193
189
)
194
- elif "L-" in cache and "U-" in cache :
190
+ if "L-" in cache and "U-" in cache :
195
191
return (
196
192
binary .pair (cache ["L-" ] & AT ).reduce_rowwise ().new (mask = mask )
197
193
+ binary .pair (cache ["U-" ] & AT ).reduce_rowwise ().new (mask = mask )
198
194
).new (name = "recip_degrees-" )
199
- else :
200
- diag = G .get_property ("diag" , mask = mask )
201
- overlap = binary .pair (A & AT ).reduce_rowwise ().new (mask = mask )
202
- rv = binary .minus (overlap | unary .one (diag )).new (name = "recip_degrees-" )
203
- rv (rv .V , replace ) << rv # drop 0s
204
- return rv
195
+ diag = G .get_property ("diag" , mask = mask )
196
+ overlap = binary .pair (A & AT ).reduce_rowwise ().new (mask = mask )
197
+ rv = binary .minus (overlap | unary .one (diag )).new (name = "recip_degrees-" )
198
+ rv (rv .V , replace ) << rv # drop 0s
199
+ return rv
205
200
if "recip_degrees-" not in cache :
206
201
if cache .get ("has_self_edges" ) is False and "recip_degrees+" in cache :
207
202
cache ["recip_degrees-" ] = cache ["recip_degrees+" ]
@@ -245,14 +240,12 @@ def get_total_degreesp(G, mask=None):
245
240
if mask is not None :
246
241
if "total_degrees+" in cache :
247
242
return cache ["total_degrees+" ].dup (mask = mask )
248
- elif cache .get ("has_self_edges" ) is False and "total_degrees-" in cache :
243
+ if cache .get ("has_self_edges" ) is False and "total_degrees-" in cache :
249
244
cache ["total_degrees+" ] = cache ["total_degrees-" ]
250
245
return cache ["total_degrees+" ].dup (mask = mask )
251
- else :
252
- return (
253
- G .get_property ("row_degrees+" , mask = mask )
254
- + G .get_property ("column_degrees+" , mask = mask )
255
- ).new (name = "total_degrees+" )
246
+ return (
247
+ G .get_property ("row_degrees+" , mask = mask ) + G .get_property ("column_degrees+" , mask = mask )
248
+ ).new (name = "total_degrees+" )
256
249
if "total_degrees+" not in cache :
257
250
if cache .get ("has_self_edges" ) is False and "total_degrees-" in cache :
258
251
cache ["total_degrees+" ] = cache ["total_degrees-" ]
@@ -277,14 +270,12 @@ def get_total_degreesm(G, mask=None):
277
270
if mask is not None :
278
271
if "total_degrees-" in cache :
279
272
return cache ["total_degrees-" ].dup (mask = mask )
280
- elif cache .get ("has_self_edges" ) is False and "total_degrees+" in cache :
273
+ if cache .get ("has_self_edges" ) is False and "total_degrees+" in cache :
281
274
cache ["total_degrees-" ] = cache ["total_degrees+" ]
282
275
return cache ["total_degrees-" ].dup (mask = mask )
283
- else :
284
- return (
285
- G .get_property ("row_degrees-" , mask = mask )
286
- + G .get_property ("column_degrees-" , mask = mask )
287
- ).new (name = "total_degrees-" )
276
+ return (
277
+ G .get_property ("row_degrees-" , mask = mask ) + G .get_property ("column_degrees-" , mask = mask )
278
+ ).new (name = "total_degrees-" )
288
279
if "total_degrees-" not in cache :
289
280
if cache .get ("has_self_edges" ) is False and "total_degrees+" in cache :
290
281
cache ["total_degrees-" ] = cache ["total_degrees+" ]
@@ -313,10 +304,7 @@ def get_total_recipp(G, mask=None):
313
304
elif "recip_degrees+" in cache :
314
305
cache ["total_recip+" ] = cache ["recip_degrees+" ].reduce ().get (0 )
315
306
else :
316
- if "AT" in cache :
317
- AT = cache ["AT" ]
318
- else :
319
- AT = A .T
307
+ AT = cache .get ("AT" , A .T )
320
308
cache ["total_recip+" ] = binary .pair (A & AT ).reduce_scalar ().get (0 )
321
309
if "has_self_edges" not in cache and "total_recip-" in cache :
322
310
cache ["has_self_edges" ] = cache ["total_recip+" ] > cache ["total_recip-" ]
@@ -398,8 +386,7 @@ def to_directed_graph(G, weight=None, dtype=None):
398
386
return DiGraph .from_networkx (G , weight = weight , dtype = dtype )
399
387
except ImportError :
400
388
pass
401
-
402
- raise TypeError ()
389
+ raise TypeError
403
390
404
391
405
392
def to_graph (G , weight = None , dtype = None ):
@@ -420,8 +407,7 @@ def to_graph(G, weight=None, dtype=None):
420
407
return ga .Graph .from_networkx (G , weight = weight , dtype = dtype )
421
408
except ImportError :
422
409
pass
423
-
424
- raise TypeError ()
410
+ raise TypeError
425
411
426
412
427
413
class AutoDict (dict ):
0 commit comments