/usr/local/lib64/python3.6/site-packages/torch/utils/data/__pycache__
Edit: /usr/local/lib64/python3.6/site-packages/torch/utils/data/__pycache__/sampler.cpython-36.pyc (9012B)
3
Eg' @ s d dl Z d dl mZ d dlmZmZmZmZmZmZm Z edddZ
G dd dee
ZG d d
d
ee Z
G dd dee ZG d
d dee ZG dd dee ZG dd deee ZdS ) N)Tensor)IteratorOptionalSequenceListTypeVarGenericSizedT_coT) covariantc @ s6 e Zd ZdZee ddddZee dddZ dS ) Samplera Base 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_sourcereturnc C s d S )N )selfr
r r D/usr/local/lib64/python3.6/site-packages/torch/utils/data/sampler.py__init__ s zSampler.__init__)r c C s t d S )N)NotImplementedError)r r r r __iter__ s zSampler.__iter__)
__name__
__module____qualname____doc__r r r r r
r r r r r r s
r c @ sF e Zd ZU dZeeddddZee dddZ edd d
Z
dS )SequentialSamplerz~Samples elements sequentially, always in the same order.
Args:
data_source (Dataset): dataset to sample from
N)r
r c C s
|| _ d S )N)r
)r r
r r r r > s zSequentialSampler.__init__)r c C s t tt| jS )N)iterrangelenr
)r r r r r A s zSequentialSampler.__iter__c C s
t | jS )N)r r
)r r r r __len__D s zSequentialSampler.__len__)r r r r r r
r r intr r r r r r r 6 s
r c @ sf e Zd ZU dZeedeeee ddddZ
ee ddd Ze
e dd
dZe ddd
ZdS )
RandomSamplera5 Samples 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
replacementnum_samplesr c C sx || _ || _|| _|| _t| jts4tdj| j| jd k rL| rLtdt| j t
sd| j dkrttdj| j d S )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.r zFnum_samples should be a positive integer value, but got num_samples={})r
r _num_samples generator
isinstancebool TypeErrorformat
ValueErrorr! r )r r
r r! r# r r r r V s
zRandomSampler.__init__)r c C s | j d krt| jS | j S )N)r" r r
)r r r r r! i s
zRandomSampler.num_samplesc c s t | j}| jd krDttjf tjdj j }tj }|j
| n| j}| jrx4t| j
d D ]"}tj|dtj|dj E d H q`W tj|| j
d ftj|dj E d H ntj||dj E d H d S )N)dtype )highsizer) r# )r# )r* )r r
r# r torchemptyZint64Zrandom_item GeneratorZmanual_seedr r r! randinttolistrandperm)r nseedr# _r r r r p s
"(zRandomSampler.__iter__c C s | j S )N)r! )r r r r r s zRandomSampler.__len__)FNN)r r r r r r
r% r r r r propertyr! r r r r r r r r H s
r c @ sP e Zd ZU dZee dee ddddZee dddZ 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)indicesr c C s || _ || _d S )N)r9 r# )r r9 r# r r r r s zSubsetRandomSampler.__init__)r c c s0 x*t jt| j| jdD ]}| j| V qW d S )N)r# )r- r3 r r9 r# )r ir r r r s zSubsetRandomSampler.__iter__c C s
t | jS )N)r r9 )r r r r r s zSubsetRandomSampler.__len__)N)r r r r r r r9 r r r r r r r r r8 s
r8 c @ sX e Zd ZU dZeee de
e eeddddZe
e ddd Zedd
dZdS )
WeightedRandomSamplera Samples 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 r c C sl t |t st |ts|dkr,tdj|t |tsDtdj|tj|tjd| _|| _ || _
|| _d S )Nr zFnum_samples should be a positive integer value, but got num_samples={}z=replacement should be a boolean value, but got replacement={})r) )r$ r r% r( r' r- Z as_tensordoubler<