@@ -119,24 +119,20 @@ def get_recip_degreesp(G, mask=None):
119119 """pair(A & A.T).reduce_rowwise()"""
120120 A = G ._A
121121 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 )
126123 if mask is not None :
127124 if "recip_degrees+" in cache :
128125 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 :
130127 cache ["recip_degrees+" ] = cache ["recip_degrees-" ]
131128 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 :
133130 return (unary .one (cache ["diag" ]) + cache ["recip_degrees-" ]).new (
134131 mask = mask , name = "recip_degrees+"
135132 )
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" ):
137134 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+" )
140136 if "recip_degrees+" not in cache :
141137 if cache .get ("has_self_edges" ) is False and "recip_degrees-" in cache :
142138 cache ["recip_degrees+" ] = cache ["recip_degrees-" ]
@@ -174,34 +170,33 @@ def get_recip_degreesm(G, mask=None):
174170 if mask is not None :
175171 if "recip_degrees-" in cache :
176172 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 :
178174 cache ["recip_degrees-" ] = cache ["recip_degrees+" ]
179175 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 :
181177 rv = binary .minus (cache ["recip_degrees+" ] | unary .one (cache ["diag" ])).new (
182178 mask = mask , name = "recip_degrees-"
183179 )
184180 rv (rv .V , replace ) << rv # drop 0s
185181 return rv
186- elif not G .get_property ("has_self_edges" ):
182+ if not G .get_property ("has_self_edges" ):
187183 return G .get_property ("recip_degrees+" , mask = mask )
188- elif "offdiag" in cache :
184+ if "offdiag" in cache :
189185 return (
190186 binary .pair (cache ["offdiag" ] & AT )
191187 .reduce_rowwise ()
192188 .new (mask = mask , name = "recip_degrees-" )
193189 )
194- elif "L-" in cache and "U-" in cache :
190+ if "L-" in cache and "U-" in cache :
195191 return (
196192 binary .pair (cache ["L-" ] & AT ).reduce_rowwise ().new (mask = mask )
197193 + binary .pair (cache ["U-" ] & AT ).reduce_rowwise ().new (mask = mask )
198194 ).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
205200 if "recip_degrees-" not in cache :
206201 if cache .get ("has_self_edges" ) is False and "recip_degrees+" in cache :
207202 cache ["recip_degrees-" ] = cache ["recip_degrees+" ]
@@ -245,14 +240,12 @@ def get_total_degreesp(G, mask=None):
245240 if mask is not None :
246241 if "total_degrees+" in cache :
247242 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 :
249244 cache ["total_degrees+" ] = cache ["total_degrees-" ]
250245 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+" )
256249 if "total_degrees+" not in cache :
257250 if cache .get ("has_self_edges" ) is False and "total_degrees-" in cache :
258251 cache ["total_degrees+" ] = cache ["total_degrees-" ]
@@ -277,14 +270,12 @@ def get_total_degreesm(G, mask=None):
277270 if mask is not None :
278271 if "total_degrees-" in cache :
279272 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 :
281274 cache ["total_degrees-" ] = cache ["total_degrees+" ]
282275 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-" )
288279 if "total_degrees-" not in cache :
289280 if cache .get ("has_self_edges" ) is False and "total_degrees+" in cache :
290281 cache ["total_degrees-" ] = cache ["total_degrees+" ]
@@ -313,10 +304,7 @@ def get_total_recipp(G, mask=None):
313304 elif "recip_degrees+" in cache :
314305 cache ["total_recip+" ] = cache ["recip_degrees+" ].reduce ().get (0 )
315306 else :
316- if "AT" in cache :
317- AT = cache ["AT" ]
318- else :
319- AT = A .T
307+ AT = cache .get ("AT" , A .T )
320308 cache ["total_recip+" ] = binary .pair (A & AT ).reduce_scalar ().get (0 )
321309 if "has_self_edges" not in cache and "total_recip-" in cache :
322310 cache ["has_self_edges" ] = cache ["total_recip+" ] > cache ["total_recip-" ]
@@ -398,8 +386,7 @@ def to_directed_graph(G, weight=None, dtype=None):
398386 return DiGraph .from_networkx (G , weight = weight , dtype = dtype )
399387 except ImportError :
400388 pass
401-
402- raise TypeError ()
389+ raise TypeError
403390
404391
405392def to_graph (G , weight = None , dtype = None ):
@@ -420,8 +407,7 @@ def to_graph(G, weight=None, dtype=None):
420407 return ga .Graph .from_networkx (G , weight = weight , dtype = dtype )
421408 except ImportError :
422409 pass
423-
424- raise TypeError ()
410+ raise TypeError
425411
426412
427413class AutoDict (dict ):
0 commit comments