pub fn joint_degree_matrix(
graph: &Graph,
weights: Option<&[f64]>,
) -> IgraphResult<Vec<Vec<f64>>>Expand description
Compute the joint degree matrix of a graph.
Returns a matrix where entry (d1-1, d2-1) counts (or sums weights of)
edges between vertices of degree d1 and degree d2.
- For undirected graphs: both endpoints contribute their total degree.
The matrix is symmetric. Each edge is counted once (but contributes
to both
[d_u-1][d_v-1]and[d_v-1][d_u-1]unlessd_u == d_v). - For directed graphs: row index is source out-degree, column index is target in-degree. Each edge is counted exactly once.
weights: optional edge weights (length must equal ecount()).
Returns an empty matrix for graphs with no edges.
§Examples
use rust_igraph::{Graph, joint_degree_matrix};
// Triangle: all vertices have degree 2. JDM[1][1] = 3 (three edges).
let mut g = Graph::with_vertices(3);
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
g.add_edge(2, 0).unwrap();
let jdm = joint_degree_matrix(&g, None).unwrap();
// max_degree = 2, so matrix is 2×2. Only [1][1] is nonzero.
assert_eq!(jdm.len(), 2);
assert!((jdm[1][1] - 3.0).abs() < 1e-10);
assert!((jdm[0][0]).abs() < 1e-10);