Ë
    ÜÍ:j¡7  ã                   óú  — d dl Z d dlZd dlZd dlmZmZmZ d dlm	Z	m
Z
 d dlmZmZ d dlmZ d dlmZmZ ej&                  j)                  ed¬«      Z G d	„ d
«      Z G d„ de«      Z G d„ d«      Z G d„ de«      Z G d„ de«      Z G d„ de«      Z G d„ de«      Z G d„ de	e«      Z G d„ de	e«      Z G d„ de	«      Z G d„ de«      Z  G d„ d e«      Z! G d!„ d"e	e«      Z"d#„ Z# G d$„ d%e	«      Z$ G d&„ d'e	e«      Z%y)(é    N)ÚBaseEstimatorÚ_fit_contextÚclone)ÚCallbackSupportMixinÚwith_callbacks)Úopen_listenerÚsend)Ú_IS_WASM)ÚParallelÚdelayedz*callback tests are skipped on WASM/Pyodide)Úreasonc                   óL   — e Zd ZdZd„ Zd„ Zdddddœd„Zdddddœd„Zd„ Zd	„ Z	y)
ÚRecordingCallbacka   A minimal callback used for smoke testing purposes.

    This callback keeps a record of the hooks called for introspection.

    This callback doesn't define `max_propagation_depth` and is therefore not an
    `AutoPropagatedCallback`: it should not be propagated to sub-estimators.
    c                 ó^   — g | _         t        | j                   j                  | ¬«      | _        y )N)Úowner)Úrecordr   ÚappendÚ_listener_handle)Úselfs    úr/home/mcse/projects/srt_converter/srt-converter-venv/lib/python3.12/site-packages/sklearn/callback/tests/_utils.pyÚ__init__zRecordingCallback.__init__   s"   € ØˆŒÜ -¨d¯k©k×.@Ñ.@ÈÔ MˆÕó    c                 ó8   — t        | j                  d||dœ«       y )NÚsetup©ÚnameÚ	estimatorÚcontext©r	   r   ©r   r   r   s      r   r   zRecordingCallback.setup"   s   € ÜØ×!Ñ!Ø¨9ÀÑIõ	
