MCPcopy Create free account
hub / github.com/alibaba/GraphScope / size

Method size

python/graphscope/nx/classes/graph.py:1180–1220  ·  view source on GitHub ↗

Returns the number of edges or total of all edge weights. Parameters ---------- weight : string or None, optional (default=None) The edge attribute that holds the numerical value used as a weight. If None, then each edge has weight 1. Returns

(self, weight=None)

Source from the content-addressed store, hash-verified

1178
1179 @clear_mutation_cache
1180 def size(self, weight=None):
1181 """Returns the number of edges or total of all edge weights.
1182
1183 Parameters
1184 ----------
1185 weight : string or None, optional (default=None)
1186 The edge attribute that holds the numerical value used
1187 as a weight. If None, then each edge has weight 1.
1188
1189 Returns
1190 -------
1191 size : numeric
1192 The number of edges or
1193 (if weight keyword is provided) the total weight sum.
1194
1195 If weight is None, returns an int. Otherwise a float
1196 (or more general numeric if the weights are more general).
1197
1198 See Also
1199 --------
1200 number_of_edges
1201
1202 Examples
1203 --------
1204 >>> G = nx.path_graph(4) # or DiGraph
1205 >>> G.size()
1206 3
1207
1208 >>> G = nx.Graph() # or DiGraph
1209 >>> G.add_edge("a", "b", weight=2)
1210 >>> G.add_edge("b", "c", weight=4)
1211 >>> G.size()
1212 2
1213 >>> G.size(weight="weight")
1214 6.0
1215 """
1216 if weight:
1217 return sum(d for v, d in self.degree(weight=weight)) / 2
1218 op = dag_utils.report_graph(self, types_pb2.EDGE_NUM)
1219 archive = op.eval()
1220 return archive.get_size() // 2
1221
1222 @clear_mutation_cache
1223 @patch_docstring(RefGraph.number_of_edges)

Callers 3

number_of_edgesMethod · 0.95
test_updateMethod · 0.95
test_updateMethod · 0.95

Calls 3

degreeMethod · 0.95
evalMethod · 0.45
get_sizeMethod · 0.45

Tested by 2

test_updateMethod · 0.76
test_updateMethod · 0.76