o
    ۷i                     @   s   d dl Z ddlmZ ddlmZ ddlmZmZmZmZm	Z	 G dd dej
ZG d	d
 d
ej
ZG dd dej
Z					ddedee dee deeedf  dee j dee	ee jf  fddZdS )    N   )brownian_base)brownian_interval   )OptionalScalarTensorTupleUnionc                       s^   e Zd Z fddZdddZdd Zed	d
 Zedd Zedd Z	edd Z
  ZS )ReverseBrownianc                    s   t t|   || _d S N)superr   __init__base_brownian)selfr   	__class__ P/home/ubuntu/vllm_env/lib/python3.10/site-packages/torchsde/_brownian/derived.pyr      s   
zReverseBrownian.__init__NFc                 C   s   | j | | ||dS N)return_Ureturn_A)r   )r   tatbr   r   r   r   r   __call__   s   zReverseBrownian.__call__c                 C      | j j d| j dS )Nz(base_brownian=))r   __name__r   r   r   r   r   __repr__       zReverseBrownian.__repr__c                 C      | j jS r   )r   dtyper   r   r   r   r"   #      zReverseBrownian.dtypec                 C   r!   r   )r   devicer   r   r   r   r$   '   r#   zReverseBrownian.devicec                 C   r!   r   )r   shaper   r   r   r   r%   +   r#   zReverseBrownian.shapec                 C   r!   r   )r   levy_area_approximationr   r   r   r   r&   /   r#   z'ReverseBrownian.levy_area_approximationNFF)r   
__module____qualname__r   r   r   propertyr"   r$   r%   r&   __classcell__r   r   r   r   r      s    



r   c                       sr   e Zd ZdZddededef fddZdd
dZdd Z	e
dd Ze
dd Ze
dd Ze
dd Z  ZS )BrownianPatha  Brownian path, storing every computed value.

    Useful for speed, when memory isn't a concern.

    To use:
    >>> bm = BrownianPath(t0=0.0, w0=torch.zeros(4, 1))
    >>> bm(0., 0.5)
    tensor([[ 0.0733],
            [-0.5692],
            [ 0.1872],
            [-0.3889]])
       t0w0window_sizec                    s>   |d }|| _ tj|||j|j|jdd| _tt| 	  dS )zInitialize Brownian path.
        Arguments:
            t0: Initial time.
            w0: Initial state.
            window_size: Unused; deprecated.
        r   N)r.   t1sizer"   r$   
cache_size)
_w0r   BrownianIntervalr%   r"   r$   	_intervalr   r,   r   )r   r.   r/   r0   r1   r   r   r   r   B   s   zBrownianPath.__init__NFc                 C   0   | j ||||d}|d u r|s|s|| j }|S r   r6   r4   r   tr   r   r   outr   r   r   r   O      
zBrownianPath.__call__c                 C   r   Nz
(interval=r   r   r   r6   r   r   r   r   r   V   r    zBrownianPath.__repr__c                 C   r!   r   r6   r"   r   r   r   r   r"   Y   r#   zBrownianPath.dtypec                 C   r!   r   r6   r$   r   r   r   r   r$   ]   r#   zBrownianPath.devicec                 C   r!   r   r6   r%   r   r   r   r   r%   a   r#   zBrownianPath.shapec                 C   r!   r   r6   r&   r   r   r   r   r&   e   r#   z$BrownianPath.levy_area_approximation)r-   r'   )r   r(   r)   __doc__r   r   intr   r   r   r*   r"   r$   r%   r&   r+   r   r   r   r   r,   4   s    



r,   c                       s   e Zd ZdZ							ddededee d	ee d
ee dedededee f fddZ	dddZ
dd Zedd Zedd Zedd Zedd Z  ZS ) BrownianTreea  Brownian tree with fixed entropy.

    Useful when the map from entropy -> Brownian motion shouldn't depend on the
    locations and order of the query points. (As the usual BrownianInterval
    does - note that BrownianTree is slower as a result though.)

    To use:
    >>> bm = BrownianTree(t0=0.0, w0=torch.zeros(4, 1))
    >>> bm(0., 0.5)
    tensor([[ 0.0733],
            [-0.5692],
            [ 0.1872],
            [-0.3889]], device='cuda:0')
    Nư>   	   r.   r/   r1   w1entropytol	pool_sizecache_depthsafetyc
                    sd   |du r|d }|du rd}
n|| }
|| _ tj|||j|j|j|||d|
d
| _tt| 	  dS )a  Initialize the Brownian tree.

        The random value generation process exploits the parallel random number paradigm and uses
        `numpy.random.SeedSequence`. The default generator is PCG64 (used by `default_rng`).

        Arguments:
            t0: Initial time.
            w0: Initial state.
            t1: Terminal time.
            w1: Terminal state.
            entropy: Global seed, defaults to `None` for random entropy.
            tol: Error tolerance before the binary search is terminated; the search depth ~ log2(tol).
            pool_size: Size of the pooled entropy. This parameter affects the query speed significantly.
            cache_depth: Unused; deprecated.
            safety: Unused; deprecated.
        Nr   T)
r.   r1   r2   r"   r$   rJ   rK   rL   halfway_treeW)
r4   r   r5   r%   r"   r$   r6   r   rE   r   )r   r.   r/   r1   rI   rJ   rK   rL   rM   rN   rP   r   r   r   r   z   s$   
zBrownianTree.__init__Fc                 C   r7   r   r8   r9   r   r   r   r      r<   zBrownianTree.__call__c                 C   r   r=   r>   r   r   r   r   r      r    zBrownianTree.__repr__c                 C   r!   r   r?   r   r   r   r   r"      r#   zBrownianTree.dtypec                 C   r!   r   r@   r   r   r   r   r$      r#   zBrownianTree.devicec                 C   r!   r   rA   r   r   r   r   r%      r#   zBrownianTree.shapec                 C   r!   r   rB   r   r   r   r   r&      r#   z$BrownianTree.levy_area_approximation)NNNrF   rG   rH   Nr'   )r   r(   r)   rC   r   r   r   rD   floatr   r   r   r*   r"   r$   r%   r&   r+   r   r   r   r   rE   j   sH    
-


rE                 ?yr.   r1   r2   .r"   r$   c                 K   sR   |du r| j n|}|du r| jn|}|du r| jn|}tjd|||||d|S )zZReturns a BrownianInterval object with the same size, device, and dtype as a given tensor.N)r.   r1   r2   r"   r$   r   )r%   r"   r$   r   r5   )rT   r.   r1   r2   r"   r$   kwargsr   r   r   brownian_interval_like   s   rV   )rR   rS   NNN)torch r   r   typesr   r   r   r	   r
   BaseBrownianr   r,   rE   rD   r"   strr$   rV   r   r   r   r   <module>   s.   6Y