Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

fixes most depwarns as of 20180529 #895

Merged
merged 4 commits into from
Jun 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,17 @@ Locate the section for your github remote in the `.git/config` file. It looks li

```
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = git@github.com:JuliaGraphs/LightGraphs.jl.git
fetch = +refs/heads/*:refs/remotes/origin/*
url = git@github.com:JuliaGraphs/LightGraphs.jl.git
```

Now add the line `fetch = +refs/pull/*/head:refs/remotes/origin/pr/*` to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

```
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = git@github.com:JuliaGraphs/LightGraphs.jl.git
fetch = +refs/pull/*/head:refs/remotes/origin/pr/*
fetch = +refs/heads/*:refs/remotes/origin/*
url = git@github.com:JuliaGraphs/LightGraphs.jl.git
fetch = +refs/pull/*/head:refs/remotes/origin/pr/*
```

Now fetch all the pull requests:
Expand Down
2 changes: 1 addition & 1 deletion benchmark/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function bench_iteredges(g::AbstractGraph)
end

function bench_has_edge(g::AbstractGraph)
srand(1)
Random.srand(1)
nvg = nv(g)
srcs = rand([1:nvg;], cld(nvg, 4))
dsts = rand([1:nvg;], cld(nvg, 4))
Expand Down
4 changes: 2 additions & 2 deletions docs/src/distance.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ Pages = ["distance.md"]
```@autodocs
Modules = [LightGraphs]
Pages = [
"distance.jl",
"transitivity.jl"
"distance.jl",
"transitivity.jl"
]
Private = false
```
23 changes: 11 additions & 12 deletions src/LightGraphs.jl
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
__precompile__(true)
module LightGraphs

using SimpleTraits

import CodecZlib
import DataStructures
import DelimitedFiles
import Distributed
import IterativeEigensolvers
import LinearAlgebra
import Markdown
import Random
import SharedArrays
import SparseArrays

using SimpleTraits
using SharedArrays
using SparseArrays
using LinearAlgebra
using IterativeEigensolvers
using SharedArrays
using Markdown
using DelimitedFiles
import Base: write, ==, <, *, ≈, convert, isless, issubset, union, intersect,
reverse, reverse!, isassigned, getindex, setindex!, show,
print, copy, in, sum, size, eltype, length, ndims, transpose,
ctranspose, join, start, next, done, eltype, get, Pair, Tuple, zero
import Random: GLOBAL_RNG
import Distributed: @distributed, @sync
import SparseArrays: sparse, blockdiag
import LinearAlgebra: issymmetric, mul!


export
# Interface
Expand Down
2 changes: 1 addition & 1 deletion src/SimpleGraphs/simpledigraph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ SimpleDiGraph(n::T) where T<:Integer = SimpleDiGraph{T}(n)
SimpleDiGraph(::Type{T}) where T<:Integer = SimpleDiGraph{T}(zero(T))

# sparse adjacency matrix constructor: SimpleDiGraph(adjmx)
function SimpleDiGraph{T}(adjmx::SparseMatrixCSC{U}) where T<:Integer where U<:Real
function SimpleDiGraph{T}(adjmx::SparseArrays.SparseMatrixCSC{U}) where T<:Integer where U<:Real
dima, dimb = size(adjmx)
isequal(dima, dimb) || throw(ArgumentError("Adjacency / distance matrices must be square"))

Expand Down
28 changes: 14 additions & 14 deletions src/SimpleGraphs/simplegraph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ const SimpleGraphEdge = SimpleEdge

