Skip to content

Commit

Permalink
fix 0.7 deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
awllee committed Jul 23, 2018
1 parent 240a44f commit 53b7209
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 19 deletions.
11 changes: 10 additions & 1 deletion src/MonteCarloMarkovKernels.jl
@@ -1,9 +1,18 @@
__precompile__()

module MonteCarloMarkovKernels
using StaticArrays

using Compat.LinearAlgebra
using Compat.Random
import Compat.Statistics.mean

import Compat.undef
import Compat: undef, UndefInitializer
if VERSION.minor < 7
MVector{d, Float64}(::UndefInitializer) where d = MVector{d, Float64}()
mul! = A_mul_B!
end

if VERSION.minor == 7
function mychol(A)
return cholesky(A).L
Expand Down
12 changes: 3 additions & 9 deletions src/adaptiveMetropolis.jl
@@ -1,9 +1,3 @@
using StaticArrays
using Compat.LinearAlgebra
using Compat.Random

if VERSION.minor == 6 mul! = A_mul_B! end

## Makes an adaptive Metropolis kernel proposed by:
## Haario, H., Saksman, E. and Tamminen, J., 2001. An adaptive Metropolis
## algorithm. Bernoulli, 7(2), pp.223-242.
Expand All @@ -18,9 +12,9 @@ function makeAMKernel(logTargetDensity::F, Σ::SMatrix{d, d, Float64},
# A::MMatrix{d, d, Float64} = chol(Symmetric(S))'
A::MMatrix{d, d, Float64} = mychol(S)

scratchv::MVector{d, Float64} = MVector{d, Float64}()
scratchz::MVector{d, Float64} = MVector{d, Float64}()
prevx::MVector{d, Float64} = MVector{d, Float64}()
scratchv::MVector{d, Float64} = MVector{d, Float64}(undef)
scratchz::MVector{d, Float64} = MVector{d, Float64}(undef)
prevx::MVector{d, Float64} = MVector{d, Float64}(undef)
ldprevx = Ref(-Inf)

accepts = Ref(0)
Expand Down
8 changes: 2 additions & 6 deletions src/randomWalkMetropolis.jl
@@ -1,15 +1,11 @@
using StaticArrays
using Compat.LinearAlgebra
using Compat.Random

## Makes a random walk Metropolis kernel
function makeRWMKernel(logTargetDensity::F,
Σ::SMatrix{d, d, Float64}) where {F<:Function, d}
# A::SMatrix{d, d, Float64} = chol(Symmetric(Σ))'
A::SMatrix{d, d, Float64} = mychol(Σ)

scratchv::MVector{d, Float64} = MVector{d, Float64}()
prevx::MVector{d, Float64} = MVector{d, Float64}()
scratchv::MVector{d, Float64} = MVector{d, Float64}(undef)
prevx::MVector{d, Float64} = MVector{d, Float64}(undef)
ldprevx = Ref(-Inf)

accepts = Ref(0)
Expand Down
1 change: 0 additions & 1 deletion src/simulateChain.jl
@@ -1,4 +1,3 @@
using StaticArrays
using ProgressMeter

function simulateChain!(chain::Vector{T}, P::F, x0::T) where {F<:Function, T}
Expand Down
4 changes: 2 additions & 2 deletions test/visualize_test.jl
Expand Up @@ -23,7 +23,7 @@ end
logtarget = makelogMVN(SVector{2, Float64}(μ1), SMatrix{2, 2, Float64}(Σ1))

niterations = 2^20
chain = Vector{SVector{2, Float64}}(niterations)
chain = Vector{SVector{2, Float64}}(undef, niterations)

srand(12345)

Expand All @@ -33,7 +33,7 @@ simulateChain!(chain, P_AM, Szero2)
@test mean(chain) μ1 atol = 0.01
@test MonteCarloMarkovKernels.cov(chain) Σ1 atol = 0.05

vs = Vector{Vector{Float64}}(2)
vs = Vector{Vector{Float64}}(undef, 2)
for i = 1:2
vs[i] = (x->x[i]).(chain)
end
Expand Down

0 comments on commit 53b7209

Please sign in to comment.