pub fn weighted_adjacency(
matrix: &[&[f64]],
mode: AdjacencyMode,
loops: LoopsMode,
) -> IgraphResult<(Graph, Vec<f64>)>Expand description
Build a graph and a per-edge weight vector from a dense real-valued adjacency matrix.
Matches igraph_weighted_adjacency() semantics exactly. The matrix
is passed as &[&[f64]] — 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 allowed.
Returns (graph, weights) where weights[k] is the weight of the
k-th emitted edge (graph.edge(k)).
§Errors
IgraphError::InvalidArgument— the matrix is non-square (a row’s length differs from the row count), or (AdjacencyMode::Undirectedonly) is not NaN-tolerantly symmetric, or the vertex count exceedsu32::MAX.
§Examples
use rust_igraph::{weighted_adjacency, AdjacencyMode, LoopsMode};
// Directed K₃ with no loops, weights = 0.5 on every arc.
let m: &[&[f64]] = &[&[0.0, 0.5, 0.5], &[0.5, 0.0, 0.5], &[0.5, 0.5, 0.0]];
let (g, w) = weighted_adjacency(m, AdjacencyMode::Directed, LoopsMode::NoLoops).unwrap();
assert_eq!(g.vcount(), 3);
assert_eq!(g.ecount(), 6);
assert!(g.is_directed());
assert_eq!(w.len(), 6);
for &x in &w {
assert!((x - 0.5).abs() < 1e-12);
}