A type representing an undirected graph.
"""
mutable struct SimpleGraph{T<:Integer} <: AbstractSimpleGraph{T}
mutable struct SimpleGraph{T <: Integer} <: AbstractSimpleGraph{T}
ne::Int
fadjlist::Vector{Vector{T}} # [src]: (dst, dst, dst)
end

eltype(x::SimpleGraph{T}) where T = T

# Graph{UInt8}(6), Graph{Int16}(7), Graph{UInt8}()
function SimpleGraph{T}(n::Integer = 0) where T<:Integer
function SimpleGraph{T}(n::Integer=0) where T <: Integer
fadjlist = [Vector{T}() for _ = one(T):n]
return SimpleGraph{T}(0, fadjlist)
end
Expand All @@ -22,26 +22,26 @@ end
SimpleGraph() = SimpleGraph{Int}()

# SimpleGraph(6), SimpleGraph(0x5)
SimpleGraph(n::T) where T<:Integer = SimpleGraph{T}(n)
SimpleGraph(n::T) where T <: Integer = SimpleGraph{T}(n)

# SimpleGraph(UInt8)
SimpleGraph(::Type{T}) where T<:Integer = SimpleGraph{T}(zero(T))
SimpleGraph(::Type{T}) where T <: Integer = SimpleGraph{T}(zero(T))

# Graph{UInt8}(adjmx)
function SimpleGraph{T}(adjmx::AbstractMatrix) where T<:Integer
function SimpleGraph{T}(adjmx::AbstractMatrix) where T <: Integer
dima, dimb = size(adjmx)
isequal(dima, dimb) || throw(ArgumentError("Adjacency / distance matrices must be square"))
issymmetric(adjmx) || throw(ArgumentError("Adjacency / distance matrices must be symmetric"))
LinearAlgebra.issymmetric(adjmx) || throw(ArgumentError("Adjacency / distance matrices must be symmetric"))

g = SimpleGraph(T(dima))
@inbounds for i in findall(triu(adjmx).!=0)
@inbounds for i in findall(triu(adjmx) .!= 0)
add_edge!(g, i[1], i[2])
end
return g
end

# converts Graph{Int} to Graph{Int32}
function SimpleGraph{T}(g::SimpleGraph) where T<:Integer
function SimpleGraph{T}(g::SimpleGraph) where T <: Integer
h_fadj = [Vector{T}(x) for x in fadj(g)]
return SimpleGraph(ne(g), h_fadj)
end
Expand Down Expand Up @@ -71,7 +71,7 @@ function SimpleGraph(g::SimpleDiGraph)
return SimpleGraph(edgect ÷ 2, newfadj)
end

@inbounds function cleanupedges!(fadjlist::Vector{Vector{T}}) where T<:Integer
@inbounds function cleanupedges!(fadjlist::Vector{Vector{T}}) where T <: Integer
neg = 0
for v in 1:length(fadjlist)
if !issorted(fadjlist[v])
Expand All @@ -90,7 +90,7 @@ end
return neg ÷ 2
end

function SimpleGraph(edge_list::Vector{SimpleGraphEdge{T}}) where T<:Integer
function SimpleGraph(edge_list::Vector{SimpleGraphEdge{T}}) where T <: Integer
nvg = zero(T)
@inbounds(
for e in edge_list
Expand Down Expand Up @@ -136,10 +136,10 @@ function SimpleGraph(edge_list::Vector{SimpleGraphEdge{T}}) where T<:Integer
end


@inbounds function add_to_fadjlist!(fadjlist::Vector{Vector{T}}, s::T, d::T) where T<:Integer
@inbounds function add_to_fadjlist!(fadjlist::Vector{Vector{T}}, s::T, d::T) where T <: Integer
nvg = length(fadjlist)
nvg_new = max(nvg, s, d)
for v = (nvg+1):nvg_new
for v = (nvg + 1):nvg_new
push!(fadjlist, Vector{T}())
end

Expand Down Expand Up @@ -174,7 +174,7 @@ function _SimpleGraphFromIterator(iter)::SimpleGraph
return g
end

function _SimpleGraphFromIterator(iter, ::Type{SimpleGraphEdge{T}}) where T<:Integer
function _SimpleGraphFromIterator(iter, ::Type{SimpleGraphEdge{T}}) where T <: Integer
fadjlist = Vector{Vector{T}}()
@inbounds(
for e in iter
Expand Down Expand Up @@ -209,7 +209,7 @@ function SimpleGraphFromIterator(iter)::SimpleGraph
end


edgetype(::SimpleGraph{T}) where T<:Integer = SimpleGraphEdge{T}
edgetype(::SimpleGraph{T}) where T <: Integer = SimpleGraphEdge{T}

"""
badj(g::SimpleGraph[, v::Integer])
Expand Down
2 changes: 1 addition & 1 deletion src/centrality/betweenness.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function parallel_betweenness_centrality(

# Parallel reduction

betweenness = @distributed (+) for s in vs
betweenness = Distributed.@distributed (+) for s in vs
temp_betweenness = zeros(n_v)
if degree(g, s) > 0 # this might be 1?
state = dijkstra_shortest_paths(g, s, distmx; allpaths=true, trackvertices=true)
Expand Down
16 changes: 7 additions & 9 deletions src/centrality/closeness.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ of the graph `g`. Return a vector representing the centrality calculated for eac
node `n` by ``\\frac{|δ_n|}{|V|-1}``, where ``δ_n`` is the set of vertices reachable
from node `n`.
"""
function closeness_centrality(
g::AbstractGraph,
distmx::AbstractMatrix = weights(g);
function closeness_centrality(g::AbstractGraph,
distmx::AbstractMatrix=weights(g);
normalize=true)

n_v = nv(g)
Expand All @@ -37,16 +36,15 @@ function closeness_centrality(
return closeness
end

function parallel_closeness_centrality(
g::AbstractGraph,
distmx::AbstractMatrix = weights(g);
function parallel_closeness_centrality(g::AbstractGraph,
distmx::AbstractMatrix=weights(g);
normalize=true)::Vector{Float64}

n_v = Int(nv(g))

closeness = SharedVector{Float64}(n_v)
closeness = SharedArrays.SharedVector{Float64}(n_v)

@sync @distributed for u in vertices(g)
Distributed.@sync Distributed.@distributed for u in vertices(g)
if degree(g, u) == 0 # no need to do Dijkstra here
closeness[u] = 0.0
else
Expand All @@ -63,5 +61,5 @@ function parallel_closeness_centrality(
end
end
end
return sdata(closeness)
return SharedArrays.sdata(closeness)
end
2 changes: 1 addition & 1 deletion src/centrality/eigenvector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ eigenvector of the adjacency matrix \$\\mathbf{A}\$.
- Mark E. J. Newman: Networks: An Introduction.
Oxford University Press, USA, 2010, pp. 169.
"""
eigenvector_centrality(g::AbstractGraph) = abs.(vec(eigs(adjacency_matrix(g), nev=1)[2]))::Vector{Float64}
eigenvector_centrality(g::AbstractGraph) = abs.(vec(IterativeEigensolvers.eigs(adjacency_matrix(g), nev=1)[2]))::Vector{Float64}
4 changes: 2 additions & 2 deletions src/centrality/katz.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ the centrality calculated for each node in `g`.
function katz_centrality(g::AbstractGraph, α::Real=0.3)
nvg = nv(g)
v = ones(Float64, nvg)
spI = sparse(one(Float64) * I, nvg, nvg)
spI = SparseArrays.sparse(one(Float64) * LinearAlgebra.I, nvg, nvg)
A = adjacency_matrix(g, Bool; dir=:in)
v = (spI - α * A) \ v
v /= norm(v)
v /= LinearAlgebra.norm(v)
return v
end
12 changes: 6 additions & 6 deletions src/centrality/radiality.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,23 @@ function radiality_centrality(g::AbstractGraph)::Vector{Float64}
dmtr = max(dmtr, maximum(d.dists))
meandists[v] = sum(d.dists) / (n_v - 1) # ignore the source vx
end
meandists = (dmtr + 1).-(meandists)
return meandists./dmtr
meandists = (dmtr + 1) .- (meandists)
return meandists ./ dmtr
end

function parallel_radiality_centrality(g::AbstractGraph)::Vector{Float64}
n_v = nv(g)
vs = vertices(g)
n = ne(g)
meandists = SharedVector{Float64}(Int(n_v))
maxdists = SharedVector{Float64}(Int(n_v))
meandists = SharedArrays.SharedVector{Float64}(Int(n_v))
maxdists = SharedArrays.SharedVector{Float64}(Int(n_v))

@sync @distributed for i = 1:n_v
Distributed.@sync Distributed.@distributed for i = 1:n_v
d = dijkstra_shortest_paths(g, vs[i])
maxdists[i] = maximum(d.dists)
meandists[i] = sum(d.dists) / (n_v - 1)
end
dmtr = maximum(maxdists)
radialities = collect(meandists)
return ((dmtr + 1).-radialities)./dmtr
return ((dmtr + 1) .- radialities) ./ dmtr
end
2 changes: 1 addition & 1 deletion src/centrality/stress.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function parallel_stress_centrality(

# Parallel reduction

stress = @distributed (+) for s in vs
stress = Distributed.@distributed (+) for s in vs
temp_stress = zeros(Int, n_v)
if degree(g, s) > 0 # this might be 1?
state = dijkstra_shortest_paths(g, s; allpaths=true, trackvertices=true)
Expand Down
Loading