Skip to main content

get_biadjacency_weighted

Function get_biadjacency_weighted 

Source
pub fn get_biadjacency_weighted(
    graph: &Graph,
    types: &[bool],
    weights: &[f64],
) -> IgraphResult<GetBiadjacencyWeightedResult>
Expand description

Extract a weighted biadjacency matrix from a bipartite graph.

Given a graph, a per-vertex type vector, and per-edge weights, returns the n1 × n2 biadjacency matrix where entry (i, j) is the sum of weights of edges between row-vertex i and column-vertex j.

Edges within the same partition are silently ignored.

§Parameters

  • graph — the input graph.
  • types — per-vertex boolean: false = row, true = column.
  • weights — per-edge weight (must have length graph.ecount()).

§Errors

§Examples

use rust_igraph::{Graph, get_biadjacency_weighted};

let mut g = Graph::new(4, false).unwrap();
// rows: {0, 1}, cols: {2, 3}
g.add_edges(vec![(0, 2), (0, 3), (1, 2)]).unwrap();
let types = vec![false, false, true, true];
let weights = vec![1.5, 2.0, 3.0];
let r = get_biadjacency_weighted(&g, &types, &weights).unwrap();
assert_eq!(r.matrix[0][0], 1.5); // edge (0,2) weight
assert_eq!(r.matrix[0][1], 2.0); // edge (0,3) weight
assert_eq!(r.matrix[1][0], 3.0); // edge (1,2) weight
assert_eq!(r.matrix[1][1], 0.0); // no edge (1,3)