Skip to content

Commit 0636459

Browse files
willow-ahrenssbromberger
authored andcommitted
added convenience constructors to drop weights. (#50)
1 parent 5d76196 commit 0636459

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed

src/simpleweighteddigraph.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ function SimpleWeightedDiGraph(i::AbstractVector{T}, j::AbstractVector{T}, v::Ab
7171
SimpleWeightedDiGraph{T, U}(sparse(j, i, v, m, m, combine); permute=false)
7272
end
7373

74+
LightGraphs.SimpleDiGraph(g::SimpleWeightedDiGraph) = SimpleDiGraph(g.weights)
75+
7476
edgetype(::SimpleWeightedDiGraph{T, U}) where T<:Integer where U<:Real = SimpleWeightedGraphEdge{T,U}
7577

7678
edges(g::SimpleWeightedDiGraph) = (SimpleWeightedEdge(x[2], x[1], x[3]) for x in zip(findnz(g.weights)...))

src/simpleweightedgraph.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ function SimpleWeightedGraph(i::AbstractVector{T}, j::AbstractVector{T}, v::Abst
8787
SimpleWeightedGraph{T, U}(s)
8888
end
8989

90+
LightGraphs.SimpleGraph(g::SimpleWeightedGraph) = SimpleGraph(g.weights)
91+
9092
edgetype(::SimpleWeightedGraph{T, U}) where T<:Integer where U<:Real= SimpleWeightedGraphEdge{T,U}
9193

9294
edges(g::SimpleWeightedGraph) = (SimpleWeightedEdge(x[1], x[2], x[3]) for x in zip(findnz(triu(g.weights))...))

test/simpleweightedgraph.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,4 +219,7 @@ using SimpleWeightedGraphs
219219
@test s.weights[1,2] == 1
220220
@test s.weights[2,1] == 2
221221

222+
@test SimpleDiGraph(SimpleWeightedDiGraph(CycleGraph(4))) == SimpleDiGraph(CycleGraph(4))
223+
@test SimpleGraph(SimpleWeightedGraph(PathGraph(5))) == PathGraph(5)
224+
222225
end

0 commit comments

Comments
 (0)