Skip to content

Commit 238fb8f

Browse files
authored
Merge pull request #11 from JuliaGraphs/sbromberger/julia-1.0
julia 1.0 / LG 1.0.0 compatibility
2 parents 68248ab + 75e55da commit 238fb8f

File tree

7 files changed

+23
-49
lines changed

7 files changed

+23
-49
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ os:
44
- linux
55
# - osx
66
julia:
7-
- 0.6
8-
# - nightly
7+
- 1.0
8+
- nightly
99
notifications:
1010
email: false
1111
git:
@@ -30,4 +30,4 @@ git:
3030
# - julia -e 'Pkg.clone(pwd()); Pkg.build("StaticGraphs"); Pkg.test("StaticGraphs"; coverage=true)'
3131
after_success:
3232
# push coverage results to Codecov
33-
- julia -e 'cd(Pkg.dir("StaticGraphs")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'
33+
- 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: 8 additions & 8 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,23 @@ 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

7878

7979
has_edge(g::AbstractStaticGraph, e::AbstractStaticEdge) =
80-
insorted(dst(e), out_neighbors(g, src(e)))
80+
insorted(dst(e), outneighbors(g, src(e)))
8181

8282
edgetype(g::AbstractStaticGraph{T}) where T = StaticEdge{T}
8383
edges(g::AbstractStaticGraph) = StaticEdgeIter(g)
8484

8585
has_vertex(g::AbstractStaticGraph, v::Integer) = v in vertices(g)
8686

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

9090
zero(g::T) where T<:AbstractStaticGraph = T()
9191

src/staticdigraph.jl

Lines changed: 2 additions & 1 deletion
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))
@@ -52,6 +52,7 @@ function StaticDiGraph(n_v, f_sd::Vector{Tuple{T, T}}, b_sd::Vector{Tuple{T, 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

src/staticgraph.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ function StaticGraph(n_v, sd::Vector{Tuple{T, T}}) where T <: Integer
3737
end
3838

3939
function StaticGraph(g::LightGraphs.SimpleGraphs.SimpleGraph)
40+
ne(g) == 0 && return StaticGraph(nv(g), Array{Tuple{UInt8, UInt8},1}())
4041
sd1 = [Tuple(e) for e in edges(g)]
4142
ds1 = [Tuple(reverse(e)) for e in edges(g)]
4243

src/utils.jl

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,3 @@
1-
struct UnsafeVectorView{T,U} <: AbstractVector{T}
2-
offset::U
3-
len::U
4-
ptr::Ptr{T}
5-
end
6-
7-
@inline UnsafeVectorView(parent::Union{Vector, Base.FastContiguousSubArray}, range::UnitRange) = UnsafeVectorView(start(range) - 1, length(range), pointer(parent))
8-
@inline Base.size(v::UnsafeVectorView) = (v.len,)
9-
@inline Base.getindex(v::UnsafeVectorView, idx) = unsafe_load(v.ptr, idx + v.offset)
10-
@inline Base.setindex!(v::UnsafeVectorView, value, idx) = unsafe_store!(v.ptr, value, idx + v.offset)
11-
@inline Base.length(v::UnsafeVectorView) = v.len
12-
Base.IndexStyle(::Type{V}) where V <: UnsafeVectorView = IndexLinear()
13-
14-
"""
15-
UnsafeVectorView only works for isbits types. For other types, we're already
16-
allocating lots of memory elsewhere, so creating a new SubArray is fine.
17-
This function looks type-unstable, but the isbits(T) test can be evaluated
18-
by the compiler, so the result is actually type-stable.
19-
From https://github.com/rdeits/NNLS.jl/blob/0a9bf56774595b5735bc738723bd3cb94138c5bd/src/NNLS.jl#L218.
20-
"""
21-
@inline function fastview(parent::Union{Vector{T}, Base.FastContiguousSubArray{T}}, range::UnitRange) where T
22-
if isbits(T)
23-
UnsafeVectorView(parent, range)
24-
else
25-
view(parent, range)
26-
end
27-
end
28-
291
"""
302
mintype(v)
313

test/runtests.jl

Lines changed: 7 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

@@ -30,8 +30,8 @@ const testdir = dirname(@__FILE__)
3030
@test @inferred eltype(hu) == UInt8
3131
@test testfn(ne)
3232
@test testfn(nv)
33-
@test testfn(in_neighbors, 1)
34-
@test testfn(out_neighbors, 1)
33+
@test testfn(inneighbors, 1)
34+
@test testfn(outneighbors, 1)
3535
@test testfn(vertices)
3636
@test testfn(degree)
3737
@test testfn(degree, 1)
@@ -73,8 +73,8 @@ const testdir = dirname(@__FILE__)
7373
@test @inferred eltype(dhu) == UInt8
7474
@test dtestfn(ne)
7575
@test dtestfn(nv)
76-
@test dtestfn(in_neighbors, 1)
77-
@test dtestfn(out_neighbors, 1)
76+
@test dtestfn(inneighbors, 1)
77+
@test dtestfn(outneighbors, 1)
7878
@test dtestfn(vertices)
7979
@test dtestfn(degree)
8080
@test dtestfn(degree, 1)
@@ -95,12 +95,12 @@ const testdir = dirname(@__FILE__)
9595

9696
@testset "utils" begin
9797
A = [1:5;]
98-
B = StaticGraphs.fastview(A, 2:3)
98+
B = StaticGraphs.view(A, 2:3)
9999
@test @inferred B == [2,3]
100100
B[1] = 5
101101
@test @inferred A == [1,5,3,4,5]
102102
A = ["a", "b", "c", "d"]
103-
@test @inferred StaticGraphs.fastview(A, 2:3) == ["b", "c"]
103+
@test @inferred StaticGraphs.view(A, 2:3) == ["b", "c"]
104104
end # utils
105105

106106
@testset "persistence" begin

0 commit comments

Comments
 (0)