Skip to main content

weighted_biadjacency

Function weighted_biadjacency 

Source
pub fn weighted_biadjacency(
    matrix: &[&[f64]],
    directed: bool,
    mode: BipartiteMode,
) -> IgraphResult<WeightedBiadjacencyResult>
Expand description

Build a bipartite graph from a weighted biadjacency matrix.

The matrix has n1 rows and n2 columns. The resulting graph has n1 + n2 vertices: vertices [0, n1) correspond to rows (partition 1) and vertices [n1, n1+n2) correspond to columns (partition 2).

Each non-zero entry in the matrix produces one edge (or two mutual edges when directed = true and mode = All) whose weight equals the matrix entry value.

§Parameters

  • matrix — row-major n1 × n2 weighted biadjacency matrix (all rows must have equal length n2).
  • directed — whether the resulting graph is directed.
  • mode — edge direction policy (only meaningful when directed = true):

§Errors

§Examples

use rust_igraph::{weighted_biadjacency, BipartiteMode};

let matrix: &[&[f64]] = &[
    &[1.5, 0.0],
    &[0.0, 2.5],
];
let r = weighted_biadjacency(matrix, false, BipartiteMode::All).unwrap();
assert_eq!(r.graph.vcount(), 4);
assert_eq!(r.graph.ecount(), 2);
assert_eq!(r.weights, vec![1.5, 2.5]);
assert_eq!(r.types, vec![false, false, true, true]);