o
    ?ß±ig  ã                   @   sœ   d Z ddlmZmZmZ ddlZddlmZmZ dej	dej	dej	dej	d	ej	d
eej	eej	 f fdd„Z
de
iZded
efdd„Zded
efdd„ZdS )zD
Impl of multistep methods to solve the ODE in the diffusion model.
é    )ÚCallableÚListÚTupleN)Úreg_x0_euler_stepÚres_x0_rk2_stepÚx_sÚsÚtÚx0_sÚx0_predsÚreturnc                 C   sD   |r|d \}}t | |||||ƒ}n	t| |||ƒd }|||fgfS )zr
    impl the second order multistep method in https://arxiv.org/pdf/2308.02157
    Adams Bashforth approach!
    r   )r   r   )r   r   r	   r
   r   Zx0_s1Ús1Zx_t© r   ú_/data/cameron/vidgen/cosmos-predict2.5/cosmos_predict2/_src/imaginaire/functional/multi_step.pyÚ	order2_fn   s
   r   Ú2abÚnamec                 C   s*   | t v rt |  S d t  ¡ ¡}td| ƒ‚)Nz
	zOnly support multistep method
)ÚMULTISTEP_FNsÚjoinÚkeysÚRuntimeError)r   Úmethodsr   r   r   Úget_multi_step_fn1   s   r   c                 C   s   | t v S )z5
    Check if the multistep method is supported.
    )r   )r   r   r   r   Úis_multi_step_fn_supported8   s   r   )Ú__doc__Útypingr   r   r   ÚtorchÚ6cosmos_predict2._src.imaginaire.functional.runge_kuttar   r   ÚTensorr   r   Ústrr   Úboolr   r   r   r   r   Ú<module>   s*   ÿÿÿÿÿ
þÿ