mixle.data.partition module¶
Structure-aware partitioning – one place that splits a dataset into chunks while honoring its
SampleStructure.
This replaces the inline striding in seq_encode (data[i::C]). For strideable structures
(IID / exchangeable / sequential-records) it reproduces that striding exactly, so the existing fast path
is bit-identical. For PARTIALLY_EXCHANGEABLE data it strides at the group level – every record of
a group lands in the same partition – so a hierarchical model never sees a group split across chunks.
- partition_records(records, structure, n)[source]
Split
recordsintonpartitions respectingstructure.Strideable structures give
records[k::n](identical to the historical chunking); a partially-exchangeable structure groups by its key and round-robins whole groups across partitions.nmust be a positive integer – a nonpositive or fractionalnused to silently collapse to a single partition instead of failing.
- num_chunks_for(size, num_chunks=1, chunk_size=None)[source]
Resolve the chunk count from an explicit
num_chunksor a targetchunk_size(as seq_encode does).Both controls are validated as exact positive integers before any arithmetic:
chunk_size=0used to raise a bareZeroDivisionError, and a negative/fractionalchunk_sizeor a nonpositive/fractionalnum_chunksused to silently collapse to one chunk instead of failing – these bound memory, so silently weakening them can materially change an execution plan. A non-defaultnum_chunkssupplied together withchunk_sizeis rejected as conflicting rather than silently lettingchunk_sizewin.
- encode_partitions(records, encoder, structure=EXCHANGEABLE, num_chunks=1, chunk_size=None)[source]
Partition
recordsbystructureandencoder.seq_encodeeach part ->[(count, payload)].