From 03d8fea3d5c9f4d1b39c988422989bc31ee22789 Mon Sep 17 00:00:00 2001 From: Luis-Varona Date: Wed, 13 Aug 2025 14:48:24 -0300 Subject: [PATCH] Update _assert_graph_has_defined_s_bandwidth in utils Fixed an in the _assert_graph_has_defined_s_bandwidth function and finished the docstring. --- CHANGELOG.md | 5 +++++ src/utils.jl | 43 ++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a802b4..ed36d99 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,9 +12,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), ### Changed +- Finished the docstring for `_assert_graph_has_defined_s_bandwidth` function (#55). - Made the return type of the `_pot_kernel_1neg_eigvecs` and `_pot_nonkernel_1neg_eigvecs` functions consistent regardless of the `n` parameter passed (#51). - Finished the docstrings for `src/eigenvector_generation.jl`, fixing some minor inaccuracies along the way (#51). +### Fixed + +- Fixed an `UndefVarError` in the `_assert_graph_has_defined_s_bandwidth` function (#55). + ## [0.1.1] - 2025-08-05 ### Changed diff --git a/src/utils.jl b/src/utils.jl index eb170b4..f425d75 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -257,7 +257,45 @@ graphs without self-loops, so this function checks that `g` satisfies these cond - `DomainError`: if `g` is directed or has self-loops. # Examples -[TODO: Write here] +The Petersen graph passes the check: +```jldoctest +julia> using Graphs + +julia> g = PetersenGraph() +{10, 15} undirected simple Int64 graph + +julia> isnothing(SDiagonalizability._assert_graph_has_defined_s_bandwidth(g)) +true +``` + +This random tournament digraph fails the check: +```jldoctest +julia> using Graphs + +julia> g = random_tournament_digraph(3; seed=13) +{3, 3} directed simple Int64 graph + +julia> SDiagonalizability._assert_graph_has_defined_s_bandwidth(g) +ERROR: DomainError with SimpleDiGraph{Int64}(3, [[2, 3], [3], Int64[]], [Int64[], [1], [1, 2]]): +S-bandwidth is not defined for directed graphs +[...] +``` + +This multigraph with self-loops fails the check: +```jldoctest +julia> using Graphs + +julia> g = SimpleGraph(3) +{3, 0} undirected simple Int64 graph + +julia> add_edge!(g, 1, 1) +true + +julia> SDiagonalizability._assert_graph_has_defined_s_bandwidth(g) +ERROR: DomainError with SimpleGraph{Int64}(1, [[1], Int64[], Int64[]]): +S-bandwidth is not defined for multigraphs; got a graph with self-loops +[...] +``` # Notes At first blush, it may seem as though the choice of `DomainError` over something like @@ -279,8 +317,7 @@ function _assert_graph_has_defined_s_bandwidth(g::AbstractGraph) if has_self_loops(g) throw( DomainError( - graph, - "S-bandwidth is not defined for multigraphs; got a graph with self-loops", + g, "S-bandwidth is not defined for multigraphs; got a graph with self-loops" ), ) end