Ë
    P/æjØ  ã                   ó@  — d dl mZ d dlmZ d dlZd dlZd dlZd dlZd dl	Z	d dl
mZ d dlmZ d„ Zde	j                   dej"                  e	j                   ef   fd	„Zd
ej(                  e   defd„Zddefd„Zddedefd„Zeddefd„«       Zddedefd„Z G d„ d«      Zy)é    )Údefaultdict)ÚcontextmanagerN)Ú
functional)ÚSubsetc                 ó0  — | j                   �^ }}t        j                  ||z  «      }|dz
  |z  |z   }t        j                  | d||z
  f«      } t        | j                  «       «      }|d   dk(  sJ d«       ‚|dd |dgz   }| j                  g |¢|‘|‘|«      S )zýGiven input of size [*OT, T], output Tensor of size [*OT, F, K]
    with K the kernel size, by extracting frames with the given stride.

    This will pad the input so that `F = ceil(T / K)`.

    see https://github.com/pytorch/pytorch/issues/60466
    é   r   éÿÿÿÿzdata should be contiguousN)ÚshapeÚmathÚceilÚFÚpadÚlistÚstrideÚ
as_strided)ÚaÚkernel_sizer   r
   ÚlengthÚn_framesÚ
tgt_lengthÚstridess           úO/root/repos/pocs/video-evals/.venv/lib/python3.12/site-packages/demucs/utils.pyÚunfoldr      s­   € ð —W‘W�N€UˆFÜ�y‰y˜ &™Ó)€HØ˜Q‘, &Ñ(¨;Ñ6€JÜ	�‰ˆa�!�Z &Ñ(Ð)Ó*€AÜ�1—8‘8“:Ó€GØ�2‰;˜!ÒÐ8Ð8Ó8ÐØ�c�rˆl˜f a˜[Ñ(€GØ�<‰<Ð7˜%Ð7 Ð7¨;Ð7¸ÓAÐAó    ÚtensorÚ	referencec                 óÜ   — t        |t        j                  «      r|j                  d«      }n|}| j                  d«      |z
  }|dk  rt	        d|› d�«      ‚|r| d|dz  ||dz  z
   …f   } | S )zõ
    Center trim `tensor` with respect to `reference`, along the last dimension.
    `reference` can also be a number, representing the length to trim to.
    If the size difference != 0 mod 2, the extra sample is removed on the right side.
    r	   r   z/tensor must be larger than reference. Delta is ú..é   )Ú
isinstanceÚtorchÚTensorÚsizeÚ
ValueError)r   r   Úref_sizeÚdeltas       r   Úcenter_trimr'   %   s€   € ô �)œUŸ\™\Ô*Ø—>‘> "Ó%‰àˆØ�K‰K˜‹O˜hÑ&€EØˆq‚yÜÐMÈeÈWÐTUÐVÓWÐWÙØ˜˜U a™Z¨%°%¸1±*Ñ*<Ð(=Ð=Ð=Ñ>ˆØ€Mr   ÚhistoryÚnamec                 ót   — g }| D ]0  }|}|j                  d«      D ]  }||   }Œ	 |j                  |«       Œ2 |S )Nr   )ÚsplitÚappend)r(   r)   ÚoutÚmetricsÚmetricÚparts         r   Úpull_metricr1   8   sN   € Ø
€CØò ˆØˆØ—J‘J˜s“Oò 	"ˆDØ˜D‘\‰Fð	"à�
‰
�6Õð	ð
 €Jr   Úbetac                 ó~   ‡ ‡‡— t        t        «      Št        t        «      Šddt        dt        dt        fˆ ˆˆfd„}|S )a  
    Exponential Moving Average callback.
    Returns a single function that can be called to repeatidly update the EMA
    with a dict of metrics. The callback will return
    the new averaged dict of metrics.

    Note that for `beta=1`, this is just plain averaging.
    r.   ÚweightÚreturnc                 óä   •— | j                  «       D ]-  \  }}‰|   ‰z  |t        |«      z  z   ‰|<   ‰|   ‰z  |z   ‰|<   Œ/ ‰j                  «       D ��ci c]  \  }}||‰|   z  “Œ c}}S c c}}w ©N)ÚitemsÚfloat)r.   r4   ÚkeyÚvalueÚtotr2   ÚfixÚtotals        €€€r   Ú_updatezEMA.<locals>._updateN   s   ø€ à!Ÿ-™-›/ò 	0‰JˆC�Ø˜s™ dÑ*¨V´e¸E³lÑ-BÑBˆE�#‰JØ˜3‘x $‘¨Ñ/ˆC�ŠHð	0ð 5:·K±K³M×B©¨¨S��S˜3˜s™8‘^Ñ#ÓBÐBùÓBs   ÁA,©r   )r   r9   Údict)r2   r?   r=   r>   s   ` @@r   ÚEMArB   B   s>   ú€ ô  +¬5Ó1€CÜ!,¬UÓ!3€EñCœð C¤uð C´T÷ Cð €Nr   ÚnumÚsuffixc                 óZ   — dD ]  }t        | «      dk  r
