Skip to main content

adjacency

Function adjacency 

Source
pub fn adjacency(
    matrix: &[&[i64]],
    mode: AdjacencyMode,
    loops: LoopsMode,
) -> IgraphResult<Graph>
Expand description

Build a graph from a dense integer adjacency matrix.

Matches igraph_adjacency() semantics exactly. The matrix is passed as &[&[i64]] — outer slice indexed by row, inner slice by column. The matrix must be square (each row length equal to the outer length); negative entries are rejected.

§Errors

  • IgraphError::InvalidArgument — the matrix is non-square (a row’s length differs from the row count), contains a negative entry, or (Undirected only) is not symmetric, or (LoopsMode::Twice with a symmetric mode) has an odd diagonal entry, or the vertex count exceeds u32::MAX.

§Examples

use rust_igraph::{adjacency, AdjacencyMode, LoopsMode};

// Directed K₃ with no loops.
let m: &[&[i64]] = &[&[0, 1, 1], &[1, 0, 1], &[1, 1, 0]];
let g = adjacency(m, AdjacencyMode::Directed, LoopsMode::NoLoops).unwrap();
assert_eq!(g.vcount(), 3);
assert_eq!(g.ecount(), 6);
assert!(g.is_directed());