Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for Julia v1.0 #46

Merged
merged 1 commit into from
Nov 3, 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
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ addons:
os:
- linux
julia:
- 0.6
- 0.7
- 1.0
- nightly
matrix:
allow_failures:
Expand All @@ -18,4 +19,4 @@ notifications:
# - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
# - julia -e 'Pkg.clone(pwd()); Pkg.build("RandomMatrices"); Pkg.test("RandomMatrices"; coverage=true)'
after_success:
- julia -e 'Pkg.add("Coverage"); cd(Pkg.dir("RandomMatrices")); using Coverage; Coveralls.submit(process_folder()); Codecov.submit(process_folder())'
- julia -e 'using Pkg; Pkg.add("Coverage"); cd(Pkg.dir("RandomMatrices")); using Coverage; Coveralls.submit(process_folder()); Codecov.submit(process_folder())'
14 changes: 7 additions & 7 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
julia 0.6
Combinatorics 0.2
Distributions 0.8.10
GSL 0.3.1
Compat 0.60
SpecialFunctions 0.4.0
FastGaussQuadrature 0.3.0
julia 0.7
Combinatorics 0.7
Distributions 0.16
GSL 0.4
SpecialFunctions 0.7
FastGaussQuadrature 0.3
Requires 0.5
4 changes: 2 additions & 2 deletions src/FastHistogram.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export hist_eig
# of the determinant is stored.
#
#For general matrices, this is slower than hist(eigvals(M), bins) and is NOT recommended
function hist_eig{GridPoint <: Number}(M::AbstractMatrix, bins::Vector{GridPoint})
function hist_eig(M::AbstractMatrix, bins::Vector{GridPoint}) where {GridPoint <: Number}
n = size(M)[1]
NumBins = length(bins)
histogram = zeros(NumBins)
Expand Down Expand Up @@ -38,7 +38,7 @@ end
# Cy P. Chan, "Sturm Sequences and the Eigenvalue Distribution of
# the Beta-Hermite Random Matrix Ensemble", M.Sc. thesis (MIT), 2007
#
function hist_eig{GridPoint <: Number}(M::SymTridiagonal, bins::Vector{GridPoint})
function hist_eig(M::SymTridiagonal, bins::Vector{GridPoint}) where {GridPoint <: Number}
n = size(M)[1]
NumBins = length(bins)
histogram = zeros(NumBins)
Expand Down
52 changes: 27 additions & 25 deletions src/FormalPowerSeries.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
# Power Series---Integration---Conformal Mapping---Location of Zeros,
# Wiley-Interscience: New York, 1974

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

zero{T}(P::FormalPowerSeries{T}) = FormalPowerSeries(T[])
one{T}(P::FormalPowerSeries{T}) = FormalPowerSeries(T[1])
zero(P::FormalPowerSeries{T}) where {T} = FormalPowerSeries(T[])
one(P::FormalPowerSeries{T}) where {T} = FormalPowerSeries(T[1])

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

# Remove extraneous zeros
function trim{T}(P::FormalPowerSeries{T})
function trim(P::FormalPowerSeries{T}) where {T}
for (k,v) in P.c
if v==0
delete!(P.c, k)
Expand All @@ -64,9 +65,9 @@ function trim{T}(P::FormalPowerSeries{T})
return P
end

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

function =={T}(P::FormalPowerSeries{T}, Q::FormalPowerSeries{T})
function ==(P::FormalPowerSeries{T}, Q::FormalPowerSeries{T}) where {T}
for (k,v) in P.c
if v==0 #ignore explicit zeros
continue
Expand All @@ -89,7 +90,7 @@ function =={T}(P::FormalPowerSeries{T}, Q::FormalPowerSeries{T})
end

# Basic arithmetic [H, p.10]
function +{T}(P::FormalPowerSeries{T}, Q::FormalPowerSeries{T})
function +(P::FormalPowerSeries{T}, Q::FormalPowerSeries{T}) where {T}
c = Dict{BigInt, T}()
for (k,v) in P.c
haskey(c,k) ? (c[k]+=v) : (c[k]=v)
Expand All @@ -100,7 +101,7 @@ function +{T}(P::FormalPowerSeries{T}, Q::FormalPowerSeries{T})
FormalPowerSeries{T}(c)
end

