Skip to content

Commit 5d1dac4

Browse files
simonschoellysbromberger
authored andcommitted
Deprecated some function (#71)
* deprecated some function * code coverage did not work * more fixes to get coverage running
1 parent a19aa1e commit 5d1dac4

File tree

10 files changed

+239
-182
lines changed

10 files changed

+239
-182
lines changed

.travis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ matrix:
1414
notifications:
1515
email: false
1616
# uncomment the following lines to override the default test script
17-
#script:
18-
# - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
19-
# - julia --check-bounds=yes -e 'Pkg.clone(pwd()); Pkg.build("GraphPlot"); Pkg.test("GraphPlot"; coverage=true)'
17+
script:
18+
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
19+
- julia -e 'using Pkg; Pkg.clone(pwd()); Pkg.build("GraphPlot"); Pkg.test("GraphPlot"; coverage=true)'
2020
after_success:
2121
# push coverage results to Codecov
22-
- julia -e 'cd(using Pkg; Pkg.dir("GraphPlot")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'
22+
- julia -e 'using Pkg; cd(Pkg.dir("GraphPlot")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'

src/GraphPlot.jl

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ export
1515
spring_layout,
1616
spectral_layout,
1717
shell_layout,
18-
stressmajorize_layout,
19-
graphfamous,
20-
readedgelist
18+
stressmajorize_layout
19+
20+
include("deprecations.jl")
2121

2222
# layout algorithms
2323
include("layout.jl")
@@ -29,19 +29,4 @@ include("lines.jl")
2929
include("plot.jl")
3030
include("collapse_plot.jl")
3131

32-
# read graph
33-
include("graphio.jl")
34-
35-
36-
# These functions are mappings to various graph packages.
37-
# Currently only LightGraphs is supported.
38-
_nv(g::LightGraphs.AbstractGraph) = LightGraphs.nv(g)
39-
_ne(g::LightGraphs.AbstractGraph) = LightGraphs.ne(g)
40-
_vertices(g::LightGraphs.AbstractGraph) = LightGraphs.vertices(g)
41-
_edges(g::LightGraphs.AbstractGraph) = LightGraphs.edges(g)
42-
_src_index(e::LightGraphs.Edge, g::LightGraphs.AbstractGraph) = LightGraphs.src(e)
43-
_dst_index(e::LightGraphs.Edge, g::LightGraphs.AbstractGraph) = LightGraphs.dst(e)
44-
_adjacency_matrix(g::LightGraphs.AbstractGraph) = LightGraphs.adjacency_matrix(g)
45-
_is_directed(g::LightGraphs.AbstractGraph) = LightGraphs.is_directed(g)
46-
_laplacian_matrix(g::LightGraphs.AbstractGraph) = LightGraphs.laplacian_matrix(g)
4732
end # module

src/collapse_plot.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
using GraphPlot
22

3-
function collapse_graph(g::AbstractGraph, membership::Vector{Int})
3+
function collapse_graph(g::AbstractGraph{T}, membership::Vector{Int}) where {T<:Integer}
44
nb_comm = maximum(membership)
55

66
collapsed_edge_weights = Vector{Dict{Int,Float64}}(undef, nb_comm)
77
for i=1:nb_comm
88
collapsed_edge_weights[i] = Dict{Int,Float64}()
99
end
1010

11-
for e in _edges(g)
12-
u = _src_index(e,g)
13-
v = _dst_index(e,g)
11+
for e in edges(g)
12+
u = src(e)
13+
v = dst(e)
1414
u_comm = membership[u]
1515
v_comm = membership[v]
1616

1717
# for special case of undirected network
18-
if !_is_directed(g)
18+
if !is_directed(g)
1919
u_comm, v_comm = minmax(u_comm, v_comm)
2020
end
2121

@@ -63,11 +63,11 @@ function community_layout(g::AbstractGraph, membership::Vector{Int})
6363
lx, ly
6464
end
6565

66-
function collapse_layout(g::AbstractGraph, membership::Vector{Int})
67-
lightg = LightGraphs.SimpleGraph(_nv(g))
68-
for e in _edges(g)
69-
u = _src_index(e, g)
70-
v = _dst_index(e, g)
66+
function collapse_layout(g::AbstractGraph{T}, membership::Vector{Int}) where {T<:Integer}
67+
lightg = LightGraphs.SimpleGraph(nv(g))
68+
for e in edges(g)
69+
u = src(e)
70+
v = dst(e)
7171
LightGraphs.add_edge!(lightg, u, v)
7272
end
7373
N = length(membership)

src/deprecations.jl

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
using Base: depwarn
2+
3+
4+
function _nv(g)
5+
depwarn("`GraphPlot._nv(g)` is deprectated. Use `LightGraphs.nv(g)` instead.", :_nv)
6+
return LightGraphs.nv(g)
7+
end
8+
9+
function _ne(g)
10+
depwarn("`GraphPlot._ne(g)` is deprectated. Use `LightGraphs.ne(g)` instead.", :_ne)
11+
return LightGraphs.ne(g)
12+
end
13+
14+
function _vertices(g)
15+
depwarn("`GraphPlot._vertices(g)` is deprectated. Use `LightGraphs.vertices(g)` instead.", :_vertices)
16+
return LightGraphs.vertices(g)
17+
end
18+
19+
function _edges(g)
20+
depwarn("`GraphPlot._edges(g)` is deprectated. Use `LightGraphs.edges(g)` instead.", :_edges)
21+
return LightGraphs.edges(g)
22+
end
23+
24+
function _src_index(e, g)
25+
depwarn("`GraphPlot._src_index(g)` is deprectated. Use `LightGraphs.src(e)` instead.", :_src_index)
26+
return LightGraphs.src(e)
27+
end
28+
29+
function _dst_index(e, g)
30+
depwarn("`GraphPlot._dst_index(g)` is deprectated. Use `LightGraphs.dst(e)` instead.", :_dst_index)
31+
return LightGraphs.dst(e)
32+
end
33+
34+
function _adjacency_matrix(g)
35+
depwarn("`GraphPlot._adjacency_matrix(g)` is deprectated. Use `LightGraphs.adjacency_matrix(g)` instead.", :_adjacency_matrix)
36+
return LightGraphs.adjacency_matrix(g)
37+
end
38+
39+
function _is_directed(g)
40+
depwarn("`GraphPlot._is_directed(g)` is deprectated. Use `LightGraphs.is_directed(g)` instead.", :_is_directed)
41+
return LightGraphs.is_directed(g)
42+
end
43+
44+
function _laplacian_matrix(g)
45+
depwarn("`GraphPlot._laplacian_matrix(g)` is deprectated. Use `LightGraphs.laplacian_matrix(g)` instead.", :_laplacian_matrix)
46+
return LightGraphs.laplacian_matrix(g)
47+
end
48+
49+
50+
"""
51+
read some famous graphs
52+
53+
**Paramenters**
54+
55+
*graphname*
56+
Currently, `graphname` can be one of ["karate", "football", "dolphins",
57+
"netscience", "polbooks", "power", "cond-mat"]
58+
59+
**Return**
60+
a graph
61+
62+
**Example**
63+
julia> g = graphfamous("karate")
64+
"""
65+
function graphfamous(graphname::AbstractString)
66+
depwarn("""
67+
`graphfamous` has been deprecated and will be removed in the future. Consider the package `GraphIO.jl` for loading graphs.
68+
""", :graphfamous)
69+
file = joinpath(dirname(@__DIR__), "data", graphname*".dat")
70+
readedgelist(file)
71+
end
72+
export graphfamous
73+
74+
using DelimitedFiles: readdlm
75+
"""read graph from in edgelist format"""
76+
function readedgelist(filename; is_directed::Bool=false, start_index::Int=0, delim::Char=' ')
77+
depwarn("""
78+
`graphfamous` has been deprecated and will be removed in the future. Consider the package `GraphIO.jl` for loading graphs.
79+
""", :graphfamous)
80+
es = readdlm(filename, delim, Int)
81+
es = unique(es, dims=1)
82+
if start_index == 0
83+
es = es .+ 1
84+
end
85+
N = maximum(es)
86+
if is_directed
87+
g = DiGraph(N)
88+
for i=1:size(es,1)
89+
add_edge!(g, es[i,1], es[i,2])
90+
end
91+
return g
92+
else
93+
for i=1:size(es,1)
94+
if es[i,1] > es[i,2]
95+
es[i,1], es[i,2] = es[i,2], es[i,1]
96+
end
97+
end
98+
es = unique(es, dims=1)
99+
g = Graph(N)
100+
for i=1:size(es,1)
101+
add_edge!(g, es[i,1], es[i,2])
102+
end
103+
return g
104+
end
105+
end
106+
export readedgelist

src/graphio.jl

Lines changed: 0 additions & 50 deletions
This file was deleted.

src/layout.jl

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ julia> loc_x, loc_y = random_layout(g)
2828
```
2929
3030
"""
31-
function random_layout(G)
32-
rand(_nv(G)), rand(_nv(G))
31+
function random_layout(g)
32+
rand(nv(g)), rand(nv(g))
3333
end
3434

3535
"""
@@ -55,8 +55,8 @@ julia> g = simple_house_graph()
5555
julia> locs_x, locs_y = circular_layout(g)
5656
```
5757
"""
58-
function circular_layout(G)
59-
if _nv(G) == 1
58+
function circular_layout(g)
59+
if nv(g) == 1
6060
return [0.0], [0.0]
6161
else
6262
# Discard the extra angle since it matches 0 radians.
@@ -79,7 +79,7 @@ where C is a parameter we can adjust
7979
8080
**Parameters**
8181
82-
*G*
82+
*g*
8383
a graph
8484
8585
*C*
@@ -97,11 +97,11 @@ julia> g = graphfamous("karate")
9797
julia> locs_x, locs_y = spring_layout(g)
9898
```
9999
"""
100-
function spring_layout(G, locs_x=2*rand(_nv(G)).-1.0, locs_y=2*rand(_nv(G)).-1.0; C=2.0, MAXITER=100, INITTEMP=2.0)
100+
function spring_layout(g::AbstractGraph{T}, locs_x=2*rand(nv(g)).-1.0, locs_y=2*rand(nv(g)).-1.0; C=2.0, MAXITER=100, INITTEMP=2.0) where {T<:Integer}
101101

102102
#size(adj_matrix, 1) != size(adj_matrix, 2) && error("Adj. matrix must be square.")
103-
N = _nv(G)
104-
adj_matrix = _adjacency_matrix(G)
103+
N = nv(g)
104+
adj_matrix = adjacency_matrix(g)
105105

106106
# The optimal distance bewteen vertices
107107
K = C * sqrt(4.0 / N)
@@ -218,7 +218,7 @@ Position nodes using the eigenvectors of the graph Laplacian.
218218
219219
**Parameters**
220220
221-
*G*
221+
*g*
222222
a graph
223223
224224
*weight*
@@ -233,34 +233,34 @@ julia> weight = rand(num_edges(g))
233233
julia> locs_x, locs_y = spectral_layout(g, weight)
234234
```
235235
"""
236-
function spectral_layout(G, weight=nothing)
237-
if _nv(G) == 1
236+
function spectral_layout(g::AbstractGraph{T}, weight=nothing) where {T<:Integer}
237+
if nv(g) == 1
238238
return [0.0], [0.0]
239-
elseif _nv(G) == 2
239+
elseif nv(g) == 2
240240
return [0.0, 1.0], [0.0, 0.0]
241241
end
242242

243243
if weight == nothing
244-
weight = ones(length(_edges(G)))
244+
weight = ones(length(edges(g)))
245245
end
246-
if _nv(G) > 500
247-
A = sparse(Int[_src_index(e, G) for e in _edges(G)],
248-
Int[_dst_index(e, G) for e in _edges(G)],
249-
weight, _nv(G), _nv(G))
250-
if _is_directed(G)
251-
A = A + A'
246+
if nv(g) > 500
247+
A = sparse(Int[src(e) for e in edges(g)],
248+
Int[dst(e) for e in edges(g)],
249+
weight, nv(g), nv(g))
250+
if is_directed(g)
251+
A = A + transpose(A)
252252
end
253253
return _spectral(A)
254254
else
255-
L = _laplacian_matrix(G)
255+
L = laplacian_matrix(g)
256256
return _spectral(Matrix(L))
257257
end
258258
end
259259

260260
function _spectral(L::Matrix)
261261
eigenvalues, eigenvectors = eigen(L)
262262
index = sortperm(eigenvalues)[2:3]
263-
eigenvectors[:, index[1]], eigenvectors[:, index[2]]
263+
return eigenvectors[:, index[1]], eigenvectors[:, index[2]]
264264
end
265265

266266
function _spectral(A::SparseMatrixCSC)
@@ -269,5 +269,5 @@ function _spectral(A::SparseMatrixCSC)
269269
L = D - A
270270
eigenvalues, eigenvectors = LightGraphs.LinAlg.eigs(L, nev=3, which=LR())
271271
index = sortperm(real(eigenvalues))[2:3]
272-
real(eigenvectors[:, index[1]]), real(eigenvectors[:, index[2]])
272+
return real(eigenvectors[:, index[1]]), real(eigenvectors[:, index[2]])
273273
end

0 commit comments

Comments
 (0)