Skip to content

Commit 176640e

Browse files
authored
Merge pull request #28 from FredericWantiez/feature/format
Use JuliaFormatter
2 parents 1f7251e + 93fa6f4 commit 176640e

File tree

12 files changed

+223
-180
lines changed

12 files changed

+223
-180
lines changed

.JuliaFormatter.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
style="blue"

.github/workflows/Format.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Format
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
9+
jobs:
10+
format:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
- uses: julia-actions/setup-julia@latest
15+
with:
16+
version: 1
17+
- name: Format code
18+
run: |
19+
using Pkg
20+
Pkg.add(; name="JuliaFormatter", uuid="98e50ef6-434e-11e9-1051-2b60c6c9e899")
21+
using JuliaFormatter
22+
format("."; verbose=true)
23+
shell: julia --color=yes {0}
24+
- uses: reviewdog/action-suggester@v1
25+
if: github.event_name == 'pull_request'
26+
with:
27+
tool_name: JuliaFormatter
28+
fail_on_error: true

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
[![Build Status](https://github.com/TuringLang/AdvancedPS.jl/workflows/CI/badge.svg?branch=master)](https://github.com/TuringLang/AdvancedPS.jl/actions?query=workflow%3ACI%20branch%3Amaster)
44
[![Coverage](https://codecov.io/gh/TuringLang/AdvancedPS.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/TuringLang/AdvancedPS.jl)
55
[![Coverage](https://coveralls.io/repos/github/TuringLang/AdvancedPS.jl/badge.svg?branch=master)](https://coveralls.io/github/TuringLang/AdvancedPS.jl?branch=master)
6+
[![Code Style: Blue](https://img.shields.io/badge/code%20style-blue-4495d1.svg)](https://github.com/invenia/BlueStyle)
67

78
### Reference
89

src/AdvancedPS.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
module AdvancedPS
22

3-
import AbstractMCMC
4-
import Distributions
5-
import Libtask
6-
import Random
7-
import StatsFuns
3+
using AbstractMCMC: AbstractMCMC
4+
using Distributions: Distributions
5+
using Libtask: Libtask
6+
using Random: Random
7+
using StatsFuns: StatsFuns
88

99
include("resampling.jl")
1010
include("container.jl")

src/container.jl

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ end
66
const Particle = Trace
77

88
function Trace(f)
9-
ctask = let f=f
9+
ctask = let f = f
1010
Libtask.CTask() do
1111
res = f()
1212
Libtask.produce(nothing)
@@ -34,7 +34,7 @@ reset_model(f) = deepcopy(f)
3434
delete_retained!(f) = nothing
3535

3636
# Task copying version of fork for Trace.
37-
function fork(trace::Trace, isref::Bool = false)
37+
function fork(trace::Trace, isref::Bool=false)
3838
newtrace = copy(trace)
3939
isref && delete_retained!(newtrace.f)
4040

@@ -48,7 +48,7 @@ end
4848
# Create new task and copy randomness
4949
function forkr(trace::Trace)
5050
newf = reset_model(trace.f)
51-
ctask = let f=trace.ctask.task.code
51+
ctask = let f = trace.ctask.task.code
5252
Libtask.CTask() do
5353
res = f()
5454
Libtask.produce(nothing)
@@ -105,7 +105,7 @@ end
105105
function Base.push!(pc::ParticleContainer, p::Particle)
106106
push!(pc.vals, p)
107107
push!(pc.logWs, 0.0)
108-
pc
108+
return pc
109109
end
110110

111111
# clones a theta-particle
@@ -116,7 +116,7 @@ function Base.copy(pc::ParticleContainer)
116116
# copy weights
117117
logWs = copy(pc.logWs)
118118

119-
ParticleContainer(vals, logWs)
119+
return ParticleContainer(vals, logWs)
120120
end
121121

122122
"""
@@ -183,9 +183,9 @@ of the particle `weights`. For Particle Gibbs sampling, one can provide a refere
183183
function resample_propagate!(
184184
rng::Random.AbstractRNG,
185185
pc::ParticleContainer,
186-
randcat = resample_systematic,
187-
ref::Union{Particle, Nothing} = nothing;
188-
weights = getweights(pc)
186+
randcat=resample_systematic,
187+
ref::Union{Particle,Nothing}=nothing;
188+
weights=getweights(pc),
189189
)
190190
# check that weights are not NaN
191191
@assert !any(isnan, weights)
@@ -232,24 +232,24 @@ function resample_propagate!(
232232
pc.vals = children
233233
reset_logweights!(pc)
234234

235-
pc
235+
return pc
236236
end
237237

238238
function resample_propagate!(
239239
rng::Random.AbstractRNG,
240240
pc::ParticleContainer,
241241
resampler::ResampleWithESSThreshold,
242-
ref::Union{Particle,Nothing} = nothing;
243-
weights = getweights(pc)
242+
ref::Union{Particle,Nothing}=nothing;
243+
weights=getweights(pc),
244244
)
245245
# Compute the effective sample size ``1 / ∑ wᵢ²`` with normalized weights ``wᵢ``
246246
ess = inv(sum(abs2, weights))
247247

248248
if ess resampler.threshold * length(pc)
249-
resample_propagate!(rng, pc, resampler.resampler, ref; weights = weights)
249+
resample_propagate!(rng, pc, resampler.resampler, ref; weights=weights)
250250
end
251251

252-
pc
252+
return pc
253253
end
254254

255255
"""
@@ -290,9 +290,13 @@ function reweight!(pc::ParticleContainer)
290290

291291
# The posterior for models with random number of observations is not well-defined.
292292
if numdone != 0
293-
error("mis-aligned execution traces: # particles = ", n,
294-
" # completed trajectories = ", numdone,
295-
". Please make sure the number of observations is NOT random.")
293+
error(
294+
"mis-aligned execution traces: # particles = ",
295+
n,
296+
" # completed trajectories = ",
297+
numdone,
298+
". Please make sure the number of observations is NOT random.",
299+
)
296300
end
297301

298302
return false

0 commit comments

Comments
 (0)