+
    NV-jn&  ã                   óÄ   € ^ RI t ^ RIHtHt ^ RIHt ^ RIHtHtH	t	H
t
 ^ RIHt ^ RIHt R tR tR tR	 tR
 R ltRR R lltRR R lltRR R llt ! R R]4      tR# )é    N)ÚpartialÚreduce)Úproduct)ÚCallableÚLiteralÚTupleÚUnion)ÚModulec                 ó¼  € \        W,          4      pV'       dD   \        P                  ! V\        P                  R 7      V ^,
          V^,
          ,          ,          pMb^V,          pV^,
          V,          V ,
          ^,           ^,          p\        P                  ! V\        P                  R 7      V,          V,
          p^.V,          p	RW“&   VP	                  V	4      # )©Údtypeéÿÿÿÿ)ÚintÚmxÚarangeÚfloat32Úreshape)
ÚNÚscaleÚalign_cornersÚdimÚndimsÚMÚindicesÚstepÚstartÚshapes
   &&&&&     Úg/Volumes/fast/ai/experiments/ui-tars-smoke/.venv/lib/python3.14/site-packages/mlx/nn/layers/upsample.pyÚ_scaled_indicesr      sš   € ÜˆE�I‹€AßÜ—)’)˜A¤R§Z¡ZÔ0°Q¸µU¸qÀ1½uÕ4EÕF‰à�5�yˆØ�a•%˜4• !Õ# aÕ'¨1Õ,ˆÜ—)’)˜A¤R§Z¡ZÔ0°4Õ7¸%Õ?ˆàˆC�%�K€EØ€E�Jà�?‰?˜5Ó!Ð!ó    c                 ón  € \        W,          4      p\        P                  ! V\        P                  R 7      pW@8”  d/   VR,           W,          ,          R,
          pVP	                  4       pMWPV,          ,          p^.V,          pRWb&   VP                  \        P                  4      P                  V4      # )r   g      à?r   )r   r   r   r   ÚroundÚastypeÚuint32r   )r   r   r   r   r   r   r   s   &&&&   r   Ú_nearest_indicesr%      s‚   € ÜˆE�I‹€AÜ�iŠi˜¤§¡Ô,€GØ„uØ˜S•= Q¥UÕ+¨cÕ1ˆØ—-‘-“/‰à �UÕ#ˆØˆC�%�K€EØ€E�JØ�>‰>œ"Ÿ)™)Ó$×,Ñ,¨UÓ3Ð3r    c                 ó„  € \        WW#V4      p\        P                  ! V^ V ^,
          R7      p\        P                  ! V4      p\        P                  ! V4      pWV,
          p\        P
                  ! VR4      pVP                  \        P                  4      ^V,
          3VP                  \        P                  4      V33# )r   ©Úa_minÚa_maxr   )r   r   ÚclipÚfloorÚceilÚexpand_dimsr#   r$   )	r   r   r   r   r   r   Ú	indices_lÚ	indices_rÚweights	   &&&&&    r   Ú_linear_indicesr1   (   s˜   € Ü˜a¨¸EÓB€GÜ�gŠg�g Q¨a°!­eÔ4€GÜ—’˜Ó!€IÜ—’˜Ó €IØÕ €FÜ�^Š^˜F BÓ'€Fð 
×	Ñ	œ"Ÿ)™)Ó	$ a¨&¥jÐ1Ø	×	Ñ	œ"Ÿ)™)Ó	$ fÐ-ðð r    c                 ót  € \        WW#V4      p\        P                  ! V4      p\        P                  ! V^,           4      pV^,
          pV^,           p	\        \        P                  RR7      R 4       p
V
! WV^R7      R,          pV
! WW^R7      R,          pV
! WX^R7      R,          pV
! WY^R7      R,          p\        P
                  ! V^ V ^,
          R7      p\        P
                  ! V^ V ^,
          R7      p\        P
                  ! V^ V ^,
          R7      p\        P
                  ! V	^ V ^,
          R7      p	VP                  \        P                  4      V3VP                  \        P                  4      V3VP                  \        P                  4      V3V	P                  \        P                  4      V33# )é   T)Ú	shapelessc                 ó  € Rp\         P                  ! W,
          4      pV^8X  d6   VR,           V,          VR,           ,
          V,          V,          ^,           pV# V^,
          V,          ^,           V,          ^,
          V,          pV# )g      è?g       @g      @g      è¿)r   Úabs)ÚindÚgridÚdistÚaÚxr0   s   &&&   r   Ú_get_weightÚ#_cubic_indices.<locals>._get_weight=   ss   € ð ˆÜ�FŠF�3•:ÓˆØ�1Œ9Ø˜3•w !•m q¨3¥wÕ/°1Õ4°qÕ8¸1Õ<ˆFð ˆð ˜A� •{ Q•¨!Õ+¨aÕ/°1Õ4ˆFØˆr    )r9   r'   ).N)r   r   r+   r   Úcompiler*   r#   r$   )r   r   r   r   r   r   Ú
