@@ -35,14 +35,15 @@ include("interface.jl")
35
35
@test Logging. current_logger () === CURRENT_LOGGER
36
36
37
37
# test output type and size
38
- @test chain isa Vector{MyTransition}
38
+ @test chain isa Vector{<: MyTransition }
39
39
@test length (chain) == N
40
40
41
41
# test some statistical properties
42
- @test mean (x. a for x in chain) ≈ 0.5 atol= 6e-2
43
- @test var (x. a for x in chain) ≈ 1 / 12 atol= 5e-3
44
- @test mean (x. b for x in chain) ≈ 0.0 atol= 5e-2
45
- @test var (x. b for x in chain) ≈ 1 atol= 6e-2
42
+ tail_chain = @view chain[2 : end ]
43
+ @test mean (x. a for x in tail_chain) ≈ 0.5 atol= 6e-2
44
+ @test var (x. a for x in tail_chain) ≈ 1 / 12 atol= 5e-3
45
+ @test mean (x. b for x in tail_chain) ≈ 0.0 atol= 5e-2
46
+ @test var (x. b for x in tail_chain) ≈ 1 atol= 6e-2
46
47
end
47
48
48
49
@testset " Juno" begin
@@ -118,26 +119,28 @@ include("interface.jl")
118
119
end
119
120
120
121
Random. seed! (1234 )
121
- chains = sample (MyModel (), MySampler (), MCMCThreads (), 10_000 , 1000 ;
122
+ N = 10_000
123
+ chains = sample (MyModel (), MySampler (), MCMCThreads (), N, 1000 ;
122
124
chain_type = MyChain)
123
125
124
126
# test output type and size
125
- @test chains isa Vector{MyChain}
127
+ @test chains isa Vector{<: MyChain }
126
128
@test length (chains) == 1000
127
- @test all (x -> length (x. as) == length (x. bs) == 10_000 , chains)
129
+ @test all (x -> length (x. as) == length (x. bs) == N , chains)
128
130
129
131
# test some statistical properties
130
- @test all (x -> isapprox (mean (x. as), 0.5 ; atol= 1e-2 ), chains)
131
- @test all (x -> isapprox (var (x. as), 1 / 12 ; atol= 5e-3 ), chains)
132
- @test all (x -> isapprox (mean (x. bs), 0 ; atol= 5e-2 ), chains)
133
- @test all (x -> isapprox (var (x. bs), 1 ; atol= 5e-2 ), chains)
132
+ @test all (x -> isapprox (mean (@view x. as[ 2 : end ] ), 0.5 ; atol= 1e-2 ), chains)
133
+ @test all (x -> isapprox (var (@view x. as[ 2 : end ] ), 1 / 12 ; atol= 5e-3 ), chains)
134
+ @test all (x -> isapprox (mean (@view x. bs[ 2 : end ] ), 0 ; atol= 5e-2 ), chains)
135
+ @test all (x -> isapprox (var (@view x. bs[ 2 : end ] ), 1 ; atol= 5e-2 ), chains)
134
136
135
137
# test reproducibility
136
138
Random. seed! (1234 )
137
- chains2 = sample (MyModel (), MySampler (), MCMCThreads (), 10_000 , 1000 ;
139
+ chains2 = sample (MyModel (), MySampler (), MCMCThreads (), N , 1000 ;
138
140
chain_type = MyChain)
139
141
140
- @test all (((x, y),) -> x. as == y. as && x. bs == y. bs, zip (chains, chains2))
142
+ @test all (c1. as[i] === c2. as[i] for (c1, c2) in zip (chains, chains2), i in 1 : N)
143
+ @test all (c1. bs[i] === c2. bs[i] for (c1, c2) in zip (chains, chains2), i in 1 : N)
141
144
142
145
# Suppress output.
143
146
logs, _ = collect_test_logs (; min_level= Logging. LogLevel (- 1 )) do
@@ -167,27 +170,30 @@ include("interface.jl")
167
170
include (" interface.jl" )
168
171
end
169
172
173
+ N = 10_000
170
174
Random. seed! (1234 )
171
- chains = sample (MyModel (), MySampler (), MCMCDistributed (), 10_000 , 1000 ;
175
+ chains = sample (MyModel (), MySampler (), MCMCDistributed (), N , 1000 ;
172
176
chain_type = MyChain)
173
177
174
178
# Test output type and size.
175
- @test chains isa Vector{MyChain}
179
+ @test chains isa Vector{<: MyChain }
180
+ @test all (c. as[1 ] === missing for c in chains)
176
181
@test length (chains) == 1000
177
- @test all (x -> length (x. as) == length (x. bs) == 10_000 , chains)
182
+ @test all (x -> length (x. as) == length (x. bs) == N , chains)
178
183
179
184
# Test some statistical properties.
180
- @test all (x -> isapprox (mean (x. as), 0.5 ; atol= 1e-2 ), chains)
181
- @test all (x -> isapprox (var (x. as), 1 / 12 ; atol= 5e-3 ), chains)
182
- @test all (x -> isapprox (mean (x. bs), 0 ; atol= 5e-2 ), chains)
183
- @test all (x -> isapprox (var (x. bs), 1 ; atol= 5e-2 ), chains)
185
+ @test all (x -> isapprox (mean (@view x. as[ 2 : end ] ), 0.5 ; atol= 1e-2 ), chains)
186
+ @test all (x -> isapprox (var (@view x. as[ 2 : end ] ), 1 / 12 ; atol= 5e-3 ), chains)
187
+ @test all (x -> isapprox (mean (@view x. bs[ 2 : end ] ), 0 ; atol= 5e-2 ), chains)
188
+ @test all (x -> isapprox (var (@view x. bs[ 2 : end ] ), 1 ; atol= 5e-2 ), chains)
184
189
185
190
# Test reproducibility.
186
191
Random. seed! (1234 )
187
- chains2 = sample (MyModel (), MySampler (), MCMCDistributed (), 10_000 , 1000 ;
192
+ chains2 = sample (MyModel (), MySampler (), MCMCDistributed (), N , 1000 ;
188
193
chain_type = MyChain)
189
194
190
- @test all (((x, y),) -> x. as == y. as && x. bs == y. bs, zip (chains, chains2))
195
+ @test all (c1. as[i] === c2. as[i] for (c1, c2) in zip (chains, chains2), i in 1 : N)
196
+ @test all (c1. bs[i] === c2. bs[i] for (c1, c2) in zip (chains, chains2), i in 1 : N)
191
197
192
198
# Suppress output.
193
199
logs, _ = collect_test_logs (; min_level= Logging. LogLevel (- 1 )) do
@@ -201,7 +207,7 @@ include("interface.jl")
201
207
chain1 = sample (MyModel (), MySampler (), 100 ; sleepy = true )
202
208
chain2 = sample (MyModel (), MySampler (), 100 ; sleepy = true , chain_type = MyChain)
203
209
204
- @test chain1 isa Vector{MyTransition}
210
+ @test chain1 isa Vector{<: MyTransition }
205
211
@test chain2 isa MyChain
206
212
end
207
213
@@ -217,10 +223,15 @@ include("interface.jl")
217
223
break
218
224
end
219
225
226
+ # don't save missing values
227
+ t. a === missing && continue
228
+
220
229
push! (as, t. a)
221
230
push! (bs, t. b)
222
231
end
223
232
233
+ @test length (as) == length (bs) == 998
234
+
224
235
@test mean (as) ≈ 0.5 atol= 1e-2
225
236
@test var (as) ≈ 1 / 12 atol= 5e-3
226
237
@test mean (bs) ≈ 0.0 atol= 5e-2
0 commit comments