
    RЦiD                     v    S r SSKJr  SSKrS r\" S5      r\" S5      r\" S5      r\" S5      r	\r
SS	 jrS
 rg)zHLayer/Module Helpers

Hacked together by / Copyright 2020 Ross Wightman
    )repeatNc                    ^  U 4S jnU$ )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                    > [        U [        R                  R                  5      (       a   [        U [        5      (       d  [        U 5      $ [        [        U T5      5      $ )N)
isinstancecollectionsabcIterablestrtupler   )xns    R/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/timm/layers/helpers.pyparse_ntuple.<locals>.parse   s@    a1122:a;M;M8OVAq\""     )r   r   s   ` r   _ntupler   
   s    # Lr               c                 t    U=(       d    Un[        U[        XS-  -   5      U-  U-  5      nXCU -  :  a  XA-  nU$ )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    $   sF     $WI	3qQ;/7:WDEEQLr   c                     [        U [        [        45      (       d  U 4n O[        U 5      n U[        U 5      -
  nUS::  a  U SU $ X S   4U-  -   $ )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&   ;   sX     a%''D!HAJEz!u"x%r   )   Ng?)__doc__	itertoolsr   collections.abcr   r   	to_1tuple	to_2tuple	to_3tuple	to_4tuple	to_ntupler    r&   r   r   r   <module>r0      sL     & AJ	AJ	AJ	AJ		. r   