indices_l1Ú
indices_r1Ú
indices_l2Ú
indices_r2r<   Ú	weight_l1Ú	weight_r1Ú	weight_l2Ú	weight_r2s   &&&&&          r   Ú_cubic_indicesrG   6   sg  € Ü˜a¨¸EÓB€GÜ—’˜'Ó"€JÜ—’˜' A�+Ó&€JØ˜a•€JØ˜a•€JäŒR�Z‰Z 4Ô(ñ	ó )ð	ñ ˜G°aÔ8¸ÕC€IÙ˜G°aÔ8¸ÕC€IÙ˜G°aÔ8¸ÕC€IÙ˜G°aÔ8¸ÕC€Iô —’˜¨1°A¸µEÔ:€JÜ—’˜¨1°A¸µEÔ:€JÜ—’˜¨1°A¸µEÔ:€JÜ—’˜¨1°A¸µEÔ:€Jð 
×	Ñ	œ2Ÿ9™9Ó	% yÐ1Ø	×	Ñ	œ2Ÿ9™9Ó	% yÐ1Ø	×	Ñ	œ2Ÿ9™9Ó	% yÐ1Ø	×	Ñ	œ2Ÿ9™9Ó	% yÐ1ð	ð r    c                óD   € V ^8„  d   QhR\         P                  R\        /# )é   r;   Úscale_factor)r   Úarrayr   )Úformats   "r   Ú__annotate__rM   \   s   € ÷ ñ œŸ™ð ´ñ r    c           	      ó|  € V P                   ^,
          pV\        V4      8w  d   \        R4      h\        \	        \
        V4      4      V8X  Ed   \        V P                  4      p\        V4       F#  pVP                  ^^V,          ,           ^4       K%  	  V P                  V4      p \        V4       F%  p\        W,          4      V^^V,          ,           &   K'  	  \        P                  ! W4      p \        V4       FC  pW4^,           ;;,          W4^,           ,          ,          uu&   VP                  V^,           4       KE  	  V P                  V4      p V # V P                  EvrVp\        R4      .p\        \!        Wa4      4       F#  w  p	w  r«VP#                  \%        W«W’4      4       K%  	  \        V4      pW,          # )rI   ú7A scale needs to be provided for each spatial dimensionN)ÚndimÚlenÚ
ValueErrorÚtupleÚmapr   Úlistr   ÚrangeÚinsertr   r   Úbroadcast_toÚpopÚsliceÚ	enumerateÚzipÚappendr%   )r;   rJ   Údimsr   ÚdÚBr   ÚCr   ÚiÚnÚss   &&          r   Úupsample_nearestre   \   sT  € Ø�6‰6�A�:€DØŒs�<Ó Ô ÜÐRÓSÐSô ŒS”�lÓ#Ó$¨Õ4Ü�Q—W‘W“ˆÜ�t–ˆAØ�L‰L˜˜Q �U� AÖ&ñ à�I‰I�eÓˆÜ�t–ˆAÜ" <¥?Ó3ˆE�!�a˜!•e•)Óñ ä�OŠO˜AÓ%ˆÜ�t–ˆAØ�a•%�L˜E a¥%�LÕ(‹LØ�I‰I�a˜!•eÖñ ð �I‰I�eÓˆØˆð —7‘7‰ˆˆqÜ˜“;�-ˆÜ"¤3 qÓ#7Ö8‰IˆA‰v�Ø�N‰NÔ+¨A°!Ó:Ö;ñ 9ä˜“.ˆà�zÐr    c                ó\   € V ^8„  d   QhR\         P                  R\        R\        R\        /# )rI   r;   rJ   Ú
indices_fnr   )r   rK   r   r   Úbool)rL   s   "r   rM   rM   z   s0   € ÷ <ñ <Ü	‡x�xð<Ü$ð<Ü2:ð<ÜKOñ<r    c           
      ó  € V P                   ^,
          pV\        V4      8w  d   \        R4      hV P                  EvrVp. p\	        \        Wa4      4       F!  w  p	w  r«VP                  V! W«W9V4      4       K#  	  . p. p\        V!   Fa  p\        V!  w  ppVP                  V \        R4      3V,           ,          4       VP                  \        \        P                  V4      4       Kc  	  \        R \        WÜ4       4       4      # )rI   rO   Nc              3   ó6   "  € T F  w  rW,          x € K  	  R # 5i)N© )Ú.0ÚwiÚxis   &  r   Ú	<genexpr>Ú_interpolate.<locals>.<genexpr>‘   s   é € Ð;Ñ%:™6˜2ˆr�wŠwÓ%:ùs   ‚)rP   rQ   rR   r   r[   r\   r]   r   rZ   r   ÚoperatorÚmulÚsum)r;   rJ   rg   r   r^   r`   r   ra   r   rb   rc   rd   ÚsamplesÚweightsÚ
