
    ^jB              	           d dl mZmZ d dlmZ  ed      Zdee   dedeee   ddf   fdZdee   d	ed
edee   fdZ	dee   dee   fdZ
y)    )	GeneratorIterable)TypeVarVsequence
batch_sizereturnNc              #      K   t        |d      }g }| D ]'  }t        |      |k(  r| g }|j                  |       ) |r| yyw)a  
    Provides a generator that yields chunks of the input sequence
    of the size specified by the `batch_size` parameter. The last
    chunk may be a smaller batch.

    Args:
        sequence: The sequence to be split into batches.
        batch_size: The expected size of a batch.

    Returns:
        A generator that yields chunks
            of `sequence` of size `batch_size`, up to the length of
            the input `sequence`.

    Examples:
        ```pycon
        >>> from supervision.utils.iterables import create_batches
        >>> list(create_batches([1, 2, 3, 4, 5], 2))
        [[1, 2], [3, 4], [5]]
        >>> list(create_batches("abcde", 3))
        [['a', 'b', 'c'], ['d', 'e']]

        ```
       N)maxlenappend)r   r   current_batchelements       f/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/supervision/utils/iterables.pycreate_batchesr      s^     6 Z#JM &}+MW%	&
  s   AAdesired_sizecontentc                 `    t        d|t        |       z
        }| j                  |g|z         | S )a  
    Fill the sequence with padding elements until the sequence reaches
    the desired size.

    Args:
        sequence: The input sequence.
        desired_size: The expected size of the output list. The
            difference between this value and the actual length of `sequence`
            (if positive) dictates how many elements will be added as padding.
        content: The element to be placed at the end of the input
            `sequence` as padding.

    Returns:
        A padded version of the input `sequence` (if needed).

    Examples:
        ```pycon
        >>> from supervision.utils.iterables import fill
        >>> fill([1, 2], 4, 0)
        [1, 2, 0, 0]
        >>> fill(['a', 'b'], 3, 'c')
        ['a', 'b', 'c']

        ```
    r   )r   r   extend)r   r   r   missing_sizes       r   fillr   -   s1    4 q,X67LOOWI,-O    c                     t               }t               }| D ])  }||v r|j                  |       |j                  |       + t        |      S )a  
    Find all duplicate elements in the input sequence.

    Args:
        sequence: The input sequence.

    Returns:
        A list of duplicate elements found in the sequence.

    Examples:
        ```pycon
        >>> from supervision.utils.iterables import find_duplicates
        >>> sorted(find_duplicates([1, 2, 3, 2, 4, 5, 1]))
        [1, 2]
        >>> find_duplicates(['a', 'b', 'c'])
        []

        ```
    )setaddlist)r   seen
duplicatesr   s       r   find_duplicatesr    L   sM    ( 5DJ d?NN7#HHW	
 
r   )collections.abcr   r   typingr   r   intr   r   r   r     r   r   <module>r%      s    / CL#qk#'*#tAwd"##L47 #  d1g >d1g $q' r   