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

Commit

Permalink
fixes most depwarns as of 20180529
Browse files Browse the repository at this point in the history
  • Loading branch information
sbromberger committed May 30, 2018
1 parent 7bf58f5 commit 0846587
Show file tree
Hide file tree
Showing 30 changed files with 135 additions and 140 deletions.
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
22 changes: 11 additions & 11 deletions src/LightGraphs.jl
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
__precompile__(true)
module LightGraphs

using SimpleTraits

import CodecZlib
import DataStructures

using SimpleTraits
using SharedArrays
using SparseArrays
using LinearAlgebra
using IterativeEigensolvers
using SharedArrays
using Markdown
using DelimitedFiles
import SharedArrays
import SparseArrays
import LinearAlgebra
import IterativeEigensolvers
import SharedArrays
import Markdown
import 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 Random
import Distributed: @distributed, @sync
import SparseArrays: sparse, blockdiag
import LinearAlgebra: issymmetric, mul!
import LinearAlgebra: issymmetric, mul!, Diagonal

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
4 changes: 2 additions & 2 deletions src/centrality/closeness.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function parallel_closeness_centrality(

n_v = Int(nv(g))

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

@sync @distributed for u in vertices(g)
if degree(g, u) == 0 # no need to do Dijkstra here
Expand All @@ -63,5 +63,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 = 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
4 changes: 2 additions & 2 deletions src/centrality/radiality.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ 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
d = dijkstra_shortest_paths(g, vs[i])
Expand Down
4 changes: 2 additions & 2 deletions src/distance.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ function parallel_eccentricity(
distmx::AbstractMatrix{T} = weights(g)
) where T <: Real
vlen = length(vs)
eccs = SharedVector{T}(vlen)
eccs = SharedArrays.SharedVector{T}(vlen)
@sync @distributed for i = 1:vlen
eccs[i] = maximum(dijkstra_shortest_paths(g, vs[i], distmx).dists)
end
d = sdata(eccs)
d = SharedArrays.sdata(eccs)
maximum(d) == typemax(T) && warn("Infinite path length detected")
return d
end
Expand Down
4 changes: 2 additions & 2 deletions src/edit_distance.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ vertex v ∈ G₂.
`p=1`: the p value for p-norm calculation.
"""
function MinkowskiCost(μ₁::AbstractVector, μ₂::AbstractVector; p::Real=1)
(u, v) -> norm(μ₁[u] - μ₂[v], p)
(u, v) -> LinearAlgebra.norm(μ₁[u] - μ₂[v], p)
end

"""
Expand All @@ -132,5 +132,5 @@ Return value similar to `MinkowskiCost`, but ensure costs smaller than 2τ.
`τ=1`: value specifying half of the upper limit of the Minkowski cost.
"""
function BoundedMinkowskiCost(μ₁::AbstractVector, μ₂::AbstractVector; p::Real=1, τ::Real=1)
(u, v) -> 1 / (1 / (2τ) + exp(-norm(μ₁[u] - μ₂[v], p)))
(u, v) -> 1 / (1 / (2τ) + exp(-LinearAlgebra.norm(μ₁[u] - μ₂[v], p)))
end
4 changes: 2 additions & 2 deletions src/generators/euclideangraphs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ a matrix with the points' positions.
function euclidean_graph(N::Int, d::Int;
L=1., seed = -1, kws...)
rng = LightGraphs.getRNG(seed)
points = rmul!(rand(rng, d, N), L)
points = LinearAlgebra.rmul!(rand(rng, d, N), L)
return (euclidean_graph(points; L=L, kws...)..., points)
end

Expand Down Expand Up @@ -49,7 +49,7 @@ function euclidean_graph(points::Matrix;
else
throw(ArgumentError("$bc is not a valid boundary condition"))
end
dist = norm(Δ, p)
dist = LinearAlgebra.norm(Δ, p)
if dist < cutoff
e = Edge(i, j)
add_edge!(g, e)
Expand Down
24 changes: 12 additions & 12 deletions src/generators/randgraphs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,9 @@ function _suitable(edges::Set{Edge}, potential_edges::Dict{T,T}) where T<:Intege
return false
end

_try_creation(n::Integer, k::Integer, rng::AbstractRNG) = _try_creation(n, fill(k, n), rng)
_try_creation(n::Integer, k::Integer, rng::Random.AbstractRNG) = _try_creation(n, fill(k, n), rng)

function _try_creation(n::T, k::Vector{T}, rng::AbstractRNG) where T<:Integer
function _try_creation(n::T, k::Vector{T}, rng::Random.AbstractRNG) where T<:Integer
edges = Set{Edge}()
m = 0
stubs = zeros(T, sum(k))
Expand All @@ -211,7 +211,7 @@ function _try_creation(n::T, k::Vector{T}, rng::AbstractRNG) where T<:Integer

while !isempty(stubs)
potential_edges = Dict{T,T}()
shuffle!(rng, stubs)
Random.shuffle!(rng, stubs)
for i in 1:2:length(stubs)
s1, s2 = stubs[i:(i + 1)]
if (s1 > s2)
Expand Down Expand Up @@ -298,7 +298,7 @@ function barabasi_albert!(g::AbstractGraph, n::Integer, k::Integer; seed::Int=-1
n0 == n && return g

# seed random number generator
seed > 0 && srand(seed)
seed > 0 && Random.srand(seed)

# add missing vertices
sizehint!(g.fadjlist, n)
Expand Down Expand Up @@ -503,7 +503,7 @@ function static_scale_free(n::Integer, m::Integer, α_out::Real, α_in::Float64;
fitness_out = _construct_fitness(n, α_out, finite_size_correction)
fitness_in = _construct_fitness(n, α_in, finite_size_correction)
# eliminate correlation
shuffle!(fitness_in)
Random.shuffle!(fitness_in)
static_fitness_model(m, fitness_out, fitness_in, seed=seed)
end

Expand Down Expand Up @@ -755,7 +755,7 @@ mutable struct StochasticBlockModel{T<:Integer,P<:Real}
n::T
nodemap::Array{T}
affinities::Matrix{P}
rng::MersenneTwister
rng::Random.MersenneTwister
end

==(sbm::StochasticBlockModel, other::StochasticBlockModel) =
Expand Down Expand Up @@ -789,7 +789,7 @@ and external probabilities `externalp`.
function sbmaffinity(internalp::Vector{T}, externalp::Real, sizes::Vector{U}) where T<:Real where U<:Integer
numblocks = length(sizes)
numblocks == length(internalp) || throw(ArgumentError("Inconsistent input dimensions: internalp, sizes"))
B = diagm(0=>internalp) + externalp * (ones(numblocks, numblocks) - I)
B = LinearAlgebra.diagm(0=>internalp) + externalp * (ones(numblocks, numblocks) - LinearAlgebra.I)
return B
end

Expand All @@ -810,7 +810,7 @@ function StochasticBlockModel(internalp::Vector{T}, externalp::Real,
end


const biclique = ones(2, 2) - eye(2)
const biclique = ones(2, 2) - Matrix{Float64}(LinearAlgebra.I, 2, 2)

#TODO: this documentation needs work. sbromberger 20170326
"""
Expand All @@ -826,7 +826,7 @@ The blocks are connected with probability `between`.
"""
function nearbipartiteaffinity(sizes::Vector{T}, between::Real, intra::Real) where T<:Integer
numblocks = div(length(sizes), 2)
return kron(between * eye(numblocks), biclique) + eye(2numblocks) * intra
return kron(between * Matrix{Float64}(LinearAlgebra.I, numblocks, numblocks), biclique) + Matrix{Float64}(LinearAlgebra.I, 2*numblocks, 2*numblocks) * intra
end

#Return a generator for edges from a stochastic block model near-bipartite graph.
Expand All @@ -841,7 +841,7 @@ nearbipartiteSBM(sizes, between, inter, noise; seed::Int = -1) =
Generate a stream of random pairs in `1:n` using random number generator `RNG`.
"""
function random_pair(rng::AbstractRNG, n::Integer)
function random_pair(rng::Random.AbstractRNG, n::Integer)
f(ch) = begin
while true
put!(ch, Edge(rand(rng, 1:n), rand(rng, 1:n)))
Expand Down Expand Up @@ -938,10 +938,10 @@ function kronecker(SCALE, edgefactor, A=0.57, B=0.19, C=0.19)
ij .+= 2^(ib - 1) .* (hcat(ii_bit, jj_bit))
end

p = randperm(N)
p = Random.randperm(N)
ij = p[ij]

p = randperm(M)
p = Random.randperm(M)
ij = ij[p, :]

g = SimpleDiGraph(N)
Expand Down
24 changes: 12 additions & 12 deletions src/graphcut/normalized_cut.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ function _normalized_cut_cost(cut, W::AbstractMatrix, D)
return cut_cost/sum(D*cut) + cut_cost/sum(D*(.~cut))
end

function _normalized_cut_cost(cut, W::SparseMatrixCSC, D)
function _normalized_cut_cost(cut, W::SparseArrays.SparseMatrixCSC, D)
cut_cost = 0
rows = rowvals(W)
vals = nonzeros(W)
rows = SparseArrays.rowvals(W)
vals = SparseArrays.nonzeros(W)
n = size(W, 2)
for i = 1:n
for j in nzrange(W, i)
for j in SparseArrays.nzrange(W, i)
row = rows[j]
if cut[i] != cut[row]
cut_cost += vals[j]/2
Expand Down Expand Up @@ -65,7 +65,7 @@ function _partition_weightmx(cut, W::AbstractMatrix)
return (W1, W2, vmap1, vmap2)
end

function _partition_weightmx(cut, W::SparseMatrixCSC)
function _partition_weightmx(cut, W::SparseArrays.SparseMatrixCSC)
nv = length(cut)
nv2 = sum(cut)
nv1 = nv - nv2
Expand All @@ -86,13 +86,13 @@ function _partition_weightmx(cut, W::SparseMatrixCSC)
end
end

rows = rowvals(W)
vals = nonzeros(W)
rows = SparseArrays.rowvals(W)
vals = SparseArrays.nonzeros(W)
I1 = Vector{Int}(); I2 = Vector{Int}()
J1 = Vector{Int}(); J2 = Vector{Int}()
V1 = Vector{Float64}(); V2 = Vector{Float64}()
for i = 1:nv
for j in nzrange(W, i)
for j in SparseArrays.nzrange(W, i)
row = rows[j]
if cut[i] == cut[row] == false
push!(I1, newvid[i])
Expand All @@ -112,18 +112,18 @@ end

function _recursive_normalized_cut(W, thres=thres, num_cuts=num_cuts)
m, n = size(W)
D = Diagonal(vec(sum(W, dims=2)))
D = LinearAlgebra.Diagonal(vec(sum(W, dims=2)))

m == 1 && return [1]

#get eigenvector corresponding to second smallest eigenvalue
# v = eigs(D-W, D, nev=2, which=:SR)[2][:,2]
# v = IterativeEigensolvers.eigs(D-W, D, nev=2, which=:SR)[2][:,2]
# At least some versions of ARPACK have a bug, this is a workaround
invDroot = sqrt.(inv(D)) # equal to Cholesky factorization for diagonal D
if n > 10
ret = eigs(invDroot'*(D-W)*invDroot, nev=2, which=:SR)[2][:,2]
ret = IterativeEigensolvers.eigs(invDroot'*(D-W)*invDroot, nev=2, which=:SR)[2][:,2]
else
ret = eigfact(Matrix(invDroot'*(D-W)*invDroot)).vectors[:,2]
ret = LinearAlgebra.eigen(Matrix(invDroot'*(D-W)*invDroot)).vectors[:,2]
end
v = invDroot*ret

Expand Down
6 changes: 3 additions & 3 deletions src/linalg/LinAlg.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module LinAlg

using SimpleTraits
using SparseArrays
using LinearAlgebra
using IterativeEigensolvers
import SparseArrays
import LinearAlgebra
import IterativeEigensolvers
using ..LightGraphs

import LightGraphs: IsDirected, AbstractGraph, inneighbors,
Expand Down
Loading

0 comments on commit 0846587

Please sign in to comment.