Graphs#
The dynamic graph container dyng::graph, its properties (row order, parallel edges, batch semantics), views, CSR and edge-list inputs, and the summary of an applied batch.
These headers are frozen since 0.1 (ADR 0023) and stable (SemVer, PLAN 5.9). The additions of
0.4 for label_propagation (M10; reviewed and frozen at the end of M10b, ADR 0109) are part of
the stable tier from 0.4.0 (the author’s decision of 2026-11-18 on AD15, GOVERNANCE.md):
graph::with_capacity, the slot and slack rows (row_layout::slotted and slack,
Row layouts, vertex batches and capacities), vertex_status, graph_view::status and row_end,
graph::num_active_vertices, batch_semantics::net_effect() (and as_net_effect), the vertex
operations of edge_batch (insert_vertex, delete_vertex and their read-back
insert_vertices(), insert_vertex_labels(), delete_vertices()), the apply_summary fields
dropped_insertions, relocated_rows and compactions, and the float instantiations of the graph
(weight_t = float). Their Python counterparts are stable from 0.4.0 too (Graph.with_capacity,
Graph.vertex_status(), dyng.VertexStatus, the vertex arrays of EdgeBatch, the float32 graph
classes and the weight_dtype keywords; Python API).
-
enum class dyng::row_layout : std::uint8_t#
Storage layout of the rows of a graph.
Values:
-
enumerator compact#
exact CSR; a batch rebuilds the touched rows (the only layout in 0.1)
-
enumerator slotted#
fixed per-vertex slot ranges and a row end per vertex (DynLP’s device graph; 0.4): built by graph::with_capacity(), it takes vertex batches under batch_semantics::net_effect(). Only label_propagation reads it; every other algorithm refuses it (not_supported_error).
-
enumerator slack#
per-row headroom with a tail region for streams without known capacities (0.4, ADR 0103): built by graph::with_capacity() from empty, partial or full capacity hints, each row gets ceil(k * (1 + headroom)) slots for its k expected entries; a row that overflows moves to the tail of the slot arena with its entries in order, and a batch compacts the rows when their dead slots outnumber the owned ones. Vertex batches under batch_semantics::net_effect() (with allow_vertex_growth if wanted). Only label_propagation reads it; every other algorithm refuses it (not_supported_error).
-
enumerator compact#
-
enum class dyng::row_order : std::uint8_t#
Order of the neighbours inside a row.
Values:
-
enumerator sorted#
rows sorted by neighbour id (stable: parallel edges keep their relative order)
-
enumerator append#
surviving edges keep their order; new edges are appended to their row (MOSP)
-
enumerator sorted#
-
enum class dyng::multi_edges : std::uint8_t#
Whether parallel edges (several (u,v) in one row) may exist.
Values:
-
enumerator forbid#
a simple graph: duplicate (u,v) in the input are merged (the last one wins)
-
enumerator allow#
parallel edges are kept; deletions and upserts act on the first (u,v) in the row
-
enumerator forbid#
-
enum class dyng::vertex_status : std::uint8_t#
The state of a vertex of a graph with vertex batches (row_layout::slotted; 0.4).
A vertex of graph::with_capacity() starts inactive; a batch’s insertion makes it active, a deletion makes it deleted. Ids are single-use: a deleted vertex never becomes active again, and its row keeps its entries (rows are never compacted), which every reader skips (an entry counts only when both of its endpoints are active). The enumerators are compared by name: O’s (LabelPropagation-CUDA’s) VertexStatus maps by name, never by value (ADR 0069), and a seeded vertex (O’s VERTEX_GROUND_TRUTH) is active (its class is the result’s seed label).
Values:
-
enumerator active#
in the graph
-
enumerator deleted#
removed by a batch (or retired by a deletion before it was ever inserted)
-
enumerator inactive#
never inserted yet
-
enumerator active#
-
std::string_view dyng::to_string(row_layout layout) noexcept#
The lower-case name of a row layout (“compact”, “slotted”, “slack”).
- Parameters:
layout – [in] The layout.
- Returns:
A static string naming
layout(the enumerator’s name).
-
std::string_view dyng::to_string(row_order order) noexcept#
The lower-case name of a row order (“sorted”, “append”).
- Parameters:
order – [in] The order.
- Returns:
A static string naming
order(the enumerator’s name).
-
std::string_view dyng::to_string(multi_edges rule) noexcept#
The lower-case name of a parallel-edge rule (“forbid”, “allow”).
- Parameters:
rule – [in] The rule.
- Returns:
A static string naming
rule(the enumerator’s name).
-
std::string_view dyng::to_string(batch_semantics::existing_insert rule) noexcept#
The lower-case name of an existing-edge insertion rule (“upsert”, “error”, “ignore”).
- Parameters:
rule – [in] The rule.
- Returns:
A static string naming
rule(the enumerator’s name).
-
std::string_view dyng::to_string(batch_semantics::missing_delete rule) noexcept#
The lower-case name of a missing-edge deletion rule (“ignore”, “error”).
- Parameters:
rule – [in] The rule.
- Returns:
A static string naming
rule(the enumerator’s name).
-
std::string_view dyng::to_string(batch_semantics::self_loop rule) noexcept#
The lower-case name of a self-loop rule (“keep”, “drop”, “error”).
- Parameters:
rule – [in] The rule.
- Returns:
A static string naming
rule(the enumerator’s name).
-
struct apply_summary#
- #include <dyng/graph/apply_summary.hpp>
Counters returned by graph::apply() and contained in every algorithm’s stats.
All counters are deterministic. For an undirected graph every batch edge counts once per stored direction.
Public Members
-
std::int64_t inserted_edges = 0#
insertions that added a new edge to a row
-
std::int64_t updated_edges = 0#
insertions that overwrote an existing edge (upsert)
-
std::int64_t deleted_edges = 0#
deletions that removed an edge
-
std::int64_t ignored_deletions = 0#
deletions of edges that did not exist
-
std::int64_t dropped_self_loops = 0#
self-loop operations skipped (self_loop::drop)
-
std::int64_t cancelled_pairs = 0#
insert/delete pairs cancelled (set semantics; from M2)
-
std::int64_t inserted_vertices = 0#
vertices added (explicitly or by vertex growth)
-
std::int64_t deleted_vertices = 0#
vertices removed (active before the batch)
-
std::int64_t num_vertices_after = 0#
the vertex count after the batch
-
std::int64_t ignored_insertions = 0#
insertions of existing edges left unchanged (ignore)
-
std::int64_t dropped_insertions = 0#
Insertions not applied because an endpoint is not active after the batch (batch_semantics::net_effect(); 0.4).
-
std::int64_t relocated_rows = 0#
Rows moved to the tail of the slot arena because the batch overflowed them (row_layout::slack; 0.4).
-
std::int64_t compactions = 0#
Compactions of the rows the batch ran (row_layout::slack: 0 or 1; 0.4). A compaction rewrites the rows in vertex order without the entries of deleted vertices, which changes the order of a row’s live entries in the slots.
-
std::int64_t inserted_edges = 0#
-
template<typename vertex_t, typename edge_t, typename weight_t>
struct csr_view# - #include <dyng/graph/csr.hpp>
A non-owning description of a CSR graph: row offsets, neighbours, weight columns.
Rows are indexed by source for out-edges and by destination for in-edges (the transposed graph). The arrays may live in any memory space; element access needs a host-accessible space.
- Template Parameters:
vertex_t – Vertex id type.
edge_t – Edge offset type.
weight_t – Weight type.
Public Functions
-
inline vertex_t num_vertices() const noexcept#
Number of rows.
- Returns:
row_ptr.size() - 1, or 0 for an empty view.
-
inline array_view<const weight_t> weight_column(int k) const#
The weights of one objective, one per edge in row order.
- Parameters:
k – [in] Objective in [0, num_weights).
- Throws:
invalid_argument_error – if
kis out of range.- Returns:
A view of num_edges() weights.
Public Members
-
array_view<const edge_t> row_ptr#
num_vertices() + 1 offsets, row_ptr[0] == 0
-
array_view<const vertex_t> col_ind#
the neighbour of each edge, in row order
-
array_view<const weight_t> weights#
num_weights columns of num_edges() values each
-
int num_weights = 0#
number of weight columns (0: unweighted)
-
template<typename vertex_t, typename edge_t, typename weight_t>
struct csr# - #include <dyng/graph/csr.hpp>
An owning host CSR graph with objective-major weight columns.
A plain aggregate: the fields may be filled directly. graph::from_csr() validates it.
- Template Parameters:
vertex_t – Vertex id type.
edge_t – Edge offset type.
weight_t – Weight type.
Public Functions
-
inline vertex_t num_vertices() const noexcept#
Number of rows.
- Returns:
row_ptr.size() - 1, or 0 if row_ptr is empty.
-
inline const weight_t &weight(edge_t e, int k) const noexcept#
The weight of one edge in one column (unchecked).
- Parameters:
e – [in] Edge index in [0, num_edges()).
k – [in] Objective in [0, num_weights).
- Returns:
weights[k * num_edges() + e].
Public Members
-
std::vector<edge_t> row_ptr#
num_vertices() + 1 offsets, row_ptr[0] == 0
-
std::vector<weight_t> weights#
num_weights columns of num_edges() values each
-
int num_weights = 0#
number of weight columns (0: unweighted)
-
template<typename vertex_t, typename weight_t>
struct edge_list_view# - #include <dyng/graph/edge_list.hpp>
A non-owning edge list: parallel arrays of sources, destinations and weights.
- Template Parameters:
vertex_t – Vertex id type.
weight_t – Weight type.
Public Functions
-
inline std::size_t num_edges() const noexcept#
Number of edges.
- Returns:
src.size().
Public Members
-
array_view<const vertex_t> src#
source of each edge
-
array_view<const vertex_t> dst#
destination of each edge
-
array_view<const weight_t> weights#
num_weights per edge, edge-major
-
int num_weights = 0#
weights per edge (0: unweighted)
-
template<typename vertex_t, typename weight_t>
struct edge_list# - #include <dyng/graph/edge_list.hpp>
An owning host edge list (COO).
- Template Parameters:
vertex_t – Vertex id type.
weight_t – Weight type.
Public Functions
-
inline std::size_t num_edges() const noexcept#
Number of edges.
- Returns:
src.size().
-
inline void add_edge(vertex_t u, vertex_t v, std::initializer_list<weight_t> w = {})#
Append one edge.
- Exception safety:
Strong: after an exception the list is unchanged.
- Parameters:
u – [in] Source.
v – [in] Destination.
w – [in] Its num_weights weights.
- Throws:
invalid_argument_error – if
wdoes not hold num_weights values.out_of_memory_error – if the arrays cannot grow.
-
inline edge_list_view<vertex_t, weight_t> view() const noexcept#
A read-only view of the arrays.
- Returns:
An edge_list_view in host memory; valid while this object is alive and unmodified.
Public Members
-
int num_weights = 0#
weights per edge (0: unweighted); last, as in edge_list_view
-
template<typename vertex_t = std::int32_t, typename edge_t = std::int32_t, typename weight_t = std::int32_t>
class graph# - #include <dyng/graph/graph.hpp>
A dynamic directed (or symmetric) graph with K weight columns.
The graph owns its storage and a version counter that increases by one with every applied batch; results computed on the graph remember the version they match and the identity of the graph state (a process-wide unique value that every construction and every batch renews and clone() copies), so a result is detected as stale when it is used with another graph, or with a graph variable that was reassigned since, even if the version counters are equal. The storage belongs to the backend of the resources that created it: algorithms refuse resources of the other kind (host backends versus cuda) instead of copying the graph silently, and to_backend(res) (or clone(res)) makes a copy for other resources.
A graph built with CUDA resources has two copies of its out-edges, at least one of which is current: a host CSR and a resident device copy (one weight column per objective), uploaded on first use. The in-edges of the device copy are built on the device only when an engine needs them (sssp does; cycle_count reads the out-edges only). A batch takes one of two paths (ADR 0020, docs/adr/0020-resident-device-graph-and-one-step-0.md):
the device merge: when the device copy is resident, the batch semantics is batch_semantics::set() (as_sets), the graph has no weight columns and 32-bit vertex ids, and the resources are CUDA resources of the graph’s device, the normalized batch is merged into the sorted rows on the device (CycleEnumeration-GPU’s build_next_rows_kernel). The device copy becomes the new state and the host CSR is stale until something reads it: view(), to_csr(), check_integrity() and clone() download it once. Step 0 of the next batch reads the device copy, so a chain of batches never downloads the graph.
the host apply, in every other case: the batch is applied to the host CSR (as MOSP-CUDA applies it) and the device copy is dropped, then uploaded again on first use. num_vertices() and num_edges() never download.
Thread safety. A graph is not thread-safe. Calls that only read it (view(), the accessors, to_csr(), an algorithm’s compute() on it) may run concurrently with each other. A call that changes it (apply(), reserve(), an algorithm’s update(), dyng::update()) must not overlap any other call on the same graph or on a result being updated with it: two concurrent updates of one graph, or reading a result on one thread (or stream) while another updates it, are undefined unless the caller orders them (a mutex, or stream events on CUDA). Distinct graphs and results may be used concurrently through copies of one resources handle.
Instantiated for (vertex_t, edge_t, weight_t) = (int32, int32, int32), (int32, int64, int32) and (int64, int64, int32), without weights for (int32, int32, unweighted) and (int32, int64, unweighted), and with float weights for (int32, int32, float) and (int32, int64, float) (label_propagation’s similarity graphs; 0.4). A graph with weight_t = unweighted has no weight columns.
Row layouts (0.4). A graph built by from_edges() or from_csr() has row_layout::compact (every algorithm reads it). graph::with_capacity() builds a graph with row_layout::slotted: fixed per-vertex slot ranges, a row end and a state per vertex (vertex_status), and vertex batches under batch_semantics::net_effect() (LabelPropagation-CUDA’s device graph; ADR 0069), or with row_layout::slack: the same vertex batches on rows whose slots move (a row that overflows moves to the tail of the slot arena; compactions; vertex growth under allow_vertex_growth; for streams whose capacities are not known; ADR 0103). Only label_propagation reads slotted and slack rows: every other algorithm, the device merge and the upload of the compact device copy refuse them with not_supported_error (ADR 0070). The default edge offset type is int32, the originals’ type, fixed by the edge_t benchmark (ADR 0009: 64-bit offsets cost more than 3 % on the parity suites). Construction is checked: a graph whose edge count does not fit edge_t (from_edges(), or a batch that grows it past 2^31 - 1 edges with int32) throws capacity_error naming the int64 instantiation.
- Template Parameters:
vertex_t – Vertex id type (signed).
edge_t – Edge offset type (signed; int32 by default, int64 for more than 2^31 - 1 edges).
weight_t – Weight type.
Public Types
-
using view_type = graph_view<vertex_t, edge_t, weight_t>#
the view type
Public Functions
-
explicit graph(const graph_properties &props = {})#
An empty graph (no vertices) with the given properties.
- Parameters:
props – [in] The properties (see graph_properties).
- Throws:
not_supported_error – if
props.layoutis not row_layout::compact (a slotted graph is built by with_capacity()), or the batch semantics cannot be applied (batch_semantics::as_sets without deletions_first, with an upsert, or on rows that are not row_order::sorted with multi_edges::forbid; batch_semantics::net_effect() on compact rows).out_of_memory_error – if host memory cannot be allocated.
-
graph(graph &&other) noexcept#
Move constructor.
- Parameters:
other – [inout] The graph to move from; it may only be assigned to or destroyed after.
-
graph &operator=(graph &&other) noexcept#
Move assignment.
- Parameters:
other – [inout] The graph to move from; it may only be assigned to or destroyed after.
- Returns:
*this.
-
~graph()#
releases the storage
-
graph clone(const resources &res) const#
A deep copy (same properties, storage, version and state) for the resources
res.The copy belongs to the backend of
res: this is how a graph moves between the host backends and cuda (a CUDA copy uploads its device copy on first use).- Synchronization:
Blocks until the work has completed (synchronous).
- Parameters:
res – [in] Execution resources of the copy.
- Throws:
invalid_argument_error – for a moved-from graph.
out_of_memory_error – if host memory cannot be allocated.
- Returns:
The copy.
-
graph to_backend(const resources &res) const#
The graph for the backend of
res: the explicit move between the host backends and cuda that the placement errors name (a graph is never copied between them silently).In this release the same as clone(res) (a deep copy that belongs to the backend of
res; the original is unchanged), since a CUDA graph keeps its authoritative CSR on the host; ADR 0017 item 3.- Synchronization:
Blocks until the work has completed (synchronous).
- Parameters:
res – [in] Execution resources of the new graph.
- Throws:
invalid_argument_error – for a moved-from graph.
out_of_memory_error – if host memory cannot be allocated.
- Returns:
The graph for
res.
-
void reserve(const resources &res, edge_t edge_capacity)#
Pre-size the current storage (out-edges and, if stored, in-edges) for
edge_capacityedges.In this release reserve() only sizes the storage the graph holds now: the host apply() is the straight port of MOSP’s applyChangeBatch(), which builds a new CSR per batch, so the first apply() after reserve() allocates new arrays and the reserved capacity is released. It gives no guarantee against reallocation until the resident apply replaces the port (invariant I9 exempts the port until then; docs/developer/framework.md, “Budgets”). A slotted graph’s storage is fixed by with_capacity(): reserve() checks the argument and, for a slotted graph whose rows are on the device (CUDA resources; ADR 0074), sizes the device scratch of vertex batches of up to
edge_capacityedges, so that applying them allocates no append scratch; otherwise it changes nothing. The device arrays of a vertex batch’s ids and labels and the page-locked staging of its pageable arrays are not sized by reserve(): they grow on demand (the first vertex batch’s size exactly, a later larger batch with 1.5x headroom), so a stream of vertex batches of similar sizes allocates in its first two batches at most.- Synchronization:
Blocks until the work has completed (synchronous).
- Exception safety:
Strong for the contents: the edges, the version and every result’s validity are unchanged (some arrays may keep a larger capacity).
- Parameters:
res – [in] Execution resources.
edge_capacity – [in] Expected maximum number of stored edges.
- Throws:
invalid_argument_error – if
edge_capacityis negative or the graph was moved from.out_of_memory_error – if the storage cannot be allocated.
-
vertex_t num_vertices() const noexcept#
Number of vertices.
- Returns:
The vertex count (row_layout::slotted: the vertex capacity, whatever the states).
-
vertex_t num_active_vertices() const noexcept#
Number of active vertices.
- Returns:
num_vertices() for row_layout::compact (every vertex is active); for row_layout::slotted the vertices whose state is vertex_status::active.
-
edge_t num_edges() const noexcept#
Number of stored (directed) edges.
- Returns:
The edge count (an undirected edge counts twice, a self-loop once). For row_layout::slotted: the entries whose two endpoints are active (the edges of the current graph, to_csr().num_edges()), not the slots; there a self-loop counts twice (both of its half-edges are appended to its vertex’s row, as in the original).
-
int num_weights() const noexcept#
Number of weight columns (objectives).
- Returns:
K >= 0.
-
const graph_properties &properties() const noexcept#
The properties of the graph.
- Returns:
The properties given at construction (num_weights as stored).
-
bool is_directed() const noexcept#
Whether the graph is directed.
- Returns:
properties().directed.
-
bool has_transposed() const noexcept#
Whether the in-edges are stored.
- Returns:
properties().store_transposed.
-
memory_space space() const noexcept#
The memory space of the storage.
- Returns:
memory_space::device for a graph built with CUDA resources (its resident device copy; the host CSR that view() and to_csr() read is kept as well, and after a device merge downloaded lazily on the first host read, see the class description), memory_space::host otherwise.
-
std::uint64_t version() const noexcept#
The version counter.
- Returns:
0 after construction; +1 per applied batch.
-
view_type view() const#
A read-only description of the storage at the current version (host memory, also for a graph built with CUDA resources).
For a CUDA graph whose current state a device merge produced, the host CSR is downloaded first (once per state; a synchronous copy on the stream of the resources that built the state). If the in-edges are stored but not built yet for this version (they are built on first use), this call builds them (with the thread count of the resources that built the graph); it is safe to call concurrently with other read-only calls.
- Throws:
out_of_memory_error – if the in-edges must be built and memory cannot be allocated.
- Returns:
The view; invalidated by the next apply().
-
apply_summary apply(const resources &res, const edge_batch_view<vertex_t, weight_t> &batch)#
Apply a batch to the structure (and weights) of the graph.
The batch is interpreted under
properties().semantics(see batch_semantics). The in-edges of the new version are built on first use. Results computed on the previous version become stale (their update() throws stale_result_error); use the algorithms’ update() to apply a batch and keep a result current.On a CUDA graph the batch is merged on the device when the class description’s conditions hold (resident device copy, batch_semantics::set(), no weight columns, 32-bit vertex ids): the host CSR is then left stale and downloaded on the next host read. Otherwise it is applied to the host CSR and the device copy is dropped (uploaded again on first use). ADR 0020. With CUDA resources of the graph’s device, the device copy of the previous version is released in the order of the stream of
res, after the work already queued there (which may still read it), whichever stream it was built on (ADR 0120).Vertex batches (row_layout::slotted, batch_semantics::net_effect(); ADR 0069). Every check runs before anything changes: an id or edge endpoint outside [0, num_vertices()), an id listed twice in insert_vertices or twice in delete_vertices, the insertion of an id that is not inactive (ids are single-use), a label other than -1, 0 or 1, labels that do not match the insertions one to one, a labelled vertex that the batch also deletes, and edge deletions, raise their error; an append past the end of a row raises capacity_error. Then the deletions (every listed id ends deleted), the effective insertions (Ins \ Del) and the appends (in batch order, both directions, each edge whose endpoints are active after the batch; the others are counted in apply_summary::dropped_insertions). The labels are not kept by the graph: an algorithm’s result keeps them (label_propagation’s seed labels).
- Synchronization:
Blocks until the work has completed (synchronous).
- Exception safety:
Strong: the batch is validated and the next state is built completely before it replaces the current one, so a throwing apply() leaves the graph (storage, version, state identity) unchanged. Basic for a row overflow of slotted rows on CUDA (the batch is applied, the graph poisoned).
Vertex batches on CUDA (ADR 0074). A slotted graph built with CUDA resources keeps its rows on the device (LabelPropagation-CUDA’s device graph): with CUDA resources of its device, the checks above run on the host first, then the batch is copied to the device (from pinned host memory directly) and applied there (a stable radix sort of the half-edges keeps the batch order), and the host copy of the rows is stale until something reads it (view(), to_csr(), check_integrity() and clone() download it once). The one check made on the device instead is the row capacity: an append past the end of a row is dropped and raises capacity_error after the batch was applied (the basic guarantee), and the graph is poisoned: every later apply() raises capacity_error, on any resources, and check_integrity() reports it; a clone() or a to_backend() copy of a poisoned graph is poisoned too.
Vertex batches on slack rows (0.4, ADR 0103). The checks of slotted rows, with ids up to the vertex type’s limit under allow_vertex_growth (the graph grows to the largest id + 1), and no capacity check: Step 0 plans the batch’s layout step (the rows that need more slots move to the tail of the slot arena with their entries in order, or, when the slots left by moved rows would outnumber the owned ones, every row is compacted in vertex order without the entries of deleted vertices), which apply() runs after the vertex states and before the appends (apply_summary::relocated_rows, compactions); capacity_error only when the slots would not fit edge_t. On CUDA the rows stay on the device and the host keeps the layout (row starts, limits and ends); a compaction reads the kept entries back once.
- Parameters:
res – [in] Execution resources (host threads; for the device merge, CUDA resources of the graph’s device).
batch – [in] The batch (any memory space: it is read on the host, where its normalization, Step 0, runs on both paths, so arrays in device memory are copied once under res.get_copy_policy()).
- Throws:
invalid_argument_error – if an id is negative or out of range (without vertex growth), the weights do not match num_weights(), a semantics rule says error, or an array must be copied and the copy policy is copy_policy::error.
capacity_error – if the edge count after the batch does not fit edge_t, or (row_layout::slotted) an append would pass the end of its row (on CUDA found on the device: the graph is poisoned, see below).
not_supported_error – for vertex insertions or deletions on compact rows (they need with_capacity() and batch_semantics::net_effect()), and for edge deletions on slotted and slack rows.
out_of_memory_error – if host or device memory cannot be allocated.
cuda_error – if the CUDA runtime reports an error (device merge).
- Returns:
What the batch did.
-
csr_type to_csr(const resources &res) const#
A host copy of the out-edges (downloaded first, once per state, if a device merge left the host CSR of a CUDA graph stale). For row_layout::slotted: the compacted edges, the entries of each row whose two endpoints are active, in slot order (an inactive or deleted vertex has an empty row).
- Synchronization:
Blocks until the work has completed (synchronous).
- Parameters:
res – [in] Execution resources.
- Throws:
invalid_argument_error – for a moved-from graph.
out_of_memory_error – if host memory cannot be allocated.
- Returns:
The out-edge CSR with objective-major weights.
-
void check_integrity(const resources &res) const#
Check the storage invariants (offsets, ids, row order, simple graph, in-edges; for row_layout::slotted: every row inside its slots, row ends and unused slots coherent, no entry to a never-inserted vertex, inactive vertices without entries, the entries symmetric, the counts of active vertices and edges).
- Synchronization:
Blocks until the work has completed (synchronous).
- Parameters:
res – [in] Execution resources.
- Throws:
internal_error – if an invariant is broken.
Public Static Functions
-
static graph from_edges(const resources &res, edge_list_view<vertex_t, weight_t> edges, const graph_properties &props = {})#
Build a graph from an edge list.
Edges are grouped by source; inside a row they keep their input order under row_order::append and are stably sorted by destination under row_order::sorted. Under multi_edges::forbid, duplicate (u,v) are merged: the first position is kept, the last weights win. Self-loops follow
props.semantics.on_self_loop. For an undirected graph every edge (u,v) is stored in both directions. The number of weight columns is taken fromedges.- Synchronization:
Blocks until the work has completed (synchronous).
- Parameters:
res – [in] Execution resources (the graph belongs to its backend).
edges – [in] The edges (any memory space: built on the host, so arrays in device memory are copied once under res.get_copy_policy()); ids must lie in [0, edges.num_vertices).
props – [in] The properties of the new graph.
- Throws:
invalid_argument_error – if an id is out of range, the arrays disagree in size, a self-loop is present under self_loop::error, or an array must be copied and the copy policy is copy_policy::error.
capacity_error – if the number of stored edges does not fit edge_t (use the int64 edge_t instantiation).
not_supported_error – for a layout other than compact, or batch semantics that cannot be applied (as graph(const graph_properties&)).
out_of_memory_error – if host memory cannot be allocated.
- Returns:
The graph at version 0.
-
static graph from_csr(const resources &res, csr_view<vertex_t, edge_t, weight_t> csr, const graph_properties &props = {})#
Build a graph from a CSR (the out-edges).
The CSR is validated (monotone offsets from 0, neighbours in range, weight array size). Under row_order::sorted rows are stably sorted; under multi_edges::forbid duplicates are merged as in from_edges(). Self-loops follow
props.semantics.on_self_loop. For an undirected graph the CSR must already be symmetric (each direction stored). The number of weight columns is taken fromcsr. The in-edges (props.store_transposed) are built on first use, not here (the same holds for from_edges() and after apply()).- Synchronization:
Blocks until the work has completed (synchronous).
- Parameters:
res – [in] Execution resources (the graph belongs to its backend).
csr – [in] The out-edge CSR (objective-major weights; any memory space: arrays in device memory are copied to the host once under res.get_copy_policy()).
props – [in] The properties of the new graph.
- Throws:
invalid_argument_error – if the CSR is malformed, or an array must be copied and the copy policy is copy_policy::error.
not_supported_error – for a layout other than compact, or batch semantics that cannot be applied (as graph(const graph_properties&)).
out_of_memory_error – if host memory cannot be allocated.
- Returns:
The graph at version 0.
-
static graph from_csr(const resources &res, csr_type &&csr, const graph_properties &props = {})#
Build a graph from a CSR it may take over (the out-edges).
The same graph as from_csr(res, csr.view(), props). When the CSR already is what
propsask for (directed, self-loops kept or absent, rows in the requested order and without forbidden parallel edges; for example any CSR under graph_properties::mosp_compatible()), its arrays are moved into the graph instead of copied;csris then left empty. Otherwise it is left unchanged.- Synchronization:
Blocks until the work has completed (synchronous).
- Exception safety:
Strong for every error in the input (invalid_argument_error, not_supported_error):
csris unchanged, because its arrays are taken over only once they are known to be final. Basic for out_of_memory_error:csrmay have been left empty.
- Parameters:
res – [in] Execution resources (the graph belongs to its backend).
csr – [inout] The out-edge CSR (objective-major weights).
props – [in] The properties of the new graph.
- Throws:
invalid_argument_error – if the CSR is malformed.
not_supported_error – for a layout other than compact, or batch semantics that cannot be applied (as graph(const graph_properties&)).
out_of_memory_error – if host memory cannot be allocated.
- Returns:
The graph at version 0.
-
static graph with_capacity(const resources &res, vertex_t vertex_capacity, array_view<const edge_t> row_capacity, const graph_properties &props)#
An empty graph with fixed slot rows (row_layout::slotted):
vertex_capacityvertices, all inactive, vertex v owning row_capacity[v] slots (LabelPropagation-CUDA’s createDeviceGraph; the published setup of label_propagation, ADR 0069).Vertices arrive and leave with the vertex arrays of the batches (batch_semantics:: net_effect()); a batch’s edges are appended to the rows of both endpoints in batch order and never move (rows are not compacted: a deleted vertex keeps its entries, and the entries pointing to it stay, skipped by every reader). An append past a row’s capacity is refused with capacity_error before anything changes (with CUDA resources the rows are built and kept on the device, and the capacity is checked there: see apply(); ADR 0074). num_vertices() is the capacity; num_edges() counts the entries whose endpoints are both active (an undirected edge twice, as for compact rows, and a self-loop twice too: its two half-edges both land in its vertex’s row, as in the original).
In 0.4 the properties must be: layout = row_layout::slotted, directed = false, order = row_order::append, parallel_edges = multi_edges::allow (the rows are not checked for duplicates, as the original does not) and semantics = batch_semantics::net_effect(); store_transposed is ignored (the rows are symmetric). num_weights must be 1 (0 for weight_t = unweighted).
row_layout::slack (0.4, ADR 0103). The same properties with layout = row_layout::slack (and batch_semantics::net_effect() with allow_vertex_growth set or not) build slack rows:
row_capacityis a hint and may be empty or shorter than vertex_capacity (the missing rows have none); row v gets ceil(row_capacity[v] * (1 + props.headroom)) slots. A batch never overflows a slack row: a row that needs more slots moves to the end of the slot arena with ceil(k * (1 + headroom)) slots for its k entries and keeps them in order (apply_summary:: relocated_rows), and when the slots left by moved rows outnumber the slots the rows own the batch compacts every row in vertex order without the entries of deleted vertices (apply_summary::compactions); both happen inside apply(), before the batch’s appends. Under allow_vertex_growth an id at or beyond num_vertices() grows the graph (the new vertices inactive). capacity_error comes only when the slots do not fit edge_t.- Synchronization:
Blocks until the work has completed (synchronous).
- Parameters:
res – [in] Execution resources (the graph belongs to their backend).
vertex_capacity – [in] The number of vertices (>= 0).
row_capacity – [in] The slots of each vertex (>= 0 each; any memory space: copied to the host once under res.get_copy_policy()), e.g. its degree in the full graph (generators::vertex_arrival_stream::row_capacity); for slack rows the expected entries of the first vertices (any number up to vertex_capacity, or none).
props – [in] The properties (see above).
- Throws:
invalid_argument_error – if
vertex_capacityis negative,row_capacitydoes not hold vertex_capacity values (slotted rows; more than vertex_capacity for slack rows) or one is negative, num_weights is not 1 (0 for unweighted),props.layoutis row_layout::compact, the headroom of slack rows is not in [0, 16], or an array must be copied and the copy policy is copy_policy::error.capacity_error – if the sum of the capacities (with the headroom of slack rows) does not fit edge_t (use the int64 edge_t instantiation).
not_supported_error – for any property the 0.4 slotted and slack rows do not support (the message names it).
out_of_memory_error – if host memory cannot be allocated.
- Returns:
The graph at version 0, every vertex inactive and every row empty.
-
struct batch_semantics#
- #include <dyng/graph/graph_properties.hpp>
How a batch of edge changes is interpreted.
The default-constructed value equals upsert_last_wins(), the semantics of MOSP’s applyChangeBatch():
deletions first, in batch order; each removes the FIRST remaining (u,v) of row u;
then insertions in batch order; an insertion of an existing (u,v) overwrites the weights of the first remaining (u,v) (so the last insertion of a pair wins), otherwise the edge is appended to row u (or merged into it under row_order::sorted).
Public Types
-
enum class existing_insert : std::uint8_t#
What an insertion of an edge that already exists does.
Values:
-
enumerator upsert#
overwrite the weights of the first existing (u,v)
-
enumerator error#
throw invalid_argument_error
-
enumerator ignore#
leave the existing edge unchanged
-
enumerator upsert#
-
enum class missing_delete : std::uint8_t#
What a deletion of an edge that does not exist does.
Values:
-
enumerator ignore#
nothing (counted in apply_summary::ignored_deletions)
-
enumerator error#
throw invalid_argument_error
-
enumerator ignore#
-
enum class self_loop : std::uint8_t#
What an insertion or deletion of a self-loop (u,u) does.
Values:
-
enumerator keep#
treat it like any other edge (MOSP)
-
enumerator drop#
skip it (counted in apply_summary::dropped_self_loops)
-
enumerator error#
throw invalid_argument_error
-
enumerator keep#
Public Members
-
existing_insert on_existing_insert = existing_insert::upsert#
insertion of an existing edge
-
missing_delete on_missing_delete = missing_delete::ignore#
deletion of a missing edge
-
bool deletions_first = true#
true: deletions, then insertions; false: the reverse
-
bool allow_vertex_growth = true#
an insertion naming v >= num_vertices grows the vertex set
-
bool as_sets = false#
true: the deletions and the insertions are read as two SETS (Step 0 of set()).
Before anything is applied, each list is sorted by (source, destination) and deduplicated (the first insertion of a pair in batch order supplies its weights); deletions of edges that do not exist and insertions of edges that exist are no-ops and leave the lists, except that an edge the batch both deletes and inserts stays in both lists (it is removed, then added back; apply_summary::cancelled_pairs counts these pairs). The two lists, in this order, are the net structural change the algorithms see (for example the change edges of cycle_count, whose position in the sorted list is their ownership id). The switches above keep their meaning:
on_missing_deleteandon_existing_insertdecide what the no-ops do (ignore or error),on_self_loopwhat self-loops do, andallow_vertex_growthwhether insertions may name new vertices.Not supported with as_sets:
on_existing_insert = upsert(an upsert of the weights of an existing edge is not a structural change; delete and re-insert the edge to change its weights),deletions_first = false, and rows that are not row_order::sorted with multi_edges::forbid (the lists are merged into the sorted rows of a simple graph). A graph constructed with such properties throws not_supported_error at construction.
-
bool as_net_effect = false#
true: a batch is read as its net effect on the VERTEX set (DynLP’s vertex batches; net_effect() sets it; 0.4).
The batch inserts the vertices Ins (edge_batch_view::insert_vertices, each with an optional seed label) and deletes Del (delete_vertices); its effect is Ins \ Del, in list order, and Del ∩ V_t: an id in both never enters the graph, and every id in Del ends deleted (deleting an id that was never inserted retires it). Ids are single-use: an id inserted, or named in a deletion, before cannot be inserted again. The batch’s edges (insert_src / insert_dst / insert_weights) are appended to the rows of both endpoints in batch order, each edge whose two endpoints are active after the batch; any other edge is dropped (and counted). Edge deletions are not supported. Only graphs with row_layout::slotted (graph::with_capacity()) take these semantics; graph::with_capacity() requires exactly net_effect().
Public Static Functions
-
static inline constexpr batch_semantics upsert_last_wins() noexcept#
MOSP applyChangeBatch() / updateGraphCSR() semantics (the default).
- Returns:
Upsert, ignore missing deletions, keep self-loops, deletions first, vertex growth.
-
static inline constexpr batch_semantics set() noexcept#
CycleEnumeration-GPU prepare_batch() / apply_batch() semantics: a batch is two sets.
as_sets with: insertions of existing edges and deletions of missing edges ignored (dropped from the normalized batch), self-loops dropped, deletions first, vertex growth. The graph after the batch has the edges (E minus Del) plus Ins, without self-loops; the normalized batch equals the original’s prepare_batch() exactly.
- Returns:
The set semantics.
-
static inline constexpr batch_semantics net_effect() noexcept#
LabelPropagation-CUDA’s vertex batches (DynLP’s runDynLP / launchAppendEdges): the net effect of each batch on the vertex set, its edges appended (see as_net_effect).
as_net_effect with: self-loops kept, deletions first (an id in both lists ends deleted), no vertex growth (the vertices are the capacity given to graph::with_capacity()). The edge-level switches (on_existing_insert, on_missing_delete) do not apply: every live edge of the batch is appended (parallel edges are kept) and edge deletions are refused. Only a graph with row_layout::slotted takes it (0.4).
- Returns:
The net-effect semantics.
-
struct graph_properties#
- #include <dyng/graph/graph_properties.hpp>
The properties of a graph: direction, stored in-edges, weights, layout, row order, multigraph switch and batch semantics.
Public Members
-
bool directed = true#
false: stored symmetric; a batch edge (u,v) changes both
-
bool store_transposed = true#
keep the in-edges (CSC, built on first use); sssp, mosp and cycle_count need them
-
int num_weights = 1#
Number of weight columns (objectives); 0 for an unweighted graph. graph::from_edges() and graph::from_csr() take the number of columns from their input and overwrite this field.
-
row_layout layout = row_layout::compact#
storage layout of the rows
-
double headroom = 0.125#
Spare capacity of row_layout::slack: a row gets ceil(k * (1 + headroom)) slots for its k expected entries (in [0, 16]; ignored by the other layouts).
-
multi_edges parallel_edges = multi_edges::forbid#
the general default: a simple graph
-
batch_semantics semantics = batch_semantics::upsert_last_wins()#
how batches are applied
Public Static Functions
-
static inline constexpr graph_properties mosp_compatible() noexcept#
Byte parity with MOSP’s CSR: append order, parallel edges allowed, upsert_last_wins.
- Returns:
Directed, transposed stored, compact rows, row_order::append, multi_edges::allow.
-
static inline constexpr graph_properties cycle_enum_compatible() noexcept#
Parity with CycleEnumeration-GPU’s DirectedGraph: sorted rows of a simple graph and set() batch semantics.
A graph built with these properties from the same edges has the CSR of the original’s build_directed_graph(), and every applied batch gives the CSR of its apply_batch() (byte for byte, row offsets and neighbours).
- Returns:
Directed, transposed stored, compact rows, row_order::sorted, multi_edges::forbid, batch_semantics::set(), no weight columns.
-
bool directed = true#
-
template<typename vertex_t, typename edge_t, typename weight_t>
struct graph_view# - #include <dyng/graph/graph_view.hpp>
A read-only description of the storage of a graph at one version.
A view is invalidated by the next graph::apply() (compare
versionwith graph::version()). For row_layout::compact,outis the exact out-edge CSR andinthe in-edge CSR (the transposed graph, rows indexed by destination, each row listing sources in increasing order of their out-edge position).For row_layout::slotted (graph::with_capacity()),
outdescribes the slot storage: vertex v owns the slots [out.row_ptr[v], out.row_ptr[v + 1]) and its entries are the slots up to row_end[v]; the unused slots hold column -1 and weight 0. An entry is an edge of the graph only when both of its endpoints are active (status): a deleted vertex keeps its entries and the entries pointing to it stay in place.inis empty (the graph is undirected and stores each edge in both rows). graph::to_csr() returns the compacted edges.For row_layout::slack (0.4, ADR 0103)
outdescribes the slot arena: row v’s entries are [out.row_ptr[v], row_end[v]) as for slotted rows, out.row_ptr[n] is the arena’s size, and a row that overflowed was moved to the tail of the arena, so out.row_ptr is not monotone and out.row_ptr[v + 1] is not the end of row v’s slots (the slots between rows hold -1 / 0). A moved row keeps its entries in order; a compaction rewrites every row in vertex order without the entries of deleted vertices, which moves a row’s live entries to other slots (so an engine that sums a row in lanes by slot position may sum it in another order after a compaction).- Template Parameters:
vertex_t – Vertex id type.
edge_t – Edge offset type.
weight_t – Weight type.
Public Functions
-
inline edge_t num_edges() const noexcept#
Number of stored (directed) edges.
- Returns:
out.num_edges(): for row_layout::slotted the number of slots (graph::num_edges() counts the edges).
-
inline int num_weights() const noexcept#
Number of weight columns.
- Returns:
out.num_weights.
Public Members
-
bool directed = true#
false: every edge is stored in both directions
-
row_layout layout = row_layout::compact#
the storage layout of the rows
-
std::uint64_t version = 0#
the graph version this view describes
-
array_view<const vertex_status> status#
Per vertex its state (row_layout::slotted and slack; empty for row_layout::compact, whose vertices are all active).
-
array_view<const edge_t> row_end#
Per vertex the end of its entries in
out(row_layout::slotted and slack; empty for row_layout::compact, whose rows end at out.row_ptr[v + 1]).