Skip to content

Commit d5503e0

Browse files
simonschoellydlfivefifty
authored andcommitted
fixes for Julia v1.0 (#46)
1 parent 70ed13b commit d5503e0

22 files changed

+173
-146
lines changed

.travis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ addons:
77
os:
88
- linux
99
julia:
10-
- 0.6
10+
- 0.7
11+
- 1.0
1112
- nightly
1213
matrix:
1314
allow_failures:
@@ -18,4 +19,4 @@ notifications:
1819
# - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
1920
# - julia -e 'Pkg.clone(pwd()); Pkg.build("RandomMatrices"); Pkg.test("RandomMatrices"; coverage=true)'
2021
after_success:
21-
- julia -e 'Pkg.add("Coverage"); cd(Pkg.dir("RandomMatrices")); using Coverage; Coveralls.submit(process_folder()); Codecov.submit(process_folder())'
22+
- julia -e 'using Pkg; Pkg.add("Coverage"); cd(Pkg.dir("RandomMatrices")); using Coverage; Coveralls.submit(process_folder()); Codecov.submit(process_folder())'

REQUIRE

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
julia 0.6
2-
Combinatorics 0.2
3-
Distributions 0.8.10
4-
GSL 0.3.1
5-
Compat 0.60
6-
SpecialFunctions 0.4.0
7-
FastGaussQuadrature 0.3.0
1+
julia 0.7
2+
Combinatorics 0.7
3+
Distributions 0.16
4+
GSL 0.4
5+
SpecialFunctions 0.7
6+
FastGaussQuadrature 0.3
7+
Requires 0.5

src/FastHistogram.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export hist_eig
1010
# of the determinant is stored.
1111
#
1212
#For general matrices, this is slower than hist(eigvals(M), bins) and is NOT recommended
13-
function hist_eig{GridPoint <: Number}(M::AbstractMatrix, bins::Vector{GridPoint})
13+
function hist_eig(M::AbstractMatrix, bins::Vector{GridPoint}) where {GridPoint <: Number}
1414
n = size(M)[1]
1515
NumBins = length(bins)
1616
histogram = zeros(NumBins)
@@ -38,7 +38,7 @@ end
3838
# Cy P. Chan, "Sturm Sequences and the Eigenvalue Distribution of
3939
# the Beta-Hermite Random Matrix Ensemble", M.Sc. thesis (MIT), 2007
4040
#
41-
function hist_eig{GridPoint <: Number}(M::SymTridiagonal, bins::Vector{GridPoint})
41+
function hist_eig(M::SymTridiagonal, bins::Vector{GridPoint}) where {GridPoint <: Number}
4242
n = size(M)[1]
4343
NumBins = length(bins)
4444
histogram = zeros(NumBins)

src/FormalPowerSeries.jl

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
# Power Series---Integration---Conformal Mapping---Location of Zeros,
88
# Wiley-Interscience: New York, 1974
99

10-
import Base: zero, one, eye, inv, length, ==, +, -, *, (.*), ^
10+
import Base: zero, one, inv, length, ==, +, -, *, ^
11+
import Base.Broadcast: broadcasted
1112
export FormalPowerSeries, fps, tovector, trim, isunit, isnonunit,
1213
MatrixForm, reciprocal, derivative, isconstant, compose,
1314
isalmostunit, FormalLaurentSeries
@@ -36,11 +37,11 @@ FormalPowerSeries(v::Vector{T}) where T = FormalPowerSeries{T}(v)
3637
#Convenient abbreviation for floats
3738
fps = FormalPowerSeries{Float64}
3839

39-
zero{T}(P::FormalPowerSeries{T}) = FormalPowerSeries(T[])
40-
one{T}(P::FormalPowerSeries{T}) = FormalPowerSeries(T[1])
40+
zero(P::FormalPowerSeries{T}) where {T} = FormalPowerSeries(T[])
41+
one(P::FormalPowerSeries{T}) where {T} = FormalPowerSeries(T[1])
4142

4243
#Return truncated vector with c[i] = P[n[i]]
43-
function tovector{T,Index<:Integer}(P::FormalPowerSeries{T}, n::AbstractVector{Index})
44+
function tovector(P::FormalPowerSeries{T}, n::AbstractVector{Index}) where {T,Index<:Integer}
4445
nn = length(n)
4546
c = zeros(nn)
4647
for (k,v) in P.c, i in eachindex(n)
@@ -55,7 +56,7 @@ tovector(P::FormalPowerSeries, n::Integer)=tovector(P,1:n)
5556
# Basic housekeeping and properties
5657

5758
# Remove extraneous zeros
58-
function trim{T}(P::FormalPowerSeries{T})
59+
function trim(P::FormalPowerSeries{T}) where {T}
5960
for (k,v) in P.c
6061
if v==0
6162
delete!(P.c, k)
@@ -64,9 +65,9 @@ function trim{T}(P::FormalPowerSeries{T})
6465
return P
6566
end
6667

67-
length{T}(P::FormalPowerSeries{T})=max([k for (k,v) in P.c])
68+
length(P::FormalPowerSeries{T}) where {T} = maximum([k for (k,v) in P.c])
6869

69-
function =={T}(P::FormalPowerSeries{T}, Q::FormalPowerSeries{T})
70+
function ==(P::FormalPowerSeries{T}, Q::FormalPowerSeries{T}) where {T}
7071
for (k,v) in P.c
7172
if v==0 #ignore explicit zeros
7273
continue
@@ -89,7 +90,7 @@ function =={T}(P::FormalPowerSeries{T}, Q::FormalPowerSeries{T})
8990
end
9091

9192
# Basic arithmetic [H, p.10]
92-
function +{T}(P::FormalPowerSeries{T}, Q::FormalPowerSeries{T})
93+
function +(P::FormalPowerSeries{T}, Q::FormalPowerSeries{T}) where {T}
9394
c = Dict{BigInt, T}()
9495
for (k,v) in P.c
9596
haskey(c,k) ? (c[k]+=v) : (c[k]=v)
@@ -100,7 +101,7 @@ function +{T}(P::FormalPowerSeries{T}, Q::FormalPowerSeries{T})
100101
FormalPowerSeries{T}(c)
101102
end
102103

103-
function -{T}(P::FormalPowerSeries{T}, Q::FormalPowerSeries{T})
104+
function -(P::FormalPowerSeries{T}, Q::FormalPowerSeries{T}) where {T}
104105
c = Dict{BigInt, T}()
105106
for (k,v) in P.c
106107
c[k] = get(c,k,zero(T)) + v
@@ -112,7 +113,7 @@ function -{T}(P::FormalPowerSeries{T}, Q::FormalPowerSeries{T})
112113
end
113114

114115
#negation
115-
function -{T}(P::FormalPowerSeries{T})
116+
function -(P::FormalPowerSeries{T}) where {T}
116117
c = Dict{BigInt, T}()
117118
for (k,v) in P.c
118119
c[k] = -v
@@ -121,18 +122,18 @@ function -{T}(P::FormalPowerSeries{T})
121122
end
122123

123124
#multiplication by scalar
124-
function *{T}(P::FormalPowerSeries{T}, n::Number)
125+
function *(P::FormalPowerSeries{T}, n::Number) where {T}
125126
c = Dict{BigInt, T}()
126127
for (k,v) in P.c
127128
c[k] = n*v
128129
end
129130
FormalPowerSeries{T}(c)
130131
end
131-
*{T}(n::Number, P::FormalPowerSeries{T}) = *(P, n)
132+
*(n::Number, P::FormalPowerSeries{T}) where {T} = *(P, n)
132133

133134
#Cauchy product [H, p.10]
134-
*{T}(P::FormalPowerSeries{T}, Q::FormalPowerSeries{T}) = CauchyProduct(P, Q)
135-
function CauchyProduct{T}(P::FormalPowerSeries{T}, Q::FormalPowerSeries{T})
135+
*(P::FormalPowerSeries{T}, Q::FormalPowerSeries{T}) where {T} = CauchyProduct(P, Q)
136+
function CauchyProduct(P::FormalPowerSeries{T}, Q::FormalPowerSeries{T}) where {T}
136137
c = Dict{BigInt, T}()
137138
for (k1, v1) in P.c, (k2, v2) in Q.c
138139
c[k1+k2]=get(c, k1+k2, zero(T))+v1*v2
@@ -141,36 +142,37 @@ function CauchyProduct{T}(P::FormalPowerSeries{T}, Q::FormalPowerSeries{T})
141142
end
142143

143144
#Hadamard product [H, p.10] - the elementwise product
144-
broadcast(::typeof(*), P::FormalPowerSeries{T}, Q::FormalPowerSeries{T}) where T =
145+
broadcasted(::typeof(*), P::FormalPowerSeries{T}, Q::FormalPowerSeries{T}) where T =
145146
HadamardProduct(P, Q)
146-
function HadamardProduct{T}(P::FormalPowerSeries{T}, Q::FormalPowerSeries{T})
147+
function HadamardProduct(P::FormalPowerSeries{T}, Q::FormalPowerSeries{T}) where {T}
147148
c = Dict{BigInt, T}()
148149
for (k,v) in P.c
149-
if v!=0 && haskey(Q.c,k) && Q.c[k]==0
150+
if v!=0 && haskey(Q.c,k) && Q.c[k] !=0
150151
c[k] = v * Q.c[k]
151152
end
152153
end
153154
FormalPowerSeries{T}(c)
154155
end
155156

156157
#The identity element over the complex numbers
157-
function eye{T <: Number}(P::FormalPowerSeries{T})
158+
#replacement for previous function eye(P::FormalPowerSeries{T})
159+
function FormalPowerSeries{T}(s::UniformScaling) where {T}
158160
c = Dict{BigInt, T}()
159161
c[0] = 1
160-
FormalPowerSeries{T}(c)
162+
return FormalPowerSeries{T}(c)
161163
end
162164

163-
isunit{T <: Number}(P::FormalPowerSeries{T}) = P==eye(P)
165+
isunit(P::FormalPowerSeries{T}) where {T <: Number} = P==FormalPowerSeries{Float64}(I)
164166

165167
# [H, p.12]
166-
isnonunit{T}(P::FormalPowerSeries{T}) = (!haskey(P.c, 0) || P.c[0]==0) && !isunit(P)
168+
isnonunit(P::FormalPowerSeries{T}) where {T} = (!haskey(P.c, 0) || P.c[0]==0) && !isunit(P)
167169

168170
#Constructs the top left m x m block of the (infinite) semicirculant matrix
169171
#associated with the fps [H, Sec.1.3, p.14]
170172
#[H] calls it the semicirculant, but in contemporary nomenclature this is an
171173
#upper triangular Toeplitz matrix
172174
#This constructs the dense matrix - Toeplitz matrices don't exist in Julia yet
173-
function MatrixForm{T}(P::FormalPowerSeries{T}, m :: Integer)
175+
function MatrixForm(P::FormalPowerSeries{T}, m :: Integer) where {T}
174176
m<0 && error("Invalid matrix dimension $m requested")
175177
M=zeros(T, m, m)
176178
for (k,v) in P.c
@@ -254,13 +256,13 @@ end
254256

255257
# Composition of fps [H, Sec.1.5, p.35]
256258
# This is the quick and dirty version
257-
function compose{T}(P::FormalPowerSeries{T}, Q::FormalPowerSeries{T})
259+
function compose(P::FormalPowerSeries{T}, Q::FormalPowerSeries{T}) where {T}
258260
sum([v * Q^k for (k, v) in P.c])
259261
end
260262

261263

262264
#[H, p.45]
263-
function isalmostunit{T}(P::FormalPowerSeries{T})
265+
function isalmostunit(P::FormalPowerSeries{T}) where {T}
264266
(haskey(P.c, 0) && P.c[0]!=0) ? (return false) :
265267
(haskey(P.c, 1) && P.c[1]!=0) ? (return true) : (return false)
266268
end
@@ -271,7 +273,7 @@ end
271273
# [H. Sec.1.7, p.47, but more succinctly stated on p.55]
272274
# Constructs the upper left nxn subblock of the matrix representation
273275
# and inverts it
274-
function reversion{T}(P::FormalPowerSeries{T}, n :: Integer)
276+
function reversion(P::FormalPowerSeries{T}, n :: Integer) where {T}
275277
n>0 ? error("Need non-negative dimension") : nothing
276278

277279
Q = P

src/GaussianEnsembles.jl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Synonym for GaussianHermite{β}
4747
"""
4848
const Wigner{β} = GaussianHermite{β}
4949

50-
rand{β}(d::Type{Wigner{β}}, dims...) = rand(d(), dims...)
50+
rand(d::Type{Wigner{β}}, dims...) where {β} = rand(d(), dims...)
5151

5252
function rand(d::Wigner{1}, n::Int)
5353
A = randn(n, n)
@@ -70,10 +70,10 @@ function rand(d::Wigner{4}, n::Int)
7070
return Hermitian((A + A') / normalization)
7171
end
7272

73-
rand{β}(d::Wigner{β}, n::Int) =
73+
rand(d::Wigner{β}, n::Int) where {β} =
7474
throw(ValueError("Cannot sample random matrix of size $n x $n for β="))
7575

76-
function rand{β}(d::Wigner{β}, dims...)
76+
function rand(d::Wigner{β}, dims...) where {β}
7777
if length(dims)==2 && dims[1] == dims[2]
7878
return rand(d, dims[1])
7979
else
@@ -89,7 +89,7 @@ Unlike for `rand(Wigner{β}, n)`, which is restricted to β=1,2 or 4,
8989
9090
The β=∞ case is defined in Edelman, Persson and Sutton, 2012
9191
"""
92-
function tridrand{β}(d::Wigner{β}, n::Int)
92+
function tridrand(d::Wigner{β}, n::Int) where {β}
9393
χ(df::Real) = rand(Distributions.Chi(df))
9494
if β0
9595
throw(ValueError("β = cannot be nonpositive"))
@@ -103,7 +103,7 @@ function tridrand{β}(d::Wigner{β}, n::Int)
103103
end
104104
end
105105

106-
function tridrand{β}(d::Wigner{β}, dims...)
106+
function tridrand(d::Wigner{β}, dims...) where {β}
107107
if length(dims)==2 && dims[1] == dims[2]
108108
return rand(d, dims[1])
109109
else
@@ -119,7 +119,7 @@ eigvalrand(d::Wigner, n::Int) = eigvals(tridrand(d, n))
119119
"""
120120
Calculate Vandermonde determinant term
121121
"""
122-
function VandermondeDeterminant{Eigenvalue<:Number}::AbstractVector{Eigenvalue}, β::Real)
122+
function VandermondeDeterminant::AbstractVector{Eigenvalue}, β::Real) where {Eigenvalue<:Number}
123123
n = length(λ)
124124
Vandermonde = one(Eigenvalue)^β
125125
for j=1:n, i=1:j-1
@@ -131,7 +131,7 @@ end
131131
"""
132132
Calculate joint eigenvalue density
133133
"""
134-
function eigvaljpdf{β,Eigenvalue<:Number}(d::Wigner{β}, λ::AbstractVector{Eigenvalue})
134+
function eigvaljpdf(d::Wigner{β}, λ::AbstractVector{Eigenvalue}) where {β,Eigenvalue<:Number}
135135
n = length(λ)
136136
#Calculate normalization constant
137137
c = (2π)^(-n/2)
@@ -167,15 +167,15 @@ function rand(d::GaussianLaguerre, dims::Dim2)
167167
X = randn(dims) + im*randn(dims)
168168
Y = randn(dims) + im*randn(dims)
169169
A = [X Y; -conj(Y) conj(X)]
170-
error(@sprintf("beta = %d is not implemented", d.beta))
170+
error("beta = $(d.beta) is not implemented")
171171
end
172172
return (A * A') / dims[1]
173173
end
174174

175175
#Generates a NxN bidiagonal Wishart matrix
176176
function bidrand(d::GaussianLaguerre, m::Integer)
177177
if d.a <= d.beta*(m-1)/2.0
178-
error(@sprintf("Given your choice of m and beta, a must be at least %f (You said a = %f)", d.beta*(m-1)/2.0, d.a))
178+
error("Given your choice of m and beta, a must be at least $(d.beta*(m-1)/2.0) (You said a = $(d.a))")
179179
end
180180
Bidiagonal([chi(2*d.a-i*d.beta) for i=0:m-1], [chi(d.beta*i) for i=m-1:-1:1], true)
181181
end
@@ -191,7 +191,7 @@ end
191191
eigvalrand(d::GaussianLaguerre, m::Integer) = eigvals(tridrand(d, m))
192192

193193
#TODO Check m and ns
194-
function eigvaljpdf{Eigenvalue<:Number}(d::GaussianLaguerre, lambda::Vector{Eigenvalue})
194+
function eigvaljpdf(d::GaussianLaguerre, lambda::Vector{Eigenvalue}) where {Eigenvalue<:Number}
195195
m = length(lambda)
196196
#Laguerre parameters
197197
p = 0.5*d.beta*(m-1) + 1.0
@@ -317,7 +317,7 @@ function eigvalrand(d::GaussianJacobi, n::Integer)
317317
end
318318

319319
#TODO Check m and ns
320-
function eigvaljpdf{Eigenvalue<:Number}(d::GaussianJacobi, lambda::Vector{Eigenvalue})
320+
function eigvaljpdf(d::GaussianJacobi, lambda::Vector{Eigenvalue}) where {Eigenvalue<:Number}
321321
m = length(lambda)
322322
#Jacobi parameters
323323
a1, a2 = d.a, d.b

src/Ginibre.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function rand(W::Ginibre)
2727
end
2828
end
2929

30-
function jpdf{z<:Complex}(Z::AbstractMatrix{z})
30+
function jpdf(Z::AbstractMatrix{z}) where {z<:Complex}
3131
pi^(size(Z,1)^2)*exp(-trace(Z'*Z))
3232
end
3333

src/Haar.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export permutations_in_Sn, compose, cycle_structure, data, part, #Functions working with partitions and permutations
2-
partition, Haar, expectation, WeingartenUnitary
2+
partition, Haar, expectation, WeingartenUnitary, Stewart
33

44

55
const partition = Vector{Int}
@@ -26,7 +26,7 @@ function permutations_in_Sn(n::Integer)
2626
P = permutation_calloc(n)
2727
while true
2828
produce(P)
29-
try permutation_next(P) catch break end
29+
try permutation_next(P) catch; break end
3030
end
3131
end
3232

@@ -101,12 +101,12 @@ function expectation(X::Expr)
101101
Qidx=[] #Indices for Haar matrices
102102
Qpidx=[] #Indices for ctranspose of Haar matrices
103103
Others=[]
104-
MyQ=None
104+
MyQ=Nothing
105105
for i=1:n
106106
thingy=X.args[i+1]
107107
if isa(thingy, Symbol)
108108
if isa(eval(thingy), Haar)
109-
if MyQ==None MyQ=thingy end
109+
if MyQ==Nothing MyQ=thingy end
110110
if MyQ == thingy
111111
Qidx=[Qidx; i]
112112
else

0 commit comments

Comments
 (0)