
    <Цi/2                        S SK r S SKJrJrJrJrJrJrJrJ	r	J
r
  S SKr/ SQr\	" SSS9r " S S\\   5      r " S	 S
\\   5      r " S S\\   5      r " S S\\   5      r " S S\\   5      r " S S\\\      5      rg)    N)	GenericIterableIteratorListOptionalSequenceSizedTypeVarUnion)BatchSamplerRandomSamplerSamplerSequentialSamplerSubsetRandomSamplerWeightedRandomSampler_T_coT)	covariantc                   H    \ rS rSrSrS	S\\   SS4S jjrS\\	   4S jr
Srg)
r      a  Base class for all Samplers.

Every Sampler subclass has to provide an :meth:`__iter__` method, providing a
way to iterate over indices or lists of indices (batches) of dataset elements,
and may provide a :meth:`__len__` method that returns the length of the returned iterators.

Args:
    data_source (Dataset): This argument is not used and will be removed in 2.2.0.
        You may still have custom implementation that utilizes it.

Example:
    >>> # xdoctest: +SKIP
    >>> class AccedingSequenceLengthSampler(Sampler[int]):
    >>>     def __init__(self, data: List[str]) -> None:
    >>>         self.data = data
    >>>
    >>>     def __len__(self) -> int:
    >>>         return len(self.data)
    >>>
    >>>     def __iter__(self) -> Iterator[int]:
    >>>         sizes = torch.tensor([len(x) for x in self.data])
    >>>         yield from torch.argsort(sizes).tolist()
    >>>
    >>> class AccedingSequenceLengthBatchSampler(Sampler[List[int]]):
    >>>     def __init__(self, data: List[str], batch_size: int) -> None:
    >>>         self.data = data
    >>>         self.batch_size = batch_size
    >>>
    >>>     def __len__(self) -> int:
    >>>         return (len(self.data) + self.batch_size - 1) // self.batch_size
    >>>
    >>>     def __iter__(self) -> Iterator[List[int]]:
    >>>         sizes = torch.tensor([len(x) for x in self.data])
    >>>         for batch in torch.chunk(torch.argsort(sizes), len(self)):
    >>>             yield batch.tolist()

.. 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_sourcereturnc                 6    Ub  SS K nUR                  S5        g g )Nr   zz`data_source` argument is not used and will be removed in 2.2.0.You may still have custom implementation that utilizes it.)warningswarn)selfr   r   s      W/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/torch/utils/data/sampler.py__init__Sampler.__init__I   s"    "MMM #    c                     [         eN)NotImplementedErrorr   s    r   __iter__Sampler.__iter__R   s    !!r    r!   )__name__
__module____qualname____firstlineno____doc__r   r	   r   r   r   r$   __static_attributes__r&   r   r   r   r      s/    'RHUO t "(5/ "r   r   c                   X    \ rS rSr% Sr\\S'   S\SS4S jrS\\	   4S jr
S\	4S jrS	rg)
r   q   zrSamples elements sequentially, always in the same order.

Args:
    data_source (Dataset): dataset to sample from
r   r   Nc                     Xl         g r!   r   )r   r   s     r   r   SequentialSampler.__init__z   s    &r   c                 P    [        [        [        U R                  5      5      5      $ r!   )iterrangelenr   r#   s    r   r$   SequentialSampler.__iter__}   s    E#d../011r   c                 ,    [        U R                  5      $ r!   )r5   r   r#   s    r   __len__SequentialSampler.__len__   s    4##$$r   r0   )r'   r(   r)   r*   r+   r	   __annotations__r   r   intr$   r8   r,   r&   r   r   r   r   q   s>     'E 'd '2(3- 2% %r   r   c            	           \ rS rSr% Sr\\S'   \\S'      SS\S\S\\	   SS4S jjr
\S\	4S	 j5       rS\\	   4S
 jrS\	4S jrSrg)r      a  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)`.
    generator (Generator): Generator used in sampling.
r   replacementNnum_samplesr   c                 0   Xl         X l        X0l        X@l        [	        U R                  [
        5      (       d  [        SU R                   35      e[	        U R                  [        5      (       a  U R                  S::  a  [        SU R                   35      eg )N;replacement should be a boolean value, but got replacement=r   Dnum_samples should be a positive integer value, but got num_samples=)
r   r>   _num_samples	generator
isinstancebool	TypeErrorr?   r;   
ValueError)r   r   r>   r?   rD   s        r   r   RandomSampler.__init__   s     '&'"$**D11MdN^N^M_`  $**C00D4D4D4IVW[WgWgVhi  5Jr   c                 ^    U R                   c  [        U R                  5      $ U R                   $ r!   )rC   r5   r   r#   s    r   r?   RandomSampler.num_samples   s-     $t''((   r   c              #     #    [        U R                  5      nU R                  co  [        [        R
                  " S[        R                  S9R                  5       R                  5       5      n[        R                  " 5       nUR                  U5        OU R                  nU R                  (       a  [        U R                  S-  5       H>  n[        R                  " US[        R                  US9R                  5        S h  vN   M@     [        R                  " UU R                  S-  4[        R                  US9R                  5        S h  vN   g [        U R                  U-  5       H-  n[        R                   " XS9R                  5        S h  vN   M/     [        R                   " XS9R                  5       S U R                  U-    S h  vN   g  N N NG N7f)Nr&   dtype    )rO   )highsizerN   rD   rD   )r5   r   rD   r;   torchemptyint64random_item	Generatormanual_seedr>   r4   r?   randinttolistrandperm)r   nseedrD   _s        r   r$   RandomSampler.__iter__   sy      !>>!u{{2U[[9AACHHJKD)I!!$'I4++r12 ==ekkY&(  3 }}&&+-kk#	
 fh  4++q01 >>!AHHJJJ 2~~a=DDF&$""Q&   KsJ   D G!GAG!GAG!G=G!GG!G!G!G!c                     U R                   $ r!   r?   r#   s    r   r8   RandomSampler.__len__       r   )rC   r   rD   r>   )FNN)r'   r(   r)   r*   r+   r	   r:   rF   r   r;   r   propertyr?   r   r$   r8   r,   r&   r   r   r   r      s    	 
 "%)  c]	 
, !S ! !(3- 6   r   r   c                   h    \ rS rSr% Sr\\   \S'   S
S\\   SS4S jjrS\	\   4S jr
S\4S jrS	rg)r      zSamples elements randomly from a given list of indices, without replacement.

Args:
    indices (sequence): a sequence of indices
    generator (Generator): Generator used in sampling.
indicesNr   c                     Xl         X l        g r!   )rh   rD   )r   rh   rD   s      r   r   SubsetRandomSampler.__init__   s    "r   c              #      #    [         R                  " [        U R                  5      U R                  S9 H  nU R                  U   v   M     g 7fNrR   )rS   r\   r5   rh   rD   )r   is     r   r$   SubsetRandomSampler.__iter__   s6     DLL 1T^^LA,,q/! Ms   AAc                 ,    [        U R                  5      $ r!   )r5   rh   r#   s    r   r8   SubsetRandomSampler.__len__   s    4<<  r   )rD   rh   r!   )r'   r(   r)   r*   r+   r   r;   r:   r   r   r$   r8   r,   r&   r   r   r   r      sF     c]# #$ #"(3- "! !r   r   c            	           \ rS rSr% Sr\R                  \S'   \\S'   \	\S'     SS\
\   S\S\	SS4S jjrS\\   4S	 jrS\4S
 jrSrg)r      a  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:
    >>> # xdoctest: +IGNORE_WANT("non-deterministic")
    >>> 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]
