@@ -109,13 +109,13 @@ using DynamicPPL:
109
109
VariableOrderAccumulator (2 )
110
110
end
111
111
112
- @testset " merge and subset " begin
112
+ @testset " merge" begin
113
113
@test merge (LogPriorAccumulator (1.0 ), LogPriorAccumulator (2.0 )) ==
114
- LogPriorAccumulator (3 .0 )
114
+ LogPriorAccumulator (2 .0 )
115
115
@test merge (LogJacobianAccumulator (1.0 ), LogJacobianAccumulator (2.0 )) ==
116
- LogJacobianAccumulator (3 .0 )
116
+ LogJacobianAccumulator (2 .0 )
117
117
@test merge (LogLikelihoodAccumulator (1.0 ), LogLikelihoodAccumulator (2.0 )) ==
118
- LogLikelihoodAccumulator (3 .0 )
118
+ LogLikelihoodAccumulator (2 .0 )
119
119
120
120
@test merge (
121
121
VariableOrderAccumulator (1 , Dict {VarName,Int} ()),
@@ -132,6 +132,49 @@ using DynamicPPL:
132
132
1 , Dict {VarName,Int} ((@varname (a) => 2 , @varname (b) => 2 , @varname (c) => 3 ))
133
133
)
134
134
end
135
+
136
+ @testset " subset" begin
137
+ @test subset (LogPriorAccumulator (1.0 ), VarName[]) == LogPriorAccumulator (1.0 )
138
+ @test subset (LogJacobianAccumulator (1.0 ), VarName[]) ==
139
+ LogJacobianAccumulator (1.0 )
140
+ @test subset (LogLikelihoodAccumulator (1.0 ), VarName[]) ==
141
+ LogLikelihoodAccumulator (1.0 )
142
+
143
+ @test subset (
144
+ VariableOrderAccumulator (1 , Dict {VarName,Int} ()),
145
+ VarName[@varname (a), @varname (b)],
146
+ ) == VariableOrderAccumulator (1 , Dict {VarName,Int} ())
147
+ @test subset (
148
+ VariableOrderAccumulator (
149
+ 2 , Dict {VarName,Int} ((@varname (a) => 1 , @varname (b) => 2 ))
150
+ ),
151
+ VarName[@varname (a)],
152
+ ) == VariableOrderAccumulator (2 , Dict {VarName,Int} ((@varname (a) => 1 )))
153
+ @test subset (
154
+ VariableOrderAccumulator (
155
+ 2 , Dict {VarName,Int} ((@varname (a) => 1 , @varname (b) => 2 ))
156
+ ),
157
+ VarName[],
158
+ ) == VariableOrderAccumulator (2 , Dict {VarName,Int} ())
159
+ @test subset (
160
+ VariableOrderAccumulator (
161
+ 2 ,
162
+ Dict {VarName,Int} ((
163
+ @varname (a) => 1 ,
164
+ @varname (a. b. c) => 2 ,
165
+ @varname (a. b. c. d[1 ]) => 2 ,
166
+ @varname (b) => 3 ,
167
+ @varname (c[1 ]) => 4 ,
168
+ )),
169
+ ),
170
+ VarName[@varname (a. b), @varname (b)],
171
+ ) == VariableOrderAccumulator (
172
+ 2 ,
173
+ Dict {VarName,Int} ((
174
+ @varname (a. b. c) => 2 , @varname (a. b. c. d[1 ]) => 2 , @varname (b) => 3
175
+ )),
176
+ )
177
+ end
135
178
end
136
179
137
180
@testset " accumulator tuples" begin
@@ -140,7 +183,7 @@ using DynamicPPL:
140
183
lp_f32 = LogPriorAccumulator (1.0f0 )
141
184
ll_f64 = LogLikelihoodAccumulator (1.0 )
142
185
ll_f32 = LogLikelihoodAccumulator (1.0f0 )
143
- np_i64 = VariableOrderAccumulator (1 )
186
+ vo_i64 = VariableOrderAccumulator (1 )
144
187
145
188
@testset " constructors" begin
146
189
@test AccumulatorTuple (lp_f64, ll_f64) == AccumulatorTuple ((lp_f64, ll_f64))
@@ -154,22 +197,22 @@ using DynamicPPL:
154
197
end
155
198
156
199
@testset " basic operations" begin
157
- at_all64 = AccumulatorTuple (lp_f64, ll_f64, np_i64 )
200
+ at_all64 = AccumulatorTuple (lp_f64, ll_f64, vo_i64 )
158
201
159
202
@test at_all64[:LogPrior ] == lp_f64
160
203
@test at_all64[:LogLikelihood ] == ll_f64
161
- @test at_all64[:VariableOrder ] == np_i64
204
+ @test at_all64[:VariableOrder ] == vo_i64
162
205
163
- @test haskey (AccumulatorTuple (np_i64 ), Val (:VariableOrder ))
164
- @test ~ haskey (AccumulatorTuple (np_i64 ), Val (:LogPrior ))
165
- @test length (AccumulatorTuple (lp_f64, ll_f64, np_i64 )) == 3
206
+ @test haskey (AccumulatorTuple (vo_i64 ), Val (:VariableOrder ))
207
+ @test ~ haskey (AccumulatorTuple (vo_i64 ), Val (:LogPrior ))
208
+ @test length (AccumulatorTuple (lp_f64, ll_f64, vo_i64 )) == 3
166
209
@test keys (at_all64) == (:LogPrior , :LogLikelihood , :VariableOrder )
167
- @test collect (at_all64) == [lp_f64, ll_f64, np_i64 ]
210
+ @test collect (at_all64) == [lp_f64, ll_f64, vo_i64 ]
168
211
169
212
# Replace the existing LogPriorAccumulator
170
213
@test setacc!! (at_all64, lp_f32)[:LogPrior ] == lp_f32
171
214
# Check that setacc!! didn't modify the original
172
- @test at_all64 == AccumulatorTuple (lp_f64, ll_f64, np_i64 )
215
+ @test at_all64 == AccumulatorTuple (lp_f64, ll_f64, vo_i64 )
173
216
# Add a new accumulator type.
174
217
@test setacc!! (AccumulatorTuple (lp_f64), ll_f64) ==
175
218
AccumulatorTuple (lp_f64, ll_f64)
@@ -197,6 +240,52 @@ using DynamicPPL:
197
240
acc -> convert_eltype (Float64, acc), accs, Val (:LogLikelihood )
198
241
) == AccumulatorTuple (lp_f32, LogLikelihoodAccumulator (1.0 ))
199
242
end
243
+
244
+ @testset " merge" begin
245
+ vo1 = VariableOrderAccumulator (
246
+ 1 , Dict {VarName,Int} (@varname (a) => 1 , @varname (b) => 1 )
247
+ )
248
+ vo2 = VariableOrderAccumulator (
249
+ 2 , Dict {VarName,Int} (@varname (a) => 2 , @varname (c) => 2 )
250
+ )
251
+ accs1 = AccumulatorTuple (lp_f64, ll_f64, vo1)
252
+ accs2 = AccumulatorTuple (lp_f32, vo2)
253
+ @test merge (accs1, accs2) == AccumulatorTuple (
254
+ ll_f64,
255
+ lp_f32,
256
+ VariableOrderAccumulator (
257
+ 2 ,
258
+ Dict {VarName,Int} (@varname (a) => 2 , @varname (b) => 1 , @varname (c) => 2 ),
259
+ ),
260
+ )
261
+ @test merge (AccumulatorTuple (), accs1) == accs1
262
+ @test merge (accs1, AccumulatorTuple ()) == accs1
263
+ @test merge (accs1, accs1) == accs1
264
+ end
265
+
266
+ @testset " subset" begin
267
+ accs = AccumulatorTuple (
268
+ lp_f64,
269
+ ll_f64,
270
+ VariableOrderAccumulator (
271
+ 1 ,
272
+ Dict {VarName,Int} (
273
+ @varname (a. b) => 1 , @varname (a. b[1 ]) => 2 , @varname (b) => 1
274
+ ),
275
+ ),
276
+ )
277
+
278
+ @test subset (accs, VarName[]) == AccumulatorTuple (
279
+ lp_f64, ll_f64, VariableOrderAccumulator (1 , Dict {VarName,Int} ())
280
+ )
281
+ @test subset (accs, VarName[@varname (a)]) == AccumulatorTuple (
282
+ lp_f64,
283
+ ll_f64,
284
+ VariableOrderAccumulator (
285
+ 1 , Dict {VarName,Int} (@varname (a. b) => 1 , @varname (a. b[1 ]) => 2 )
286
+ ),
287
+ )
288
+ end
200
289
end
201
290
end
202
291
0 commit comments