Skip to content

Commit ff89d57

Browse files
committed
merge master
2 parents 6eb927d + 19c3d81 commit ff89d57

File tree

8 files changed

+58
-35
lines changed

8 files changed

+58
-35
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ os:
44
- linux
55
# - osx
66
julia:
7-
- 0.6
7+
-1.0
88
- nightly
99

1010
matrix:
@@ -29,4 +29,4 @@ git:
2929
# - julia -e 'Pkg.clone(pwd()); Pkg.build("StaticGraphs"); Pkg.test("StaticGraphs"; coverage=true)'
3030
after_success:
3131
# push coverage results to Codecov
32-
- julia -e 'cd(Pkg.dir("StaticGraphs")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'
32+
- julia -e 'using Pkg; cd(Pkg.dir("StaticGraphs")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'

REQUIRE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
julia 0.6
2-
LightGraphs 0.11
1+
julia 1.0
2+
LightGraphs 1.0
33
JLD2

src/StaticGraphs.jl

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ using LightGraphs
44
using JLD2
55

66
import Base:
7-
convert, eltype, show, ==, Pair, Tuple, in, copy, length, start, next, done, issubset, zero, one,
7+
convert, eltype, show, ==, Pair, Tuple, in, copy, length, issubset, zero, one,
88
size, getindex, setindex!, length, IndexStyle
99

1010
import LightGraphs:
11-
_NI, _insert_and_dedup!, AbstractEdge, AbstractEdgeIter,
11+
_NI, AbstractEdge, AbstractEdgeIter,
1212
src, dst, edgetype, nv, ne, vertices, edges, is_directed,
13-
has_vertex, has_edge, in_neighbors, out_neighbors,
13+
has_vertex, has_edge, inneighbors, outneighbors,
1414
indegree, outdegree, degree, insorted, squash,
1515

1616
AbstractGraphFormat, loadgraph, savegraph
@@ -57,7 +57,7 @@ indtype(g::AbstractStaticGraph{T, U}) where T where U = U
5757
eltype(x::AbstractStaticGraph) = vectype(x)
5858

5959
function show(io::IO, g::AbstractStaticGraph)
60-
dir = is_directed(g)? "directed" : "undirected"
60+
dir = is_directed(g) ? "directed" : "undirected"
6161
print(io, "{$(nv(g)), $(ne(g))} $dir simple static {$(vectype(g)), $(indtype(g))} graph")
6262
end
6363

@@ -69,23 +69,22 @@ end
6969

7070
@inline function fadj(g::AbstractStaticGraph, s::Integer)
7171
r = _fvrange(g, s)
72-
return fastview(g.f_vec, r)
72+
return view(g.f_vec, r)
7373
end
7474

7575
nv(g::AbstractStaticGraph{T, U}) where T where U = T(length(g.f_ind) - 1)
7676
vertices(g::AbstractStaticGraph{T, U}) where T where U = one(T):nv(g)
7777

78-
7978
has_edge(g::AbstractStaticGraph, e::AbstractStaticEdge) =
80-
insorted(dst(e), out_neighbors(g, src(e)))
79+
insorted(dst(e), outneighbors(g, src(e)))
8180

8281
edgetype(g::AbstractStaticGraph{T}) where T = StaticEdge{T}
8382
edges(g::AbstractStaticGraph) = StaticEdgeIter(g)
8483

8584
has_vertex(g::AbstractStaticGraph, v::Integer) = v in vertices(g)
8685

87-
out_neighbors(g::AbstractStaticGraph, v::Integer) = fadj(g, v)
88-
in_neighbors(g::AbstractStaticGraph, v::Integer) = badj(g, v)
86+
outneighbors(g::AbstractStaticGraph, v::Integer) = fadj(g, v)
87+
inneighbors(g::AbstractStaticGraph, v::Integer) = badj(g, v)
8988

9089
zero(g::T) where T<:AbstractStaticGraph = T()
9190

@@ -97,6 +96,7 @@ include("staticgraph.jl")
9796
include("staticdigraph.jl")
9897
include("persistence.jl")
9998

99+
100100
const SGraph = StaticGraph
101101
const SDiGraph = StaticDiGraph
102102

@@ -105,5 +105,6 @@ const StaticEdgeIter{G} = LightGraphs.SimpleGraphs.SimpleEdgeIter{G}
105105
eltype(::Type{StaticEdgeIter{StaticGraph{T, U}}}) where T where U = StaticGraphEdge{T}
106106
eltype(::Type{StaticEdgeIter{StaticDiGraph{T, U}}}) where T where U = StaticDiGraphEdge{T}
107107

108+
include("overrides.jl")
108109

