@@ -3,7 +3,7 @@ using Test
3
3
4
4
@testset " merge_union" begin
5
5
@test @inferred (MCMCChains. merge_union ((a = [1 ], b = [3.0 ]), (c = [3 ], a = [2.5 ]))) ==
6
- (a = [1.0 , 2.5 ], b = [3.0 ], c = [3 ])
6
+ (a = [1.0 , 2.5 ], b = [3.0 ], c = [3 ])
7
7
end
8
8
9
9
@testset " concatenation tests" begin
19
19
20
20
# Test dim 1
21
21
c1_2 = cat (c1, c2; dims = 1 )
22
- @test c1_2. value. data == cat (v1, v2, dims= 1 )
22
+ @test c1_2. value. data == cat (v1, v2, dims = 1 )
23
23
@test range (c1_2) == 1 : 1 : 1000
24
24
@test names (c1_2) == names (c1) == names (c2)
25
25
@test chains (c1_2) == chains (c1) == chains (c2)
26
26
@test c1_2. value == vcat (c1, c2). value
27
27
28
28
# Test dim 2
29
29
c1_3 = cat (c1, c3; dims = 2 )
30
- @test c1_3. value. data == cat (v1, v3, dims= 2 )
30
+ @test c1_3. value. data == cat (v1, v3, dims = 2 )
31
31
@test range (c1_3) == 1 : 1 : 500
32
- @test names (c1_3) == cat (names (c1), names (c3), dims= 1 )
32
+ @test names (c1_3) == cat (names (c1), names (c3), dims = 1 )
33
33
@test chains (c1_3) == chains (c1) == chains (c3)
34
34
@test c1_3. value == hcat (c1, c3). value
35
35
36
36
# Test dim 3
37
37
c1_4 = cat (c1, c4; dims = 3 )
38
- @test c1_4. value. data == cat (v1, v4, dims= 3 )
38
+ @test c1_4. value. data == cat (v1, v4, dims = 3 )
39
39
@test range (c1_4) == 1 : 1 : 500
40
40
@test names (c1_4) == names (c1) == names (c4)
41
41
@test length (chains (c1_4)) == length (chains (c1)) + length (chains (c4))
50
50
@test_throws ArgumentError vcat (chn, Chains (rand (2 , 5 , 2 )))
51
51
52
52
# incorrect names
53
- @test_throws ArgumentError vcat (chn, Chains (rand (10 , 5 , 2 ), [" a" , " b" , " c" , " d" , " f" ]; start= 11 ))
53
+ @test_throws ArgumentError vcat (
54
+ chn,
55
+ Chains (rand (10 , 5 , 2 ), [" a" , " b" , " c" , " d" , " f" ]; start = 11 ),
56
+ )
54
57
55
58
# incorrect number of chains
56
- @test_throws ArgumentError vcat (chn, Chains (rand (10 , 5 , 3 ), [" a" , " b" , " c" , " d" , " e" ]; start= 11 ))
59
+ @test_throws ArgumentError vcat (
60
+ chn,
61
+ Chains (rand (10 , 5 , 3 ), [" a" , " b" , " c" , " d" , " e" ]; start = 11 ),
62
+ )
57
63
58
64
# concate the same chain
59
65
chn_shifted = setrange (chn, 11 : 20 )
126
132
@test names (chn2) == vcat (names (chn), names (chn1))
127
133
@test range (chn2) == 1 : 10
128
134
@test chn2. name_map == (parameters = [:a , :b , :e ], internal = [:c , :d ])
129
-
135
+
130
136
chn2a = cat (chn, chn1; dims = Val (2 ))
131
137
@test chn2a. value == chn2. value
132
138
@test chn2a. name_map == chn2. name_map
157
163
@test range (chn2) == 1 : 10
158
164
# just keep the name map of the first argument
159
165
@test chn2. name_map == (parameters = [:a , :b ], internal = [:c ])
160
-
166
+
161
167
chn2a = cat (chn, chn1; dims = Val (3 ))
162
168
@test chn2a. value == chn2. value
163
169
@test chn2a. name_map == chn2. name_map
167
173
@test chn2b. value == chn2. value
168
174
@test chn2b. name_map == chn2. name_map
169
175
@test chn2b. info == chn2. info
170
- end
176
+
177
+ # check merging of info field
178
+ chn = Chains (
179
+ rand (10 , 3 , 1 ),
180
+ [" a" , " b" , " c" ],
181
+ info = (
182
+ start_time = 1 ,
183
+ stop_time = 2 ,
184
+ samplerstate = " state1" ,
185
+ otherinfo = " info1" ,
186
+ ),
187
+ )
188
+ chn1 = Chains (
189
+ rand (10 , 3 , 1 ),
190
+ [" a" , " b" , " c" ],
191
+ info = (
192
+ start_time = 3 ,
193
+ stop_time = 4 ,
194
+ samplerstate = " state2" ,
195
+ otherinfo = " info2" ,
196
+ ),
197
+ )
198
+ chn3 = chainscat (chn, chn1)
199
+ # these three fields should be concatenated
200
+ @test chn3. info. start_time == [1 , 3 ]
201
+ @test chn3. info. stop_time == [2 , 4 ]
202
+ @test chn3. info. samplerstate == [" state1" , " state2" ]
203
+ # other fields should just be taken from the first chain
204
+ @test chn3. info. otherinfo == " info1"
205
+ end
0 commit comments