1111
1212@testset " ProductSplit" begin
1313
14+ various_iters = [(1 : 10 ,),(1 : 10 ,4 : 6 ),(1 : 10 ,4 : 6 ,1 : 4 ),(1 : 2 : 10 ,4 : 1 : 6 ),
15+ (1 : 2 ,Base. OneTo (4 ),1 : 3 : 10 )]
16+
1417 function split_across_processors_iterators (arr:: Base.Iterators.ProductIterator ,num_procs,proc_id)
1518
1619 num_tasks = length (arr);
7174 iters = (10 : - 1 : 10 ,6 : - 2 : 0 )
7275 @test_throws ParallelUtilities. DecreasingIteratorError ProductSplit (iters,3 ,2 )
7376 end
77+ @testset " mixed" begin
78+ for iters in [(1 : 2 ,4 : 2 : 6 ),(1 : 2 ,Base. OneTo (4 ),1 : 3 : 10 )]
79+ checkPSconstructor (iters)
80+ end
81+ end
7482
7583 @testset " empty" begin
7684 iters = (1 : 1 ,)
8088 end
8189
8290 @testset " first and last ind" begin
83- iters = (1 : 10 ,)
84- ps = ProductSplit (iters,2 ,1 )
85- @test firstindex (ps) == 1
86- @test ps. firstind == 1
87- @test ps. lastind == div (length (iters[1 ]),2 )
88- @test lastindex (ps) == div (length (iters[1 ]),2 )
89- @test lastindex (ps) == length (ps)
90- ps = ProductSplit (iters,2 ,2 )
91- @test ps. firstind == div (length (iters[1 ]),2 ) + 1
92- @test firstindex (ps) == 1
93- @test ps. lastind == length (iters[1 ])
94- @test lastindex (ps) == length (ps)
95-
96- for np in length (iters[1 ])+ 1 : length (iters[1 ])+ 10 ,
97- p in length (iters[1 ])+ 1 : np
98-
99- ps = ProductSplit (iters,np,p)
100- @test ps. firstind == length (iters[1 ]) + 1
101- @test ps. lastind == length (iters[1 ])
102- end
91+ for iters in [(1 : 10 ,),(1 : 2 ,Base. OneTo (4 ),1 : 3 : 10 )]
92+ ps = ProductSplit (iters,2 ,1 )
93+ @test firstindex (ps) == 1
94+ @test ps. firstind == 1
95+ @test ps. lastind == div (ntasks (iters),2 )
96+ @test lastindex (ps) == div (ntasks (iters),2 )
97+ @test lastindex (ps) == length (ps)
98+ ps = ProductSplit (iters,2 ,2 )
99+ @test ps. firstind == div (ntasks (iters),2 ) + 1
100+ @test firstindex (ps) == 1
101+ @test ps. lastind == ntasks (iters)
102+ @test lastindex (ps) == length (ps)
103+
104+ for np in ntasks (iters)+ 1 : ntasks (iters)+ 10 ,
105+ p in ntasks (iters)+ 1 : np
106+
107+ ps = ProductSplit (iters,np,p)
108+ @test ps. firstind == ntasks (iters) + 1
109+ @test ps. lastind == ntasks (iters)
110+ end
111+ end
103112 end
104113 end
105114
@@ -108,23 +117,21 @@ end
108117
109118 @test ParallelUtilities. _first (()) == ()
110119
111- for iters in [(1 : 10 ,),(1 : 10 ,4 : 6 ),(1 : 10 ,4 : 6 ,1 : 4 ),(1 : 2 : 10 ,4 : 1 : 6 )],
112- np= 1 : 5 ntasks (iters)
120+ for iters in various_iters,np= 1 : 5 ntasks (iters)
113121
114122 ps = ProductSplit (iters,np,1 )
115123 @test first (ps) == ( isempty (ps) ? nothing : map (first,iters) )
116124 end
117125
118126 iters = (1 : 1 ,)
119- ps = ProductSplit (iters,2 length (iters[ 1 ]), length (iters[ 1 ] )+ 1 ) # must be empty
127+ ps = ProductSplit (iters,2 ntasks (iters), ntasks (iters)+ 1 ) # must be empty
120128 @test first (ps) === nothing
121129 end
122130 @testset " last" begin
123131
124132 @test ParallelUtilities. _last (()) == ()
125133
126- for iters in [(1 : 10 ,),(1 : 10 ,4 : 6 ),(1 : 10 ,4 : 6 ,1 : 4 ),(1 : 2 : 10 ,4 : 1 : 6 )],
127- np= 1 : 5 ntasks (iters)
134+ for iters in various_iters,np= 1 : 5 ntasks (iters)
128135
129136 ps = ProductSplit (iters,np,np)
130137 @test last (ps) == ( isempty (ps) ? nothing : map (last,iters) )
155162 end
156163 end
157164
158- for iters in [(1 : 10 ,),(1 : 10 ,4 : 6 ),(1 : 10 ,4 : 6 ,1 : 4 ),(1 : 2 : 10 ,4 : 1 : 6 )],
159- fn in [maximum,minimum,extrema]
165+ for iters in various_iters, fn in [maximum,minimum,extrema]
160166
161167 checkPSextrema (iters,fn)
162168 end
165171 @testset " extremadims" begin
166172 ps = ProductSplit ((1 : 10 ,),2 ,1 )
167173 @test ParallelUtilities. _extremadims (ps,1 ,()) == ()
168- for iters in [(1 : 10 ,),(1 : 10 ,4 : 6 ),(1 : 10 ,4 : 6 ,1 : 4 ),(1 : 2 : 10 ,4 : 1 : 6 )]
174+ for iters in various_iters
175+
169176 dims = length (iters)
170177 for np = 1 : 5 ntasks (iters), proc_id = 1 : np
171178 ps = ProductSplit (iters,np,proc_id)
208215 end
209216 end
210217
211- for iters in [( 1 : 10 ,),( 1 : 10 , 4 : 6 ),( 1 : 10 , 4 : 6 , 1 : 4 ),( 1 : 2 : 10 , 4 : 1 : 6 )]
218+ for iters in various_iters
212219 checkifpresent (iters)
213220 end
214221
219226 n = 10
220227 np,proc_id = 5 ,3
221228 @test evenlyscatterproduct (n,np,proc_id) == ProductSplit ((1 : n,),np,proc_id)
222- for iters in [( 1 : 10 ,),( 1 : 10 , 4 : 6 ),( 1 : 10 , 4 : 6 , 1 : 4 ),( 1 : 2 : 10 , 4 : 1 : 6 )]
229+ for iters in various_iters
223230 @test evenlyscatterproduct (iters,np,proc_id) == ProductSplit (iters,np,proc_id)
224231 itp = Iterators. product (iters... )
225232 @test evenlyscatterproduct (itp,np,proc_id) == ProductSplit (iters,np,proc_id)
247254 @test procrange_recast (iters,ps,2 ) == 1 : 1
248255 @test procrange_recast (ps,2 ) == 1 : 1
249256
257+ iters = (Base. OneTo (2 ),2 : 4 )
258+ ps = ProductSplit (iters,2 ,1 )
259+ @test procrange_recast (iters,ps,1 ) == 1 : 1
260+ @test procrange_recast (iters,ps,2 ) == 1 : 1
261+ @test procrange_recast (iters,ps,ntasks (iters)) == 1 : length (ps)
262+
250263 for np_new in 1 : 5 ntasks (iters)
251264 for proc_id_new= 1 : np_new
252265 ps_new = ProductSplit (iters,np_new,proc_id_new)
279292
280293 @testset " localindex" begin
281294
282- for iters in [( 1 : 10 ,),( 1 : 10 , 4 : 6 ),( 1 : 10 , 4 : 6 , 1 : 4 ),( 1 : 2 : 10 , 4 : 1 : 6 )]
295+ for iters in various_iters
283296 for np= 1 : 5 ntasks (iters),proc_id= 1 : np
284297 ps = ProductSplit (iters,np,proc_id)
285298 for (ind,val) in enumerate (ps)
294307 end
295308
296309 @testset " procid_and_localindex" begin
297- for iters in [( 1 : 10 ,),( 1 : 10 , 4 : 6 ),( 1 : 10 , 4 : 6 , 1 : 4 ),( 1 : 2 : 10 , 4 : 1 : 6 )]
310+ for iters in various_iters
298311 for np= 1 : ntasks (iters),proc_id= 1 : np
299312 ps_col = collect (ProductSplit (iters,np,proc_id))
300313 ps_col_rev = [reverse (t) for t in ps_col]
315328
316329 @test ParallelUtilities. childindex ((),1 ) == (1 ,)
317330
318- for iters in [( 1 : 10 ,),( 1 : 10 , 4 : 6 ),( 1 : 10 , 4 : 6 , 1 : 4 ),( 1 : 2 : 10 , 4 : 1 : 6 )]
331+ for iters in various_iters
319332 for np= 1 : ntasks (iters),p= 1 : np
320333 ps = ProductSplit (iters,np,p)
321334 ps_col = collect (ps)
0 commit comments