/usr/local/lib64/python3.6/site-packages/torch/utils/data/__pycache__
NameSizeModeActions
backward_compatibility.cpython-36.pyc4740644editdlrm
dataloader.cpython-36.pyc241450644editdlrm
dataloader_experimental.cpython-36.pyc42840644editdlrm
dataset.cpython-36.pyc170510644editdlrm
distributed.cpython-36.pyc48510644editdlrm
graph.cpython-36.pyc12660644editdlrm
sampler.cpython-36.pyc90120644editdlrm
sharding.cpython-36.pyc10110644editdlrm
_decorator.cpython-36.pyc60310644editdlrm
_typing.cpython-36.pyc98520644editdlrm
__init__.cpython-36.pyc14770644editdlrm
Edit: /usr/local/lib64/python3.6/site-packages/torch/utils/data/__pycache__/sampler.cpython-36.pyc (9012B)
3 Eg'@sddlZddlmZddlmZmZmZmZmZmZm Z edddZ Gdddee Z Gd d d e e Z Gd d d e e ZGd dde e ZGddde e ZGddde ee ZdS)N)Tensor)IteratorOptionalSequenceListTypeVarGenericSizedT_coT) covariantc@s6eZdZdZeeddddZeedddZ dS) SampleraBase class for all Samplers. Every Sampler subclass has to provide an :meth:`__iter__` method, providing a way to iterate over indices of dataset elements, and a :meth:`__len__` method that returns the length of the returned iterators. .. note:: The :meth:`__len__` method isn't strictly required by :class:`~torch.utils.data.DataLoader`, but is expected in any calculation involving the length of a :class:`~torch.utils.data.DataLoader`. N) data_sourcereturncCsdS)N)selfr rrD/usr/local/lib64/python3.6/site-packages/torch/utils/data/sampler.py__init__szSampler.__init__)rcCstdS)N)NotImplementedError)rrrr__iter__szSampler.__iter__) __name__ __module__ __qualname____doc__rr rrr rrrrrr s r c@sFeZdZUdZeeddddZeedddZ edd d Z dS) SequentialSamplerz~Samples elements sequentially, always in the same order. Args: data_source (Dataset): dataset to sample from N)r rcCs ||_dS)N)r )rr rrrr>szSequentialSampler.__init__)rcCsttt|jS)N)iterrangelenr )rrrrrAszSequentialSampler.__iter__cCs t|jS)N)rr )rrrr__len__DszSequentialSampler.__len__) rrrrr r rrintrrrrrrr6s rc@sfeZdZUdZeedeeee ddddZ e e ddd Z e e dd d Ze dd d ZdS) RandomSamplera5Samples elements randomly. If without replacement, then sample from a shuffled dataset. If with replacement, then user can specify :attr:`num_samples` to draw. Args: data_source (Dataset): dataset to sample from replacement (bool): samples are drawn on-demand with replacement if ``True``, default=``False`` num_samples (int): number of samples to draw, default=`len(dataset)`. This argument is supposed to be specified only when `replacement` is ``True``. generator (Generator): Generator used in sampling. FN)r replacement num_samplesrcCsx||_||_||_||_t|jts4tdj|j|jdk rL| rLtdt|j t  sd|j dkrttdj|j dS)Nz=replacement should be a boolean value, but got replacement={}zfWith replacement=False, num_samples should not be specified, since a random permute will be performed.rzFnum_samples should be a positive integer value, but got num_samples={}) r r _num_samples generator isinstancebool TypeErrorformat ValueErrorr!r)rr r r!r#rrrrVs  zRandomSampler.__init__)rcCs|jdkrt|jS|jS)N)r"rr )rrrrr!is  zRandomSampler.num_samplesccst|j}|jdkrDttjftjdjj}tj }|j |n|j}|j rx4t |j dD]"}tj|dtj|djEdHq`Wtj||j dftj|djEdHntj||djEdHdS)N)dtype )highsizer)r#)r#)r*)rr r#rtorchemptyZint64Zrandom_item GeneratorZ manual_seedr rr!randinttolistrandperm)rnseedr#_rrrrps   "(zRandomSampler.__iter__cCs|jS)N)r!)rrrrrszRandomSampler.__len__)FNN)rrrrr r r%r rrrpropertyr!rrrrrrrrHs rc@sPeZdZUdZeed eeddddZeedddZ edd d Z dS) SubsetRandomSamplerzSamples elements randomly from a given list of indices, without replacement. Args: indices (sequence): a sequence of indices generator (Generator): Generator used in sampling. N)indicesrcCs||_||_dS)N)r9r#)rr9r#rrrrszSubsetRandomSampler.__init__)rccs0x*tjt|j|jdD]}|j|VqWdS)N)r#)r-r3rr9r#)rirrrrszSubsetRandomSampler.__iter__cCs t|jS)N)rr9)rrrrrszSubsetRandomSampler.__len__)N) rrrrrrr9rrrrrrrrr8s r8c@sXeZdZUdZeee d e e eeddddZ e eddd Zedd d ZdS) WeightedRandomSampleraSamples elements from ``[0,..,len(weights)-1]`` with given probabilities (weights). Args: weights (sequence) : a sequence of weights, not necessary summing up to one num_samples (int): number of samples to draw replacement (bool): if ``True``, samples are drawn with replacement. If not, they are drawn without replacement, which means that when a sample index is drawn for a row, it cannot be drawn again for that row. generator (Generator): Generator used in sampling. Example: >>> list(WeightedRandomSampler([0.1, 0.9, 0.4, 0.7, 3.0, 0.6], 5, replacement=True)) [4, 4, 1, 4, 5] >>> list(WeightedRandomSampler([0.9, 0.4, 0.05, 0.2, 0.3, 0.1], 5, replacement=False)) [0, 1, 4, 3, 2] TN)weightsr!r rcCslt|t st|ts|dkr,tdj|t|tsDtdj|tj|tjd|_||_ ||_ ||_ dS)NrzFnum_samples should be a positive integer value, but got num_samples={}z=replacement should be a boolean value, but got replacement={})r)) r$rr%r(r'r-Z as_tensordoubler<r!r r#)rr<r!r r#rrrrs zWeightedRandomSampler.__init__)rccs0tj|j|j|j|jd}t|jEdHdS)N)r#)r-Z multinomialr<r!r r#rr2)rZ rand_tensorrrrrszWeightedRandomSampler.__iter__cCs|jS)N)r!)rrrrrszWeightedRandomSampler.__len__)TN)rrrrrr<rr!r%r rfloatrrrrrrrrr;s  r;c@sLeZdZdZeeeeddddZee edddZ edd d Z dS) BatchSampleraiWraps another sampler to yield a mini-batch of indices. Args: sampler (Sampler or Iterable): Base sampler. Can be any iterable object batch_size (int): Size of mini-batch. drop_last (bool): If ``True``, the sampler will drop the last batch if its size would be less than ``batch_size`` Example: >>> list(BatchSampler(SequentialSampler(range(10)), batch_size=3, drop_last=False)) [[0, 1, 2], [3, 4, 5], [6, 7, 8], [9]] >>> list(BatchSampler(SequentialSampler(range(10)), batch_size=3, drop_last=True)) [[0, 1, 2], [3, 4, 5], [6, 7, 8]] N)sampler batch_size drop_lastrcCsZt|t st|ts|dkr,tdj|t|tsDtdj|||_||_||_dS)NrzDbatch_size should be a positive integer value, but got batch_size={}z9drop_last should be a boolean value, but got drop_last={})r$rr%r(r'r@rArB)rr@rArBrrrrs zBatchSampler.__init__)rccsTg}x0|jD]&}|j|t||jkr |Vg}q Wt|dkrP|j rP|VdS)Nr)r@appendrrArB)rbatchidxrrrrs  zBatchSampler.__iter__cCs4|jrt|j|jSt|j|jd|jSdS)N)rBrr@rA)rrrrrszBatchSampler.__len__) rrrrr rr%rrrrrrrrrr?s r?)r-rtypingrrrrrrr r r rrrr8r;r?rrrrs $ .<+