109110
end # module

src/overrides.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
function adjacency_matrix(g::StaticGraph)
2+
SparseMatrixCSC{Bool,UInt32}(nv(g), nv(g), g.f_ind, g.f_vec, ones(Bool, ne(g)*2))
3+
end
4+
5+
function adjacency_matrix(g::StaticDiGraph)
6+
SparseMatrixCSC{Bool,UInt32}(nv(g), nv(g), g.f_ind, g.f_vec, ones(Bool, ne(g)))
7+
end

src/staticdigraph.jl

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ end
1818

1919
@inline function badj(g::StaticDiGraph, s)
2020
r = _bvrange(g, s)
21-
return fastview(g.b_vec, r)
21+
return view(g.b_vec, r)
2222
end
2323

2424
ne(g::StaticDiGraph{T, U}) where T where U = U(length(g.f_vec))
@@ -31,8 +31,8 @@ function StaticDiGraph(nvtx::I, f_ss::AbstractVector{F}, f_ds::AbstractVector{D}
3131
push!(f_ind, length(f_ss)+1)
3232
b_ind = [searchsortedfirst(b_ss, x) for x in 1:nvtx]
3333
push!(b_ind, length(b_ss)+1)
34-
T = mintype(f_ds)
35-
U = mintype(f_ind)
34+
T = mintype(maximum(f_ds))
35+
U = mintype(f_ind[end])
3636
return StaticDiGraph{T, U}(
3737
convert(Vector{T}, f_ds),
3838
convert(Vector{U}, f_ind),
@@ -52,6 +52,7 @@ function StaticDiGraph(nvtx::I, f_sd::Vector{Tuple{T, T}}, b_sd::Vector{Tuple{T,
5252
end
5353

5454
function StaticDiGraph(g::LightGraphs.SimpleGraphs.SimpleDiGraph)
55+
ne(g) == 0 && return StaticDiGraph(nv(g), Array{Tuple{UInt8, UInt8},1}(), Array{Tuple{UInt8, UInt8},1}())
5556
f_sd = [Tuple(e) for e in edges(g)]
5657
b_sd = sort([Tuple(reverse(e)) for e in edges(g)])
5758

@@ -62,6 +63,15 @@ function StaticDiGraph()
6263
return StaticDiGraph(UInt8[], UInt8[1], UInt8[], UInt8[1])
6364
end
6465

66+
function StaticDiGraph{T, U}(s::StaticDiGraph) where T <: Integer where U <: Integer
67+
new_fvec = T.(s.f_vec)
68+
new_find = U.(s.f_ind)
69+
new_bvec = T.(s.b_vec)
70+
new_bind = U.(s.b_ind)
71+
return StaticDiGraph(new_fvec, new_find, new_bvec, new_bind)
72+
end
73+
74+
6575
==(g::StaticDiGraph, h::StaticDiGraph) = g.f_vec == h.f_vec && g.f_ind == h.f_ind && g.b_vec == h.b_vec && g.b_ind == h.b_ind
6676

6777
degree(g::StaticDiGraph, v::Integer) = indegree(g, v) + outdegree(g, v)
@@ -79,4 +89,5 @@ Return `true` if `g` is a directed graph.
7989
"""
8090
is_directed(::Type{StaticDiGraph}) = true
8191
is_directed(::Type{StaticDiGraph{T}}) where T = true
92+
is_directed(::Type{StaticDiGraph{T, U}}) where T where U = true
8293
is_directed(g::StaticDiGraph) = true

src/staticgraph.jl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,17 @@ function StaticGraph(nvtx::I, ss::AbstractVector{S}, ds::AbstractVector{D}) wher
1717
(nvtx == 0 || length(ss) == 0) && return StaticGraph()
1818
f_ind = [searchsortedfirst(ss, x) for x in 1:nvtx]
1919
push!(f_ind, length(ss)+1)
20-
T = mintype(ds)
21-
U = mintype(f_ind)
20+
T = mintype(maximum(ds))
21+
U = mintype(f_ind[end])
2222
return StaticGraph{T, U}(convert(Vector{T},ds), convert(Vector{U}, f_ind))
2323
end
2424

25+
function StaticGraph{T, U}(s::StaticGraph) where T <: Integer where U <: Integer
26+
new_fvec = T.(s.f_vec)
27+
new_find = U.(s.f_ind)
28+
return StaticGraph(new_fvec, new_find)
29+
end
30+
2531
# sorted src, dst tuples
2632
function StaticGraph(nvtx::I, sd::Vector{Tuple{T, T}}) where {T<:Integer, I<:Integer}
2733
ss = [x[1] for x in sd]
@@ -30,6 +36,7 @@ function StaticGraph(nvtx::I, sd::Vector{Tuple{T, T}}) where {T<:Integer, I<:Int
3036
end
3137

3238
function StaticGraph(g::LightGraphs.SimpleGraphs.SimpleGraph)
39+
ne(g) == 0 && return StaticGraph(nv(g), Array{Tuple{UInt8, UInt8},1}())
3340
sd1 = [Tuple(e) for e in edges(g)]
3441
ds1 = [Tuple(reverse(e)) for e in edges(g)]
3542
sd = sort(vcat(sd1, ds1))

src/utils.jl

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,13 @@ end
2929
"""
3030
mintype(v)
3131
32-
Returns the minimum integer type required to fit all elements
33-
in sorted vector `v`.
34-
35-
### Implementation Notes
36-
`v` is assumed to be sorted.
32+
Returns the minimum integer type required to represent integer `v`.
3733
"""
38-
function mintype(v::AbstractVector)
34+
function mintype(v::T) where T <: Integer
3935
validtypes = [UInt8, UInt16, UInt32, UInt64, UInt128]
40-
l = v[end]
41-
for T in validtypes
42-
l <= typemax(T) && return T
36+
for U in validtypes
37+
v <= typemax(U) && return U
4338
end
44-
return eltype(v)
39+
return T
4540
end
4641

test/runtests.jl

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using StaticGraphs
22
using LightGraphs
33
using LightGraphs.SimpleGraphs
4-
using Base.Test
4+
using Test
55

66
const testdir = dirname(@__FILE__)
77

@@ -19,6 +19,7 @@ const testdir = dirname(@__FILE__)
1919
sgu = StaticGraph(gu)
2020
gempty = StaticGraph()
2121
gdempty = StaticDiGraph()
22+
@test eltype(StaticGraph{UInt128, UInt128}(sgu)) == UInt128
2223
@test sprint(show, sg) == "{5, 6} undirected simple static {UInt8, UInt8} graph"
2324
@test sprint(show, sgu) == "{5, 6} undirected simple static {UInt8, UInt8} graph"
2425
testfn(fn, args...) =
@@ -31,8 +32,8 @@ const testdir = dirname(@__FILE__)
3132
@test @inferred eltype(hu) == UInt8
3233
@test testfn(ne)
3334
@test testfn(nv)
34-
@test testfn(in_neighbors, 1)
35-
@test testfn(out_neighbors, 1)
35+
@test testfn(inneighbors, 1)
36+
@test testfn(outneighbors, 1)
3637
@test testfn(vertices)
3738
@test testfn(degree)
3839
@test testfn(degree, 1)
@@ -65,6 +66,7 @@ const testdir = dirname(@__FILE__)
6566
dgu = squash(dg)
6667
dsg = StaticDiGraph(dg)
6768
dsgu = StaticDiGraph(dgu)
69+
@test eltype(StaticDiGraph{UInt128, UInt128}(dsgu)) == UInt128
6870
@test sprint(show, dsg) == "{5, 4} directed simple static {UInt8, UInt8} graph"
6971
@test sprint(show, dsgu) == "{5, 4} directed simple static {UInt8, UInt8} graph"
7072
dhu = loadgraph(joinpath(testdir, "testdata", "pathdg-uint8.jsg"), SDGFormat())
@@ -79,8 +81,8 @@ const testdir = dirname(@__FILE__)
7981
@test @inferred eltype(dhu) == UInt8
8082
@test dtestfn(ne)
8183
@test dtestfn(nv)
82-
@test dtestfn(in_neighbors, 1)
83-
@test dtestfn(out_neighbors, 1)
84+
@test dtestfn(inneighbors, 1)
85+
@test dtestfn(outneighbors, 1)
8486
@test dtestfn(vertices)
8587
@test dtestfn(degree)
8688
@test dtestfn(degree, 1)
@@ -101,12 +103,12 @@ const testdir = dirname(@__FILE__)
101103

102104
@testset "utils" begin
103105
A = [1:5;]
104-
B = StaticGraphs.fastview(A, 2:3)
106+
B = StaticGraphs.view(A, 2:3)
105107
@test @inferred B == [2,3]
106108
B[1] = 5
107109
@test @inferred A == [1,5,3,4,5]
108110
A = ["a", "b", "c", "d"]
109-
@test @inferred StaticGraphs.fastview(A, 2:3) == ["b", "c"]
111+
@test @inferred StaticGraphs.view(A, 2:3) == ["b", "c"]
110112
end # utils
111113

112114
@testset "persistence" begin

0 commit comments

Comments
 (0)