§
    ·¯¸j=
  ã                   ó–   — d Z ddlmZ ddlZd„ Z ed¦  «        Z ed¦  «        Z ed¦  «        Z ed¦  «        Z	eZ
dd	„Zdd„Zd„ ZdS )zI Layer/Module Helpers

Hacked together by / Copyright 2020 Ross Wightman
é    )ÚrepeatNc                 ó   ‡ — ˆ fd„}|S )a<  Return a function that converts input to an n-tuple.

    Scalar values are repeated n times, while iterables are converted to tuples.
    Strings are treated as scalars to avoid character-level splitting.

    Args:
        n: Target tuple length.

    Returns:
        Function that converts input to n-tuple.
    c                 óÄ   •— t          | t          j        j        ¦  «        r$t          | t          ¦  «        st          | ¦  «        S t          t          | ‰¦  «        ¦  «        S )N)Ú
isinstanceÚcollectionsÚabcÚIterableÚstrÚtupler   )ÚxÚns    €úc/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/timm/layers/helpers.pyÚparsez_ntuple.<locals>.parse   sL   ø€ Ý�a�œÔ1Ñ2Ô2ð 	½:ÀaÍÑ;MÔ;Mð 	Ý˜‘8”8ˆOÝ•V˜A˜q‘\”\Ñ"Ô"Ð"ó    © )r   r   s   ` r   Ú_ntupler   
   s#   ø€ ð#ð #ð #ð #ð #ð €Lr   é   é   é   é   c                 óx   — t          |                      ¦   «         d¦  «        }|�|€|j        }|€|j        }||dœS )zºResolve factory device and dtype kwargs from a parent module.

    Explicit values take precedence. Missing values are inferred from the
    module's first parameter, if it has one.
    N)ÚdeviceÚdtype)ÚnextÚ
parametersr   r   )Úmoduler   r   Ú	parameters       r   Úget_device_dtyper   $   sL   € õ �V×&Ò&Ñ(Ô(¨$Ñ/Ô/€IØÐØˆ>ØÔ%ˆFØˆ=Ø”OˆEØ uÐ-Ð-Ð-r   é   çÍÌÌÌÌÌì?c                 ó|   — |p|}t          |t          | |dz  z   ¦  «        |z  |z  ¦  «        }||| z  k     r||z  }|S )aá  Adjust value to be divisible by a divisor, typically for channel counts.

    Rounds to the nearest multiple of divisor while ensuring the result doesn't
    fall below min_value or decrease by more than (1 - round_limit).

    Args:
        v: Value to adjust.
        divisor: Target divisor.
        min_value: Minimum acceptable value.
        round_limit: Prevent decrease beyond this fraction of original value.

    Returns:
        Adjusted value divisible by divisor.
    r   )ÚmaxÚint)ÚvÚdivisorÚ	min_valueÚround_limitÚnew_vs        r   Úmake_divisibler)   3   sU   € ð Ð$˜W€IÝ�	�3˜q 7¨Q¡;™Ñ/Ô/°7Ñ:¸WÑDÑEÔE€Eàˆ{˜Q‰ÒÐØ�ÑˆØ€Lr   c                 óÂ   — t          | t          t          f¦  «        s| f} nt          | ¦  «        } |t          | ¦  «        z
  }|dk    r
| d|…         S | | d         f|z  z   S )a&  Pad a tuple to length n by repeating the last value.

    If input is shorter than n, extends by repeating the last element.
    If input is longer than n, truncates to n.

    Args:
        x: Input value, tuple, or list.
        n: Target length.

    Returns:
        Tuple of length n.
    r   Néÿÿÿÿ)r   r   ÚlistÚlen)r   r   Úpad_ns      r   Úextend_tupler/   J   si   € õ �a�%¥˜Ñ'Ô'ð ØˆDˆˆå�!‰HŒHˆØ•�A‘”‰J€EØ�‚z€zØ��!�ŒuˆØ��"”ˆx˜%ÑÑÐr   )NN)r   Nr    )Ú__doc__Ú	itertoolsr   Úcollections.abcr   r   Ú	to_1tupleÚ	to_2tupleÚ	to_3tupleÚ	to_4tupleÚ	to_ntupler   r)   r/   r   r   r   ú<module>r8      sº   ððð ð Ð Ð Ð Ð Ð Ø Ð Ð Ð ðð ð ð& ˆG�A‰JŒJ€	ØˆG�A‰JŒJ€	ØˆG�A‰JŒJ€	ØˆG�A‰JŒJ€	Ø€	ð.ð .ð .ð .ðð ð ð ð. ð  ð  ð  ð  r   