pub fn biadjacency(
matrix: &[&[f64]],
directed: bool,
mode: BipartiteMode,
multiple: bool,
) -> IgraphResult<BiadjacencyResult>Expand description
Build a bipartite graph from a 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).
§Parameters
matrix— row-majorn1 × n2biadjacency matrix (all rows must have equal lengthn2).directed— whether the resulting graph is directed.mode— edge direction policy (only meaningful whendirected = true):BipartiteMode::Out— arcs from rows to columns.BipartiteMode::In— arcs from columns to rows.BipartiteMode::All— mutual arcs in both directions.
multiple— iftrue, matrix values are interpreted as integer multiplicities (must be non-negative); iffalse, any non-zero value produces a single edge.
§Errors
IgraphError::InvalidArgument— ragged matrix, negative entry whenmultiple = true, or vertex count overflow.
§Examples
use rust_igraph::{biadjacency, BipartiteMode};
// 2×3 matrix → graph with 5 vertices.
let matrix: &[&[f64]] = &[
&[1.0, 0.0, 2.0],
&[0.0, 1.0, 0.0],
];
let r = biadjacency(matrix, false, BipartiteMode::All, false).unwrap();
assert_eq!(r.graph.vcount(), 5);
assert_eq!(r.graph.ecount(), 3); // three non-zero entries
assert_eq!(r.types, vec![false, false, true, true, true]);
// With multiple=true, entry 2.0 produces 2 edges.
let m = biadjacency(matrix, false, BipartiteMode::All, true).unwrap();
assert_eq!(m.graph.ecount(), 4); // 1 + 2 + 1