r   N©ÚXÚyÚmetadataÚfitted_estimatorc                óD   — t        | j                  d||||||dœdœ«       y )NÚon_fit_task_beginr!   ©r   r   r   Úkwargsr   ©r   r   r   r"   r#   r$   r%   s          r   r'   z#RecordingCallback.on_fit_task_begin(   s4   € ô 	Ø×!Ñ!à+Ø&Ø"àØØ (Ø(8ñ	ñ	
õ	
r   c                óD   — t        | j                  d||||||dœdœ«       y )NÚon_fit_task_endr!   r(   r   r*   s          r   r,   z!RecordingCallback.on_fit_task_endA   s4   € ô 	Ø×!Ñ!à)Ø&Ø"àØØ (Ø(8ñ	ñ	
õ	
r   c                 ó8   — t        | j                  d||dœ«       y )NÚteardownr   r   r    s      r   r.   zRecordingCallback.teardownZ   s   € ÜØ×!Ñ!Ø¨iÀGÑLõ	
r   c                 ód   — t        | j                  D �cg c]  }|d   |k(  sŒ|‘Œ c}«      S c c}w )Nr   )Úlenr   )r   Ú	hook_nameÚrecs      r   Úcount_hookszRecordingCallback.count_hooks`   s*   € Ü 4§;¡;ÖK˜C°#°f±+ÀÓ2J’CÒKÓLÐLùÒKs   ”-¢-)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r'   r,   r.   r3   © r   r   r   r      sC   „ ñòNò
ð Ø
ØØô
ð< Ø
ØØô
ò2
óMr   r   c                   ó   — e Zd ZdZdZy)ÚRecordingAutoPropagatedCallbackaF  A minimal auto-propagated callback used for smoke testing purposes.

    This callback keeps a record of the hooks called for introspection.

    This callback defines `max_propagation_depth` and is therefore an
    `AutoPropagatedCallback`: it should be set on a top-level estimator and propagated
    to sub-estimators.
    N)r4   r5   r6   r7   Úmax_propagation_depthr8   r   r   r:   r:   d   s   „ ñð !Ñr   r:   c                   ó   — e Zd ZdZd„ Zd„ Zy)ÚNotValidCallbackz>Invalid callback since it's missing methods from the protocol.c                  ó   — y ©Nr8   r    s      r   r   zNotValidCallback.setupt   ó   € Ør   c                  ó   — y r?   r8   r    s      r   r,   z NotValidCallback.on_fit_task_endw   r@   r   N)r4   r5   r6   r7   r   r,   r8   r   r   r=   r=   q   s   „ ÙHòór   r=   c                   ó   — e Zd ZdZddœd„Zy)ÚNotValidHookCallbackzIInvalid callback since it has invalid parameters in the hooks signatures.N)Únot_valid_kwargc                 ó   — y r?   r8   )r   r   r   rD   s       r   r'   z&NotValidHookCallback.on_fit_task_begin~   r@   r   )r4   r5   r6   r7   r'   r8   r   r   rC   rC   {   s   „ ÙSàGKõ r   rC   c                   óL   ‡ — e Zd ZdZdˆ fd„	Zˆ fd„Zˆ fd„Zˆ fd„Zˆ fd„Zˆ xZ	S )ÚFailingCallbackz.A callback that raises an error at some point.c                 ó0   •— t         ‰| �  «        || _        y r?   )Úsuperr   Úfail_at)r   rJ   Ú	__class__s     €r   r   zFailingCallback.__init__…   s   ø€ Ü‰ÑÔØˆ�r   c                 óZ   •— t         ‰| �  ||«       | j                  dk(  rt        d«      ‚y )Nr   z Failing callback failed at setup)rI   r   rJ   Ú
ValueError©r   r   r   rK   s      €r   r   zFailingCallback.setup‰   s.   ø€ Ü‰‰�i Ô)Ø�<‰<˜7Ò"ÜÐ?Ó@Ð@ð #r   c                 óZ   •— t         ‰| �  ||«       | j                  dk(  rt        d«      ‚y )Nr'   z,Failing callback failed at on_fit_task_begin)rI   r'   rJ   rM   rN   s      €r   r'   z!FailingCallback.on_fit_task_beginŽ   s0   ø€ Ü‰Ñ! )¨WÔ5Ø�<‰<Ð.Ò.ÜÐKÓLÐLð /r   c                 óZ   •— t         ‰| �  ||«       | j                  dk(  rt        d«      ‚y )Nr,   z*Failing callback failed at on_fit_task_end)rI   r,   rJ   rM   rN   s      €r   r,   zFailingCallback.on_fit_task_end“   s0   ø€ Ü‰Ñ 	¨7Ô3Ø�<‰<Ð,Ò,ÜÐIÓJÐJð -r   c                 óZ   •— t         ‰| �  ||«       | j                  dk(  rt        d«      ‚y )Nr.   z#Failing callback failed at teardown)rI   r.   rJ   rM   rN   s      €r   r.   zFailingCallback.teardown˜   s/   ø€ Ü‰Ñ˜ GÔ,Ø�<‰<˜:Ò%ÜÐBÓCÐCð &r   r?   )
r4   r5   r6   r7   r   r   r'   r,   r.   Ú__classcell__©rK   s   @r   rG   rG   ‚   s)   ø„ Ù8õôAô
Mô
K÷
Dð Dr   rG   c                   ó"   ‡ — e Zd ZdZˆ fd„Zˆ xZS )ÚStopFitCallbackz8A callback with a `on_fit_task_end` hook returning True.c                 ó&   •— t         ‰| �  ||«       y)NT©rI   r,   rN   s      €r   r,   zStopFitCallback.on_fit_task_end¡   s   ø€ Ü‰Ñ 	¨7Ô3Ør   ©r4   r5   r6   r7   r,   rR   rS   s   @r   rU   rU   ž   s   ø„ ÙB÷ð r   rU   c                   ó*   ‡ — e Zd ZdZdddœˆ fd„
Zˆ xZS )ÚNotRequiredKwargsCallbackzFA callback with a `on_fit_task_end` not requiring all possible kwargs.N©r"   r#   c                ó,   •— t         ‰| �  ||||¬«       y )Nr[   rW   )r   r   r   r"   r#   rK   s        €r   r,   z)NotRequiredKwargsCallback.on_fit_task_end©   s   ø€ Ü‰Ñ 	¨7°a¸1ÐÕ=r   rX   rS   s   @r   rZ   rZ   ¦   s   ø„ ÙPà7;¸t÷ >ò >r   rZ   c                   óX   — e Zd ZU dZi Zeed<   d
d„Z ed¬«      	 	 dddœd„«       Z	d	„ Z
y)ÚMaxIterEstimatora+  A class that mimics the behavior of an estimator.

    The iterative part uses a loop with a max number of iterations known in advance.

    This estimator computes arbitrary predictions by averaging the feature
    values and multiplying the result by the number of iterations done
    in fit.
    Ú_parameter_constraintsc                 ó    — || _         || _        y r?   ©Úmax_iterÚcomputation_intensity©r   rb   rc   s      r   r   zMaxIterEstimator.__init__¹   ó   € Ø ˆŒØ%:ˆÕ"r   F©Úprefer_skip_nested_validationN)Úsample_weightc          	      ó¶  ‡— | j                  | j                  ¬«      }|�d|ini }|j                  | |||¬«       t        | j                  «      D ]f  Š|j	                  d‰› �¬«      }|j                  | |||¬«       t        j                  | j                  «       |j                  | |||ˆfd„¬«      sŒf n ‰dz   | _	        |j                  | |||i ¬«       | S )	N©Úmax_subtasksrh   ©r   r"   r#   r$   z
iteration ©Ú	task_namec                  ó   •— d‰ dz   iS )NÚn_iter_é   r8   )Úis   €r   ú<lambda>z&MaxIterEstimator.fit.<locals>.<lambda>Ö   s   ø€ °9¸aÀ!¹eÐ2D€ r   )r   r"   r#   r$   Úreconstruction_attributesrq   ©
Ú_init_callback_contextrb   Úcall_on_fit_task_beginÚrangeÚ
subcontextÚtimeÚsleeprc   Úcall_on_fit_task_endrp   )r   r"   r#   rh   Úcallback_ctxr$   ry   rr   s          @r   ÚfitzMaxIterEstimator.fit½   s  ø€ ð ×2Ñ2ÀÇÁÐ2ÓNˆØ7DÐ7P�O ]Ñ3ÐVXˆØ×+Ñ+°d¸aÀ1ÈxÐ+ÔXä�t—}‘}Ó%ò 	ˆAØ%×0Ñ0¸ZÈÀsÐ;KÐ0ÓLˆJØ×-Ñ-Ø ! q°8ð .ô ô �J‰J�t×1Ñ1Ô2à×.Ñ.ØØØØ!Û*Dð /õ ñ ð	ð" ˜1‘uˆŒà×)Ñ)ØØØØØ&(ð 	*ô 	
ð ˆr   c                 óJ   — t        j                  |d¬«      | j                  z  S )Nrq   )Úaxis)ÚnpÚmeanrp   ©r   r"   s     r   ÚpredictzMaxIterEstimator.predictæ   s   € Ü�w‰w�q˜qÔ! D§L¡LÑ0Ð0r   ©é   çü©ñÒMbP?©NN)r4   r5   r6   r7   r_   ÚdictÚ__annotations__r   r   r~   r„   r8   r   r   r^   r^   ­   sJ   … ñð $&Ð˜DÓ%ó;ñ °Ô6ð Ø
ð&ð
 ó&ó 7ð&óP1r   r^   c                   óH   — e Zd ZU dZi Zeed<   dd„Z ed¬«      d	d„«       Z	y)
ÚWhileEstimatorz”A class that mimics the behavior of an estimator.

    The iterative part uses a while loop with a number of iterations unknown in
    advance.
    r_   c                 ó   — || _         y r?   )rc   )r   rc   s     r   r   zWhileEstimator.__init__ó   s
   € Ø%:ˆÕ"r   Frf   Nc                 óH  — | j                  d ¬«      }|j                  | ||¬«       d}	 |j                  «       }|j                  | ||¬«       t        j                  | j
                  «       |j                  | ||¬«      rn|dk(  rn|dz  }Œd|j                  | ||¬«       | S )Nrj   ©r   r"   r#   r   r†   rq   )rv   rw   ry   rz   r{   rc   r|   ©r   r"   r#   r}   rr   ry   s         r   r~   zWhileEstimator.fitö   s³   € à×2Ñ2ÀÐ2ÓEˆØ×+Ñ+°d¸aÀ1Ð+ÔEàˆØØ%×0Ñ0Ó2ˆJØ×-Ñ-¸ÀÀQÐ-ÔGä�J‰J�t×1Ñ1Ô2à×.Ñ.¸ÀÀaÐ.ÔHØà�BŠwØà�‰FˆAð ð 	×)Ñ)°D¸AÀÐ)ÔCàˆr   )r‡   rˆ   ©
r4   r5   r6   r7   r_   r‰   rŠ   r   r   r~   r8   r   r   rŒ   rŒ   ê   s2   … ñð $&Ð˜DÓ%ó;ñ °Ô6òó 7ñr   rŒ   c                   ó*   — e Zd ZdZdd„Zedd„«       Zy)ÚThirdPartyEstimatorzaA class that mimics a third-party estimator with callback support only using
    public API.
    c                 ó    — || _         || _        y r?   ra   rd   s      r   r   zThirdPartyEstimator.__init__  re   r   Nc                 óˆ  — | j                  | j                  ¬«      }|j                  | ||¬«       t        | j                  «      D ][  }|j	                  «       }|j                  | ||¬«       t        j                  | j                  «       |j                  | ||¬«      sŒ[ n |j                  | ||¬«       dz   | _	        | S )Nrj   r�   rq   ru   r�   s         r   r~   zThirdPartyEstimator.fit  sº   € à×2Ñ2ÀÇÁÐ2ÓNˆØ×+Ñ+°d¸aÀ1Ð+ÔEä�t—}‘}Ó%ò 	ˆAØ%×0Ñ0Ó2ˆJØ×-Ñ-¸ÀÀQÐ-ÔGä�J‰J�t×1Ñ1Ô2à×.Ñ.¸ÀÀaÐ.ÕHÙð	ð 	×)Ñ)°D¸AÀÐ)ÔCà˜1‘uˆŒàˆr   r…   rˆ   ©r4   r5   r6   r7   r   r   r~   r8   r   r   r“   r“     s    „ ñó;ð òó ñr   r“   c                   óX   ‡ — e Zd ZU dZi Zeed<   dˆ fd„	Z ed¬«      dˆ fd„	«       Z	ˆ xZ
S )	ÚParentFitEstimatorz=A class that mimics an estimator using its parent fit method.r_   c                 ó&   •— t         ‰| �  ||«       y r?   )rI   r   )r   rb   rc   rK   s      €r   r   zParentFitEstimator.__init__2  s   ø€ Ü‰Ñ˜Ð#8Õ9r   Frf   c                 ó$   •— t         ‰| �  ||«      S r?   )rI   r~   )r   r"   r#   rK   s      €r   r~   zParentFitEstimator.fit5  s   ø€ ä‰w‰{˜1˜aÓ Ð r   r…   rˆ   )r4   r5   r6   r7   r_   r‰   rŠ   r   r   r~   rR   rS   s   @r   r˜   r˜   -  s/   ø… ÙGà#%Ð˜DÓ%õ:ñ °Ô6ô!ó 7ô!r   r˜   c                   ó&   — e Zd ZdZdd„Zdd„Zd„ Zy)ÚNoCallbackEstimatorz:A class that mimics an estimator without callback support.c                 ó    — || _         || _        y r?   ra   rd   s      r   r   zNoCallbackEstimator.__init__=  re   r   Nc                 óx   — t        | j                  «      D ]!  }t        j                  | j                  «       Œ# | S r?   )rx   rb   rz   r{   rc   )r   r"   r#   rr   s       r   r~   zNoCallbackEstimator.fitA  s3   € Ü�t—}‘}Ó%ò 	3ˆAÜ�J‰J�t×1Ñ1Õ2ð	3ð ˆr   c                 óF   — t        j                  |j                  d   «      S )Nr   )r�   ÚzerosÚshaperƒ   s     r   r„   zNoCallbackEstimator.predictG  s   € Ü�x‰x˜Ÿ™ ™
Ó#Ð#r   r…   rˆ   )r4   r5   r6   r7   r   r~   r„   r8   r   r   rœ   rœ   :  s   „ ÙDó;óó$r   rœ   c                   óJ   — e Zd ZU dZi Zeed<   	 dd„Z ed¬«      d	d„«       Z	y)
ÚMetaEstimatora0  A class that mimics the behavior of a meta-estimator.

    It has two levels of iterations. The outer level uses parallelism and the inner
    level is done in a function that is not a method of the class. That function must
    therefore receive the estimator and the callback context as arguments.
    r_   Nc                 óJ   — || _         || _        || _        || _        || _        y r?   )r   Ún_outerÚn_innerÚn_jobsÚprefer)r   r   r¥   r¦   r§   r¨   s         r   r   zMetaEstimator.__init__U  s'   € ð #ˆŒØˆŒØˆŒØˆŒØˆ�r   Frf   c                 óÄ  ‡ ‡‡‡‡— ‰ j                  ‰ j                  d¬«      }|�d|ini Š|j                  ‰ ‰‰‰¬«       t        ‰ j                  «      D �cg c]   }|j	                  d|‰ j
                  ¬«      ‘Œ" c}Š t        ‰ j                  ‰ j                  ¬«      ˆˆˆˆ ˆfd„t        ‰ j                  «      D «       «       |j                  ‰ ‰‰‰¬«       ‰ S c c}w )	NF)rk   Úsequential_subtasksrh   rl   Úouter)rn   Útask_idrk   )r§   r¨   c           
   3   ón   •K  — | ],  } t        t        «      ‰‰j                  ‰‰‰‰|   ¬ «      –— Œ. y­w))r"   r#   r$   Úouter_callback_ctxN)r   Ú_fit_subestimatorr   )Ú.0rr   r"   r$   Úouter_callback_contextsr   r#   s     €€€€€r   ú	<genexpr>z$MetaEstimator.fit.<locals>.<genexpr>m  sH   øè ø€ ò 
9
ð ð 'ŒGÔ%Ó&ØØ—‘ØØØ!Ø#:¸1Ñ#=÷ð ñ
9
ùs   ƒ25)
rv   r¥   rw   rx   ry   r¦   r   r§   r¨   r|   )r   r"   r#   rh   r}   rr   r$   r±   s   ```   @@r   r~   zMetaEstimator.fit^  sä   ü€ à×2Ñ2ØŸ™¸5ð 3ó 
ˆð 8EÐ7P�O ]Ñ3ÐVXˆØ×+Ñ+°d¸aÀ1ÈxÐ+ÔXô ˜4Ÿ<™<Ó(ö	#
ð ð ×#Ñ#Ø!¨1¸4¿<¹<ð $õ ò#
Ðð 	9Œ˜Ÿ™¨D¯K©KÔ8÷ 
9
ô ˜4Ÿ<™<Ó(ô
9
ô 
	
ð 	×)Ñ)°D¸AÀÈXÐ)ÔVàˆùò+#
s   Á%C)é   é   NÚ	processes)NNNr‘   r8   r   r   r£   r£   K  s9   … ñð $&Ð˜DÓ%ð DOóñ °Ô6òó 7ñr   r£   c                ó�  — |j                  | |||¬«       t        | j                  «      D ]x  }t        |«      }|j	                  d¬«      }|j                  |«      5  |j                  | |||¬«        |j                  d||dœ|¤Ž |j                  | |||¬«       d d d «       Œz |j                  | |||¬«       y # 1 sw Y   ŒšxY w)Nrl   Úinnerrm   r[   r8   )rw   rx   r¦   r   ry   Úpropagate_callback_contextr~   r|   )	Úmeta_estimatorÚinner_estimatorr"   r#   r$   r®   rr   ÚestÚ	inner_ctxs	            r   r¯   r¯   ~  sñ   € ð ×-Ñ-Ø  A¨°Xð .ô ô �>×)Ñ)Ó*ò ˆÜ�OÓ$ˆà&×1Ñ1¸GÐ1ÓDˆ	Ø×1Ñ1°#Ó6ñ 		Ø×,Ñ,Ø(¨A°¸Xð -ô ð ˆC�G‰GÐ)�a˜1Ñ) Ò)à×*Ñ*Ø(¨A°¸Xð +ô ÷		ð 		ð	ð ×+Ñ+Ø  A¨°Xð ,õ ÷		ð 		ús   ÁA B<Â<C	c                   ó(   — e Zd ZdZd„ Zedd„«       Zy)ÚHeterogeneousMetaEstimatorz9A meta-estimator that fits a list of estimators in order.c                 ó   — || _         y r?   )Ú
estimators)r   rÀ   s     r   r   z#HeterogeneousMetaEstimator.__init__œ  s	   € Ø$ˆ�r   Nc                 ój  — | j                  t        | j                  «      ¬«      }|j                  | ||¬«       t	        | j                  «      D ]Á  \  }}|rd|j
                  j                  › �nd|› �}|j                  |¬«      }|�`t        |«      }|j                  |«      5  |j                  | ||¬«       |j                  ||«       |j                  | ||¬«       d d d «       Œš|j                  | ||¬«       |j                  | ||¬«       ŒÃ |j                  | ||¬«       | S # 1 sw Y   ŒãxY w)Nrj   r�   zfit zskip rm   )rv   r0   rÀ   rw   Ú	enumeraterK   r4   ry   r   r¸   r~   r|   )r   r"   r#   r}   rr   r»   rn   ry   s           r   r~   zHeterogeneousMetaEstimator.fitŸ  s?  € à×2Ñ2ÄÀDÇOÁOÓ@TÐ2ÓUˆØ×+Ñ+°d¸aÀ1Ð+ÔEä §¡Ó0ò 	J‰FˆAˆsÙ;>˜$˜sŸ}™}×5Ñ5Ð6Ñ7ÀeÈAÈ3ÀKˆIØ%×0Ñ0¸9Ð0ÓEˆJØˆÜ˜C“j�Ø×:Ñ:¸3Ó?ñ NØ×5Ñ5ÀÈÈQÐ5ÔOØ—G‘G˜A˜q”MØ×3Ñ3¸dÀaÈ1Ð3ÔM÷Nð Nð
 ×1Ñ1¸DÀAÈÐ1ÔKØ×/Ñ/¸$À!ÀqÐ/ÕIð	Jð 	×)Ñ)°D¸AÀÐ)ÔCàˆ÷Nð Nús   Â%;D)Ä)D2	rˆ   r–   r8   r   r   r¾   r¾   ™  s   „ ÙCò%ð òó ñr   r¾   c                   ó"   — e Zd ZdZedd„«       Zy)ÚNoSubtaskEstimatorz7A class mimicking an estimator without subtasks in fit.Nc                 ór   — | j                  «       j                  | ||¬«      }|j                  | ||¬«       | S )Nr�   )rv   rw   r|   )r   r"   r#   r}   s       r   r~   zNoSubtaskEstimator.fit¹  sD   € à×2Ñ2Ó4×KÑKØ˜a 1ð Ló 
ˆð 	×)Ñ)°D¸AÀÐ)ÔCàˆr   rˆ   )r4   r5   r6   r7   r   r~   r8   r   r   rÄ   rÄ   ¶  s   „ ÙAàò	ó ñ	r   rÄ   )&rz   Únumpyr�   ÚpytestÚsklearn.baser   r   r   Úsklearn.callbackr   r   Úsklearn.callback._transportr   r	   Úsklearn.utils.fixesr
   Úsklearn.utils.parallelr   r   ÚmarkÚskipifÚskip_callback_test_if_wasmr   r:   r=   rC   rG   rU   rZ   r^   rŒ   r“   r˜   rœ   r£   r¯   r¾   rÄ   r8   r   r   ú<module>rÐ      s  ðó ã Û ç ;Ñ ;ß Aß ;Ý (ß 4à#Ÿ[™[×/Ñ/ØØ7ð 0ó Ð ÷LMñ LMô^
!Ð&7ô 
!÷ñ ôÐ,ô ôDÐ'ô Dô8Ð'ô ô>Ð 1ô >ô:1Ð+¨]ô :1ôz"Ð)¨=ô "ôJÐ.ô ô<
!Ð)ô 
!ô$˜-ô $ô"0Ð(¨-ô 0òfô6Ð!5ô ô:Ð-¨}õ r   