
    ^jD                     t    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
 Zy)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    ^/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/timm/layers/helpers.pyparsez_ntuple.<locals>.parse   s:    a112:a;M8OVAq\""     )r   r   s   ` r   _ntupler   
   s    # Lr               c                 n    |xs |}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   $   sL     $WI	3q7Q;/7:WDEE{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%   ;   sW     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>r/      sL     & AJ	AJ	AJ	AJ		. r   