weightsr?   r>   Nr   c                    [        U[        5      (       a  [        U[        5      (       d  US::  a  [        SU 35      e[        U[        5      (       d  [        SU 35      e[        R
                  " U[        R                  S9n[        UR                  5      S:w  a!  [        S[        UR                  5       35      eXPl
        X l        X0l        X@l        g )Nr   rB   rA   rM      z=weights should be a 1d sequence but given weights have shape )rE   r;   rF   rH   rS   	as_tensordoubler5   shapetuplers   r?   r>   rD   )r   rs   r?   r>   rD   weights_tensors         r   r   WeightedRandomSampler.__init__   s     ;,,+t,,aVWbVcd  +t,,Mk][  E~##$)&&+N,@,@&A%BD 
 &&&"r   c              #      #    [         R                  " U R                  U R                  U R                  U R
                  S9n[        UR                  5       5       S h  vN   g  N7frl   )rS   multinomialrs   r?   r>   rD   r3   r[   )r   rand_tensors     r   r$   WeightedRandomSampler.__iter__  sK     ''LL$**D,<,<
 **,---s   AA&A$A&c                     U R                   $ r!   rb   r#   s    r   r8   WeightedRandomSampler.__len__"  rd   r   )rD   r?   r>   rs   )TN)r'   r(   r)   r*   r+   rS   Tensorr:   r;   rF   r   floatr   r   r$   r8   r,   r&   r   r   r   r      ss    $ \\ !#%# # 	# 
#@.(3- .   r   r   c                   p    \ rS rSrSrS\\\   \\   4   S\S\	SS4S jr
S\\\      4S	 jrS\4S
 jrSrg)r   i&  a=  Wraps 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]]
sampler
batch_size	drop_lastr   Nc                     [        U[        5      (       a  [        U[        5      (       d  US::  a  [        SU 35      e[        U[        5      (       d  [        SU 35      eXl        X l        X0l        g )Nr   zBbatch_size should be a positive integer value, but got batch_size=z7drop_last should be a boolean value, but got drop_last=)rE   r;   rF   rH   r   r   r   )r   r   r   r   s       r   r   BatchSampler.__init__6  su     :s++*d++QTU_T`a  )T**I)U  $"r   c              #   V  #    [        U R                  5      nU R                  (       a&  U/U R                  -  n[	        U6  H	  n/ UQv   M     g / [
        R                  " XR                  5      QnU(       a0  Uv   / [
        R                  " XR                  5      QnU(       a  M/  g g 7fr!   )r3   r   r   r   zip	itertoolsislice)r   sampler_iterargsbatch_droplastbatchs        r   r$   BatchSampler.__iter__O  s     DLL)>> >DOO3D"%t*''' #- Gi&&|__EFEJ)**<IJ %s   B#B)'B)c                     U R                   (       a"  [        U R                  5      U R                  -  $ [        U R                  5      U R                  -   S-
  U R                  -  $ )Nru   )r   r5   r   r   r#   s    r   r8   BatchSampler.__len__]  sI    
 >>t||$77%7!;OOr   )r   r   r   )r'   r(   r)   r*   r+   r   r   r;   r   rF   r   r   r   r$   r8   r,   r&   r   r   r   r   &  si    #ws|Xc]23# # 	#
 
#2K(49- KP Pr   r   )r   typingr   r   r   r   r   r   r	   r
   r   rS   __all__r   r   r;   r   r   r   r   r   r&   r   r   <module>r      s    
 
 
  	4(4"gen 4"d% %&H GCL H V!'#, !,> GCL > B?P749% ?Pr   