MCPcopy Create free account
hub / github.com/easy-graph/Easy-Graph / density

Function density

cpp_easygraph/classes/operation.cpp:4–16  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2#include "graph.h"
3
4py::object density(py::object G) {
5 Graph& G_ = G.cast<Graph&>();
6 int n = G_.node.size();
7 int m = G.attr("number_of_edges")().cast<int>();
8 if (m == 0 || n <= 1) {
9 return py::cast(0);
10 }
11 weight_t d = m * 1.0 / (n * (n - 1));
12 if(G.attr("is_directed")().equal(py::cast(false))){
13 d*=2;
14 }
15 return py::cast(d);
16}

Callers

nothing calls this directly

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected