From d995ffd3b587c8bfd7b574b3d56ce5f9b8b56e0a Mon Sep 17 00:00:00 2001 From: Guillaume Dalle <22795598+gdalle@users.noreply.github.com> Date: Thu, 6 Apr 2023 09:30:14 +0200 Subject: [PATCH] Document default direction (`:both`) in `laplacian_matrix` and others (#41) Partially solves #24 without breaking backwards compatibility --- src/overrides.jl | 6 +++--- test/overrides.jl | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/overrides.jl b/src/overrides.jl index fdb6325..d767bf6 100644 --- a/src/overrides.jl +++ b/src/overrides.jl @@ -1,7 +1,7 @@ """ degree_matrix(g, T; dir) -Construct the weighted diagonal degree matrix, filled with element type `T` and considering edge direction `dir ∈ [:in, :out, :both]`. +Construct the weighted diagonal degree matrix, filled with element type `T` and considering edge direction `dir ∈ [:in, :out, :both]` (default is `:out`). """ function degree_matrix( g::AbstractSimpleWeightedGraph, T::DataType=weighttype(g); dir::Symbol=:out @@ -25,7 +25,7 @@ end """ Graphs.adjacency_matrix(g, T; dir) -Construct the weighted adjacency matrix, filled with element type `T` and considering edge direction `dir ∈ [:in, :out, :both]`. +Construct the weighted adjacency matrix, filled with element type `T` and considering edge direction `dir ∈ [:in, :out, :both]` (default is `:out`). """ function Graphs.adjacency_matrix( g::AbstractSimpleWeightedGraph, T::DataType=weighttype(g); dir::Symbol=:out @@ -40,7 +40,7 @@ end """ Graphs.laplacian_matrix(g, T; dir) -Subtract the adjacency matrix to the degree matrix, both filled with element type `T` and considering edge direction `dir ∈ [:in, :out, :both]`. +Subtract the adjacency matrix to the degree matrix, both filled with element type `T` and considering edge direction `dir ∈ [:in, :out, :both]` (unlike in Graphs.jl, default is `:out`). """ function Graphs.laplacian_matrix( g::AbstractSimpleWeightedGraph, T::DataType=weighttype(g); dir::Symbol=:out diff --git a/test/overrides.jl b/test/overrides.jl index dda32ef..ecf475c 100644 --- a/test/overrides.jl +++ b/test/overrides.jl @@ -47,8 +47,8 @@ @test degree_matrix(g, Float64; dir=:out) == degree_matrix(g, Float64; dir=:in) @test adjacency_matrix(g)[2, 4] == 0 @test adjacency_matrix(g; dir=:out) == adjacency_matrix(g; dir=:in)' - @test issymmetric(laplacian_matrix(g)) - @test laplacian_matrix(g, Float64) ≈ g3_l + @test issymmetric(laplacian_matrix(g; dir=:out)) + @test laplacian_matrix(g, Float64; dir=:out) ≈ g3_l @test g[1:3] == SimpleWeightedGraph{eltype(g),weighttype(g)}(path_graph(3)) gx = copy(g) add_edge!(gx, 2, 3, 99) @@ -74,8 +74,8 @@ @test_throws DomainError degree_matrix(g, dir=:other) @test @inferred(adjacency_matrix(g, Int64)) == adjacency_matrix(g, Int64; dir=:out) @test adjacency_matrix(g; dir=:out) == adjacency_matrix(g; dir=:in)' - @test !issymmetric(laplacian_matrix(g)) - @test laplacian_matrix(g, Float64) ≈ g5_l + @test !issymmetric(laplacian_matrix(g; dir=:out)) + @test laplacian_matrix(g, Float64; dir=:out) ≈ g5_l @test @inferred(pagerank(g))[3] ≈ 0.2266 atol = 0.001 @test length(@inferred(pagerank(g))) == nv(g) @test_throws ErrorException pagerank(g, 2)