Skip to content

Commit 3c97457

Browse files
authored
Fix issymmetric (#265)
* Fix issymmetric * Add @ traitfn * Fix @ traitfn * Wrong value for undirected * Replace src and dst with reverse
1 parent 327740b commit 3c97457

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/operators.jl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,19 @@ sparse(g::AbstractGraph) = adjacency_matrix(g)
509509

510510
length(g::AbstractGraph) = widen(nv(g)) * widen(nv(g))
511511
ndims(g::AbstractGraph) = 2
512-
issymmetric(g::AbstractGraph) = !is_directed(g)
512+
513+
@traitfn function issymmetric(g::AG) where {AG <: AbstractGraph; !IsDirected{AG}}
514+
return true
515+
end
516+
517+
@traitfn function issymmetric(g::AG) where {AG <: AbstractGraph; IsDirected{AG}}
518+
for e in edges(g)
519+
if !has_edge(g, reverse(e))
520+
return false
521+
end
522+
end
523+
return true
524+
end
513525

514526
"""
515527
cartesian_product(g, h)

test/operators.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,15 @@
203203
@test @inferred(!issymmetric(g))
204204
end
205205

206+
gx = SimpleDiGraph(4)
207+
add_edge!(gx, 1, 2)
208+
add_edge!(gx, 2, 1)
209+
add_edge!(gx, 1, 3)
210+
add_edge!(gx, 3, 1)
211+
@testset "Matrix operations: $g" for g in testdigraphs(gx)
212+
@test @inferred(issymmetric(g))
213+
end
214+
206215
nx = 20
207216
ny = 21
208217
@testset "Cartesian Product / Crosspath: $g" for g in testlargegraphs(path_graph(ny))

0 commit comments

Comments
 (0)