idx_weightÚidxr0   s   &&&&             r   Ú_interpolaterx   z   sá   € ð �6‰6�A�:€DØŒs�<Ó Ô ÜÐRÓSÐSà�w‰w�H€Aˆ1ð €GÜœs 1Ó3Ö4‰	ˆ‰6ˆAØ�‰‘z !¨¸$Ó?Ö@ñ 5ð €GØ€GÜ˜wÔ'ˆ
Ü˜:Ñ&‰ˆˆVØ�‰�qœ% ›+˜¨#Õ-Õ.Ô/Ø�‰”vœhŸl™l¨FÓ3Ö4ñ (ô Ñ;¤S¨Ô%:Ó;Ó;Ð;r    c                óP   € V ^8„  d   QhR\         P                  R\        R\        /# ©rI   r;   rJ   r   ©r   rK   r   rh   )rL   s   "r   rM   rM   ”   s%   € ÷ ñ ”r—x‘xð ¬uð ÄTñ r    c                 ó(   € \        V V\        VR 7      # ©)r;   rJ   rg   r   )rx   r1   ©r;   rJ   r   s   &&&r   Úupsample_linearr   ”   s   € ÜØ
Ø!Ü"Ø#ô	ð r    c                óP   € V ^8„  d   QhR\         P                  R\        R\        /# rz   r{   )rL   s   "r   rM   rM   �   s%   € ÷ ñ ”b—h‘hð ¬eð ÄDñ r    c                 ó(   € \        V V\        VR 7      # r}   )rx   rG   r~   s   &&&r   Úupsample_cubicr‚   �   s   € ÜØ
Ø!Ü!Ø#ô	ð r    c                   ój   a a€ ] tR t^¦t oRtR	V3R lV 3R llltV3R lR ltV3R lR ltRtVt	V ;t
# )
ÚUpsampleaÈ	  Upsample the input signal spatially.

The spatial dimensions are by convention dimensions ``1`` to ``x.ndim -
2``. The first is the batch dimension and the last is the feature
dimension.

For example, an audio signal would be 3D with 1 spatial dimension, an image
4D with 2 and so on and so forth.

There are three upsampling algorithms implemented nearest neighbor upsampling,
linear interpolation, and cubic interpolation. All can be applied to any number
of spatial dimensions. The linear interpolation will be bilinear, trilinear etc
when applied to more than one spatial dimension. And cubic interpolation will be
bicubic when there are 2 spatial dimensions.

.. note::
   When using one of the linear or cubic interpolation modes the ``align_corners``
   argument changes how the corners are treated in the input image. If
   ``align_corners=True`` then the top and left edge of the input and
   output will be matching as will the bottom right edge.

Parameters:
    scale_factor (float or tuple): The multiplier for the spatial size.
        If a ``float`` is provided, it is the multiplier for all spatial dimensions.
        Otherwise, the number of scale factors provided must match the
        number of spatial dimensions.
    mode (str, optional): The upsampling algorithm, either ``"nearest"``,
        ``"linear"`` or ``"cubic"``. Default: ``"nearest"``.
    align_corners (bool, optional): Changes the way the corners are treated
        during ``"linear"`` and ``"cubic"`` upsampling.  See the note above and the
        examples below for more details.  Default: ``False``.

Examples:
    >>> import mlx.core as mx
    >>> import mlx.nn as nn
    >>> x = mx.arange(1, 5).reshape((1, 2, 2, 1))
    >>> x
    array([[[[1],
             [2]],
            [[3],
             [4]]]], dtype=int32)
    >>> n = nn.Upsample(scale_factor=2, mode='nearest')
    >>> n(x).squeeze()
    array([[1, 1, 2, 2],
           [1, 1, 2, 2],
           [3, 3, 4, 4],
           [3, 3, 4, 4]], dtype=int32)
    >>> b = nn.Upsample(scale_factor=2, mode='linear')
    >>> b(x).squeeze()
    array([[1, 1.25, 1.75, 2],
           [1.5, 1.75, 2.25, 2.5],
           [2.5, 2.75, 3.25, 3.5],
           [3, 3.25, 3.75, 4]], dtype=float32)
    >>> b = nn.Upsample(scale_factor=2, mode='linear', align_corners=True)
    >>> b(x).squeeze()
    array([[1, 1.33333, 1.66667, 2],
           [1.66667, 2, 2.33333, 2.66667],
           [2.33333, 2.66667, 3, 3.33333],
           [3, 3.33333, 3.66667, 4]], dtype=float32)
c                óP   <€ V ^8„  d   QhRS[ S[S[3,          RS[R,          RS[/# )rI   rJ   Úmoder   ©ÚnearestÚlinearÚcubic)r	   Úfloatr   r   rh   )rL   Ú__classdict__s   "€r   rM   ÚUpsample.__annotate__ä   s8   ø€ ÷ +ñ +á™E¡5˜LÕ)ð+ñ Ð2Õ3ð+ñ ñ	+r    c                óü   <€ \         SV `  4        VR9  d   \        RV 24      h\        V\        \
        34      '       d    \        \        \        V4      4      V n        M\        V4      V n        W n	        W0n
        R# )rˆ   z1[Upsample] Got unsupported upsampling algorithm: Nr‡   )ÚsuperÚ__init__rR   Ú
isinstancerU   rS   rT   r‹   rJ   r†   r   )ÚselfrJ   r†   r   Ú	__class__s   &&&&€r   r�   ÚUpsample.__init__ä   sk   ø€ ô 	‰ÑÔØÐ5Ô5ÜÐPÐQUÐPVÐWÓXÐXÜ�l¤T¬5 M×2Ò2Ü %¤c¬%°Ó&>Ó ?ˆDÕä % lÓ 3ˆDÔØŒ	Ø*Ör    c                ó    <€ V ^8„  d   QhRS[ /# )rI   Úreturn)Ústr)rL   rŒ   s   "€r   rM   r�   ô   s   ø€ ÷ 
ñ 
™Sñ 
r    c                óV   € R V P                    RV P                  : RV P                   2# )zscale_factor=z, mode=z, align_corners=)rJ   r†   r   )r’   s   &r   Ú_extra_reprÚUpsample._extra_reprô   s6   € à˜D×-Ñ-Ð.¨g°d·i±i±]ð CØ!×/Ñ/Ð0ð2ð	
r    c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# )rI   r;   r–   )r   rK   )rL   rŒ   s   "€r   rM   r�   ú   s'   ø€ ÷ Hñ H™"Ÿ(™(ð H¡r§x¡xñ Hr    c                ó  € VP                   ^,
          pV^ 8:  d   \        RVP                    R24      hV P                  p\        V\        4      '       d#   \        V4      V8w  d   \        RV RV 24      hM
V3V,          pV P                  R8X  d   \        W4      # V P                  R8X  d   \        WV P                  4      # V P                  R8X  d   \        WV P                  4      # \        RV P                   24      h)	rI   zg[Upsample] The input should have at least 1 spatial dimension which means it should be at least 3D but zD was providedzH[Upsample] One scale per spatial dimension is required but scale_factor=z+ and the number of spatial dimensions were rˆ   r‰   rŠ   zUnknown interpolation mode: )rP   rR   rJ   r‘   rS   rQ   r†   re   r   r   r‚   Ú	Exception)r’   r;   r^   rJ   s   &&  r   Ú__call__ÚUpsample.__call__ú   s  € Ø�v‰v˜�zˆØ�1Œ9ÜðFà—6‘6�(˜.ð*óð ð ×(Ñ(ˆÜ�l¤E×*Ò*Ü�<Ó  DÔ(Ü ð$Ø$0 >ð 2'Ø'+ fð.óð ð )ð )˜?¨TÕ1ˆLà�9‰9˜	Ô!Ü# AÓ4Ð4Ø�Y‰Y˜(Ô"Ü" 1°D×4FÑ4FÓGÐGØ�Y‰Y˜'Ô!Ü! !°4×3EÑ3EÓFÐFäÐ:¸4¿9¹9¸+ÐFÓGÐGr    )r   r†   rJ   )rˆ   F)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r�   r™   rž   Ú__static_attributes__Ú__classdictcell__Ú__classcell__)r“   rŒ   s   @@r   r„   r„   ¦   s1   ù‡ € ñ;÷z+õ +÷ 
ð 
÷H÷ Hð Hr    r„   )F)rq   Ú	functoolsr   r   Ú	itertoolsr   Útypingr   r   r   r	   Úmlx.coreÚcorer   Úmlx.nn.layers.baser
   r   r%   r1   rG   re   rx   r   r‚   r„   rk   r    r   Ú<module>r®      sU   ðó ß %Ý ß 2Ó 2å Ý %ò"ò
4òò#õL÷<<÷4÷ôoHˆvö oHr    