o
    zi                     @   sH   d dl mZ d dlZd dlmZ d dlmZ ddeded	efd
dZdS )    )CallableN)Tensor)tqdm              ?xdrift_fnNc                 K   s   |rdnd}| j ^}}	t|g| j| }
|| | }tt||dD ]!}| ||
| |  }| d||
| ||
| |  |  } |
| }
q%| S )a  
        A basic implementation of Heun second order discretisation method of the ODE associated 
        with the marginales of the learned SDE.
        
        x: Initial state
        drift_fn: Update the state x
        N: Number of steps
        t0: Initial time of integration, defaults to 0.
        t1: Final time of integration, defaults to 1.
        
        Returns the final state
        FT)disableg      ?)shapetorchonestodevicer   range)r   r   r	   t0t1verbosekwargsr
   BDtdt_new_x r   I/home/ubuntu/.local/lib/python3.10/site-packages/score_models/ode/heun.pyheun   s   
$
r   )r   r   r   )typingr   r   r   r   intr   r   r   r   r   <module>   s
    