Skip to main content

Module weighted_adjacency

Module weighted_adjacency 

Source
Expand description

Dense weighted adjacency-matrix constructor (ALGO-CN-030).

Counterpart of igraph_weighted_adjacency() in references/igraph/src/constructors/adjacency.c:785-878.

Builds a Graph and a parallel weight vector from a square n × n real-valued matrix. Differences from the integer adjacency variant:

  • Entries are edge weights, not multiplicities: every non-zero cell becomes exactly one edge whose weight equals the cell value (the integer variant duplicates edges by cell value).
  • Negative weights are allowed.
  • NaN propagation rules apply to AdjacencyMode::Max and AdjacencyMode::Min; AdjacencyMode::Undirected uses a NaN-tolerant symmetry check (NaN == NaN on the same diagonal reflection is treated as symmetric, matching upstream’s ! (isnan(M1) && isnan(M2)) predicate).

The shape of the resulting graph (directed / undirected, which triangle drives the edge count, how the diagonal becomes self-loops) is controlled by the two enums that adjacency exposes — AdjacencyMode and LoopsMode. They are re-exported here for convenience.

For consistency with upstream igraph the Twice request is silently collapsed to Once for the Directed, Upper and Lower modes — the matrix only stores one copy of each loop in those layouts (see the issue cited in the upstream source, igraph#2501).

For LoopsMode::NoLoops, the diagonal contribution is zeroed and consequently skipped by the post-adjust != 0.0 filter so no self-loops are emitted.

Matrix layout: &[&[f64]] — a slice of equal-length rows in row-major form. Every row must have the same length as the outer slice; ragged input is rejected. A 0 × 0 matrix produces an empty graph and an empty weight vector (matches the C semantics for an IGRAPH_MATRIX_NULL of shape 0 × 0).

Time complexity: O(|V|² + |E|).

Functions§

weighted_adjacency
Build a graph and a per-edge weight vector from a dense real-valued adjacency matrix.