@@ -233,22 +233,41 @@ def rectilinear_chunks(draw: st.DrawFn, *, shape: tuple[int, ...]) -> list[list[
233233 for size in shape :
234234 assert size > 0
235235 if size > 1 :
236- # Limit max chunks to 20 to avoid performance issues with large chunk grids
237- max_chunks = min (size - 1 , 20 )
238- nchunks = draw (st .integers (min_value = 1 , max_value = max_chunks ))
239- dividers = sorted (
240- draw (
241- st .lists (
242- st .integers (min_value = 1 , max_value = size - 1 ),
243- min_size = nchunks - 1 ,
244- max_size = nchunks - 1 ,
245- unique = True ,
236+ mode = draw (st .sampled_from (["expanded" , "rle" ]))
237+ if mode == "expanded" :
238+ event ("rectilinear expanded" )
239+ # Limit max chunks to 20 to avoid performance issues with large chunk grids
240+ max_chunks = min (size - 1 , 20 )
241+ nchunks = draw (st .integers (min_value = 1 , max_value = max_chunks ))
242+ dividers = sorted (
243+ draw (
244+ st .lists (
245+ st .integers (min_value = 1 , max_value = size - 1 ),
246+ min_size = nchunks - 1 ,
247+ max_size = nchunks - 1 ,
248+ unique = True ,
249+ )
246250 )
247251 )
248- )
249- chunk_shapes .append (
250- [a - b for a , b in zip (dividers + [size ], [0 ] + dividers , strict = False )]
251- )
252+ chunk_shapes .append (
253+ [a - b for a , b in zip (dividers + [size ], [0 ] + dividers , strict = False )]
254+ )
255+ else :
256+ # RLE mode: uniform chunks with optional remainder
257+ max_chunk_size = min (size , 20 )
258+ chunk_size = draw (st .integers (min_value = 1 , max_value = max_chunk_size ))
259+ n_full = size // chunk_size
260+ remainder = size % chunk_size
261+ chunks_list = [chunk_size ] * n_full
262+ if remainder > 0 :
263+ chunks_list .append (remainder )
264+ # Optionally shuffle to create non-contiguous duplicate patterns
265+ if draw (st .booleans ()):
266+ event ("rectilinear rle shuffled" )
267+ chunks_list = draw (st .permutations (chunks_list ))
268+ else :
269+ event ("rectilinear rle" )
270+ chunk_shapes .append (list (chunks_list ))
252271 else :
253272 chunk_shapes .append ([1 ])
254273 return chunk_shapes
0 commit comments