o
    üN i  ã                   @   s$   d dl Z d dlZdd„ Zdd„ ZdS )é    Nc                 C   s¼   t  ¡ L t  t  || | ¡t d¡ ¡}t| ¡ ƒD ]&}|| d }| |ƒ}	t  |||	ƒ¡}
||
k}t  |||¡}t  |||¡}q|| d }W d   ƒ n1 sSw   Y  || |ƒfS )Ng       @)	ÚtorchÚno_gradÚceilÚlogÚmathÚrangeÚlongÚsignÚwhere)Ú	interp_fnÚsign0Út0Út1Úevent_fnÚtolÚnitrsÚ_Út_midÚy_midÚsign_midÚsame_as_sign0Úevent_t© r   úT/home/ubuntu/.local/lib/python3.10/site-packages/torchdiffeq/_impl/event_handling.pyÚ
find_event   s   
"ôr   c                    sJ   t  ¡  t  ˆ ||ƒ¡‰W d  ƒ n1 sw   Y  ‡ ‡fdd„}|S )zp
    We ensure all event functions are initially positive,
    so then we can combine them by taking a min.
    Nc                    s   ˆ | |ƒ}t  |ˆ ¡S )N)r   Úmin)ÚtÚyÚc©r   Úinitial_signsr   r   Úcombined_event_fn   s   
z2combine_event_functions.<locals>.combined_event_fn)r   r   r	   )r   r   Úy0r!   r   r   r   Úcombine_event_functions   s
   
ÿr#   )r   r   r   r#   r   r   r   r   Ú<module>   s    