ó šÄïYc@sndZddlZdefd„ƒYZdefd„ƒYZdefd„ƒYZd efd „ƒYZdS( sDataset sampler.iÿÿÿÿNtSamplercBs eZdZd„Zd„ZRS(szBase class for samplers. All samplers should subclass `Sampler` and define `__iter__` and `__len__` methods. cCs t‚dS(N(tNotImplementedError(tself((s8build/bdist.linux-armv7l/egg/mxnet/gluon/data/sampler.pyt__iter__scCs t‚dS(N(R(R((s8build/bdist.linux-armv7l/egg/mxnet/gluon/data/sampler.pyt__len__!s(t__name__t __module__t__doc__RR(((s8build/bdist.linux-armv7l/egg/mxnet/gluon/data/sampler.pyRs tSequentialSamplercBs)eZdZd„Zd„Zd„ZRS(s„Samples elements from [0, length) sequentially. Parameters ---------- length : int Length of the sequence. cCs ||_dS(N(t_length(Rtlength((s8build/bdist.linux-armv7l/egg/mxnet/gluon/data/sampler.pyt__init__-scCstt|jƒƒS(N(titertrangeR (R((s8build/bdist.linux-armv7l/egg/mxnet/gluon/data/sampler.pyR0scCs|jS(N(R (R((s8build/bdist.linux-armv7l/egg/mxnet/gluon/data/sampler.pyR3s(RRRR RR(((s8build/bdist.linux-armv7l/egg/mxnet/gluon/data/sampler.pyR%s  t RandomSamplercBs)eZdZd„Zd„Zd„ZRS(s”Samples elements from [0, length) randomly without replacement. Parameters ---------- length : int Length of the sequence. cCs ||_dS(N(R (RR ((s8build/bdist.linux-armv7l/egg/mxnet/gluon/data/sampler.pyR ?scCs,tt|jƒƒ}tj|ƒt|ƒS(N(tlistR R trandomtshuffleR (Rtindices((s8build/bdist.linux-armv7l/egg/mxnet/gluon/data/sampler.pyRBs cCs|jS(N(R (R((s8build/bdist.linux-armv7l/egg/mxnet/gluon/data/sampler.pyRGs(RRRR RR(((s8build/bdist.linux-armv7l/egg/mxnet/gluon/data/sampler.pyR7s  t BatchSamplercBs,eZdZdd„Zd„Zd„ZRS(sZWraps over another `Sampler` and return mini-batches of samples. Parameters ---------- sampler : Sampler The source Sampler. batch_size : int Size of mini-batch. last_batch : {'keep', 'discard', 'rollover'} Specifies how the last batch is handled if batch_size does not evenly divide sequence length. If 'keep', the last batch will be returned directly, but will contain less element than `batch_size` requires. If 'discard', the last batch will be discarded. If 'rollover', the remaining elements will be rolled over to the next iteration. Examples -------- >>> sampler = gluon.data.SequentialSampler(10) >>> batch_sampler = gluon.data.BatchSampler(sampler, 3, 'keep') >>> list(batch_sampler) [[0, 1, 2], [3, 4, 5], [6, 7, 8], [9]] tkeepcCs(||_||_||_g|_dS(N(t_samplert _batch_sizet _last_batcht_prev(Rtsamplert batch_sizet last_batch((s8build/bdist.linux-armv7l/egg/mxnet/gluon/data/sampler.pyR gs   ccs¼|jg}|_xA|jD]6}|j|ƒt|ƒ|jkr|Vg}qqW|r¸|jdkrt|Vq¸|jdkr‡dS|jdkr¢||_q¸td|jƒ‚ndS(NRtdiscardtrolloversFlast_batch must be one of 'keep', 'discard', or 'rollover', but got %s(RRtappendtlenRRt ValueError(Rtbatchti((s8build/bdist.linux-armv7l/egg/mxnet/gluon/data/sampler.pyRms    cCs˜|jdkr.t|jƒ|jd|jS|jdkrQt|jƒ|jS|jdkrt|jƒt|jƒ|jStd|jƒ‚dS(NRiRRsFlast_batch must be one of 'keep', 'discard', or 'rollover', but got %s(RRRRRR (R((s8build/bdist.linux-armv7l/egg/mxnet/gluon/data/sampler.pyR€s!(RRRR RR(((s8build/bdist.linux-armv7l/egg/mxnet/gluon/data/sampler.pyRKs  (RRtobjectRRRR(((s8build/bdist.linux-armv7l/egg/mxnet/gluon/data/sampler.pyts