function -{T}(P::FormalPowerSeries{T}, Q::FormalPowerSeries{T})
function -(P::FormalPowerSeries{T}, Q::FormalPowerSeries{T}) where {T}
c = Dict{BigInt, T}()
for (k,v) in P.c
c[k] = get(c,k,zero(T)) + v
Expand All @@ -112,7 +113,7 @@ function -{T}(P::FormalPowerSeries{T}, Q::FormalPowerSeries{T})
end

#negation
function -{T}(P::FormalPowerSeries{T})
function -(P::FormalPowerSeries{T}) where {T}
c = Dict{BigInt, T}()
for (k,v) in P.c
c[k] = -v
Expand All @@ -121,18 +122,18 @@ function -{T}(P::FormalPowerSeries{T})
end

#multiplication by scalar
function *{T}(P::FormalPowerSeries{T}, n::Number)
function *(P::FormalPowerSeries{T}, n::Number) where {T}
c = Dict{BigInt, T}()
for (k,v) in P.c
c[k] = n*v
end
FormalPowerSeries{T}(c)
end
*{T}(n::Number, P::FormalPowerSeries{T}) = *(P, n)
*(n::Number, P::FormalPowerSeries{T}) where {T} = *(P, n)

#Cauchy product [H, p.10]
*{T}(P::FormalPowerSeries{T}, Q::FormalPowerSeries{T}) = CauchyProduct(P, Q)
function CauchyProduct{T}(P::FormalPowerSeries{T}, Q::FormalPowerSeries{T})
*(P::FormalPowerSeries{T}, Q::FormalPowerSeries{T}) where {T} = CauchyProduct(P, Q)
function CauchyProduct(P::FormalPowerSeries{T}, Q::FormalPowerSeries{T}) where {T}
c = Dict{BigInt, T}()
for (k1, v1) in P.c, (k2, v2) in Q.c
c[k1+k2]=get(c, k1+k2, zero(T))+v1*v2
Expand All @@ -141,36 +142,37 @@ function CauchyProduct{T}(P::FormalPowerSeries{T}, Q::FormalPowerSeries{T})
end

#Hadamard product [H, p.10] - the elementwise product
broadcast(::typeof(*), P::FormalPowerSeries{T}, Q::FormalPowerSeries{T}) where T =
broadcasted(::typeof(*), P::FormalPowerSeries{T}, Q::FormalPowerSeries{T}) where T =
HadamardProduct(P, Q)
function HadamardProduct{T}(P::FormalPowerSeries{T}, Q::FormalPowerSeries{T})
function HadamardProduct(P::FormalPowerSeries{T}, Q::FormalPowerSeries{T}) where {T}
c = Dict{BigInt, T}()
for (k,v) in P.c
if v!=0 && haskey(Q.c,k) && Q.c[k]==0
if v!=0 && haskey(Q.c,k) && Q.c[k] !=0
c[k] = v * Q.c[k]
end
end
FormalPowerSeries{T}(c)
end

#The identity element over the complex numbers
function eye{T <: Number}(P::FormalPowerSeries{T})
#replacement for previous function eye(P::FormalPowerSeries{T})
function FormalPowerSeries{T}(s::UniformScaling) where {T}
c = Dict{BigInt, T}()
c[0] = 1
FormalPowerSeries{T}(c)
return FormalPowerSeries{T}(c)
end

isunit{T <: Number}(P::FormalPowerSeries{T}) = P==eye(P)
isunit(P::FormalPowerSeries{T}) where {T <: Number} = P==FormalPowerSeries{Float64}(I)

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

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

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


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

Q = P
Expand Down
22 changes: 11 additions & 11 deletions src/GaussianEnsembles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Synonym for GaussianHermite{β}
"""
const Wigner{β} = GaussianHermite{β}

rand{β}(d::Type{Wigner{β}}, dims...) = rand(d(), dims...)
rand(d::Type{Wigner{β}}, dims...) where {β} = rand(d(), dims...)

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

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

function rand{β}(d::Wigner{β}, dims...)
function rand(d::Wigner{β}, dims...) where {β}
if length(dims)==2 && dims[1] == dims[2]
return rand(d, dims[1])
else
Expand All @@ -89,7 +89,7 @@ Unlike for `rand(Wigner{β}, n)`, which is restricted to β=1,2 or 4,

The β=∞ case is defined in Edelman, Persson and Sutton, 2012
"""
function tridrand{β}(d::Wigner{β}, n::Int)
function tridrand(d::Wigner{β}, n::Int) where {β}
χ(df::Real) = rand(Distributions.Chi(df))
if β≤0
throw(ValueError("β = $β cannot be nonpositive"))
Expand All @@ -103,7 +103,7 @@ function tridrand{β}(d::Wigner{β}, n::Int)
end
end