d| ||fz  c S | dz  } Œ! d| d|fz  S )zk
    Given `num` bytes, return human readable size.
    Taken from https://stackoverflow.com/a/1094933
    )Ú ÚKiÚMiÚGiÚTiÚPiÚEiÚZig      �@z	%3.1f%s%sz%.1f%s%sÚYi)Úabs)rC   rD   Úunits      r   Ú
sizeof_fmtrQ   W   sN   € ð
 ?ò ˆÜˆs‹8�fÒØ # t¨VÐ!4Ñ4Ò4Øˆv‰‰ðð ˜˜d FÐ+Ñ+Ð+r   Úcountc              #   ó  K  — g }	 t        | «      D ]1  }|j                  t        j                  d¬«      j                  «       Œ3 |–— |r|D ]  }t        j                  |«       Œ y y # |r|D ]  }t        j                  |«       Œ w w xY w­w)NF)Údelete)Úranger,   ÚtempfileÚNamedTemporaryFiler)   ÚosÚunlink)rR   rT   ÚnamesÚ_r)   s        r   Útemp_filenamesr\   c   s‹   è ø€ à€Eð Ü�u“ò 	IˆAØ�L‰Lœ×4Ñ4¸EÔB×GÑGÕHð	IàŠáØò  �Ü—	‘	˜$•ñ ð ø‰6Øò  �Ü—	‘	˜$•ñ ð üs   ‚B†AA) Á	 BÁ)!B
Â
BÚmax_samplesÚseedc                 óâ   — |t        | «      k\  r| S t        j                  «       j                  |«      }t        j                  t        | «      |¬«      }t        | |d | j                  «       «      S )N)Ú	generator)Úlenr!   Ú	GeneratorÚmanual_seedÚrandpermr   Útolist)Údatasetr]   r^   r`   Úperms        r   Úrandom_subsetrh   p   s[   € Ø”c˜'“lÒ"Øˆä—‘Ó!×-Ñ-¨dÓ3€IÜ�>‰>œ#˜g›,°)Ô<€DÜ�'˜4  Ð-×4Ñ4Ó6Ó7Ð7r   c                   ó:   — e Zd Z G d„ d«      Zdd„Zd„ Zd„ Zd„ Zy)	ÚDummyPoolExecutorc                   ó   — e Zd Zd„ Zd„ Zy)úDummyPoolExecutor.DummyResultc                 ó.   — || _         || _        || _        y r7   ©ÚfuncÚargsÚkwargs©Úselfro   rp   rq   s       r   Ú__init__z&DummyPoolExecutor.DummyResult.__init__{   s   € ØˆDŒIØˆDŒIØ ˆD�Kr   c                 óN   —  | j                   | j                  i | j                  ¤ŽS r7   rn   ©rs   s    r   Úresultz$DummyPoolExecutor.DummyResult.result€   s    € Ø�4—9‘9˜dŸi™iÐ7¨4¯;©;Ñ7Ð7r   N)Ú__name__Ú
__module__Ú__qualname__rt   rw   © r   r   ÚDummyResultrl   z   s   „ ò	!ó
	8r   r|   c                  ó   — y r7   r{   )rs   Úworkerss     r   rt   zDummyPoolExecutor.__init__ƒ   s   € Ør   c                 ó4   — t        j                  |g|¢­i |¤ŽS r7   )rj   r|   rr   s       r   ÚsubmitzDummyPoolExecutor.submit†   s   € Ü ×,Ñ,¨TÐC°DÒC¸FÑCÐCr   c                 ó   — | S r7   r{   rv   s    r   Ú	__enter__zDummyPoolExecutor.__enter__‰   s   € Øˆr   c                  ó   — y r7   r{   )rs   Úexc_typeÚ	exc_valueÚexc_tbs       r   Ú__exit__zDummyPoolExecutor.__exit__Œ   s   € Ør   N)r   )rx   ry   rz   r|   rt   r€   r‚   r‡   r{   r   r   rj   rj   y   s!   „ ÷8ñ 8óòDòór   rj   r@   )ÚB)T)é*   )Úcollectionsr   Ú
contextlibr   r   rX   rV   ÚtypingÚtpr!   Útorch.nnr   r   Útorch.utils.datar   r   r"   ÚUnionÚintr'   ÚListrA   Ústrr1   r9   rB   rQ   r\   rh   rj   r{   r   r   ú<module>r”      sÃ   ðõ $Ý %Û Û 	Û Û ã Ý $Ý #òBð$˜Ÿ™ð °·±¸%¿,¹,ÈÐ:KÑ1Ló ð&˜Ÿ™ ™ð ¨có ñˆeó ñ*	,�Eð 	, 3ó 	,ð ñ	 ˜#ò 	 ó ð	 ñ8¨ð 8°3ó 8÷ò r   