function tridrand{β}(d::Wigner{β}, dims...)
function tridrand(d::Wigner{β}, dims...) where {β}
if length(dims)==2 && dims[1] == dims[2]
return rand(d, dims[1])
else
Expand All @@ -119,7 +119,7 @@ eigvalrand(d::Wigner, n::Int) = eigvals(tridrand(d, n))
"""
Calculate Vandermonde determinant term
"""
function VandermondeDeterminant{Eigenvalue<:Number}(λ::AbstractVector{Eigenvalue}, β::Real)
function VandermondeDeterminant(λ::AbstractVector{Eigenvalue}, β::Real) where {Eigenvalue<:Number}
n = length(λ)
Vandermonde = one(Eigenvalue)^β
for j=1:n, i=1:j-1
Expand All @@ -131,7 +131,7 @@ end
"""
Calculate joint eigenvalue density
"""
function eigvaljpdf{β,Eigenvalue<:Number}(d::Wigner{β}, λ::AbstractVector{Eigenvalue})
function eigvaljpdf(d::Wigner{β}, λ::AbstractVector{Eigenvalue}) where {β,Eigenvalue<:Number}
n = length(λ)
#Calculate normalization constant
c = (2π)^(-n/2)
Expand Down Expand Up @@ -167,15 +167,15 @@ function rand(d::GaussianLaguerre, dims::Dim2)
X = randn(dims) + im*randn(dims)
Y = randn(dims) + im*randn(dims)
A = [X Y; -conj(Y) conj(X)]
error(@sprintf("beta = %d is not implemented", d.beta))
error("beta = $(d.beta) is not implemented")
end
return (A * A') / dims[1]
end

#Generates a NxN bidiagonal Wishart matrix
function bidrand(d::GaussianLaguerre, m::Integer)
if d.a <= d.beta*(m-1)/2.0
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))
error("Given your choice of m and beta, a must be at least $(d.beta*(m-1)/2.0) (You said a = $(d.a))")
end
Bidiagonal([chi(2*d.a-i*d.beta) for i=0:m-1], [chi(d.beta*i) for i=m-1:-1:1], true)
end
Expand All @@ -191,7 +191,7 @@ end
eigvalrand(d::GaussianLaguerre, m::Integer) = eigvals(tridrand(d, m))

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

#TODO Check m and ns
function eigvaljpdf{Eigenvalue<:Number}(d::GaussianJacobi, lambda::Vector{Eigenvalue})
function eigvaljpdf(d::GaussianJacobi, lambda::Vector{Eigenvalue}) where {Eigenvalue<:Number}
m = length(lambda)
#Jacobi parameters
a1, a2 = d.a, d.b
Expand Down
2 changes: 1 addition & 1 deletion src/Ginibre.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function rand(W::Ginibre)
end
end

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

Expand Down
8 changes: 4 additions & 4 deletions src/Haar.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export permutations_in_Sn, compose, cycle_structure, data, part, #Functions working with partitions and permutations
partition, Haar, expectation, WeingartenUnitary
partition, Haar, expectation, WeingartenUnitary, Stewart


const partition = Vector{Int}
Expand All @@ -26,7 +26,7 @@ function permutations_in_Sn(n::Integer)
P = permutation_calloc(n)
while true
produce(P)
try permutation_next(P) catch break end
try permutation_next(P) catch; break end
end
end

Expand Down Expand Up @@ -101,12 +101,12 @@ function expectation(X::Expr)
Qidx=[] #Indices for Haar matrices
Qpidx=[] #Indices for ctranspose of Haar matrices
Others=[]
MyQ=None
MyQ=Nothing
for i=1:n
thingy=X.args[i+1]
if isa(thingy, Symbol)
if isa(eval(thingy), Haar)
if MyQ==None MyQ=thingy end
if MyQ==Nothing MyQ=thingy end
if MyQ == thingy
Qidx=[Qidx; i]
else
Expand Down
Loading