U
    š»|eN%  ã                   @   s@   d dl Zdd„ ZG dd„ dƒZG dd„ dƒZG dd	„ d	eƒZdS )
é    Nc                    sf   t  |¡}t  |jt j¡r,|s&tdƒ‚t‰ nt‰ |jˆ dd�}|j	dkrPtdƒ‚‡ ‡fdd„}||fS )z=Helper function for checking arguments common to all solvers.zX`y0` is complex, but the chosen solver does not support integration in a complex domain.F)Úcopyé   z`y0` must be 1-dimensional.c                    s   t jˆ| |ƒˆ d�S )N)Údtype)ÚnpÚasarray©ÚtÚy©r   Úfun© úV/var/www/website-v5/atlas_env/lib/python3.8/site-packages/scipy/integrate/_ivp/base.pyÚfun_wrapped   s    z$check_arguments.<locals>.fun_wrapped)
r   r   Ú
issubdtyper   ÚcomplexfloatingÚ
ValueErrorÚcomplexÚfloatÚastypeÚndim)r   Úy0Úsupport_complexr   r   r
   r   Úcheck_arguments   s    

r   c                   @   sJ   e Zd ZdZdZddd„Zedd„ ƒZdd	„ Zd
d„ Z	dd„ Z
dd„ ZdS )Ú	OdeSolveraÙ  Base class for ODE solvers.

    In order to implement a new solver you need to follow the guidelines:

        1. A constructor must accept parameters presented in the base class
           (listed below) along with any other parameters specific to a solver.
        2. A constructor must accept arbitrary extraneous arguments
           ``**extraneous``, but warn that these arguments are irrelevant
           using `common.warn_extraneous` function. Do not pass these
           arguments to the base class.
        3. A solver must implement a private method `_step_impl(self)` which
           propagates a solver one step further. It must return tuple
           ``(success, message)``, where ``success`` is a boolean indicating
           whether a step was successful, and ``message`` is a string
           containing description of a failure if a step failed or None
           otherwise.
        4. A solver must implement a private method `_dense_output_impl(self)`,
           which returns a `DenseOutput` object covering the last successful
           step.
        5. A solver must have attributes listed below in Attributes section.
           Note that ``t_old`` and ``step_size`` are updated automatically.
        6. Use `fun(self, t, y)` method for the system rhs evaluation, this
           way the number of function evaluations (`nfev`) will be tracked
           automatically.
        7. For convenience, a base class provides `fun_single(self, t, y)` and
           `fun_vectorized(self, t, y)` for evaluating the rhs in
           non-vectorized and vectorized fashions respectively (regardless of
           how `fun` from the constructor is implemented). These calls don't
           increment `nfev`.
        8. If a solver uses a Jacobian matrix and LU decompositions, it should
           track the number of Jacobian evaluations (`njev`) and the number of
           LU decompositions (`nlu`).
        9. By convention, the function evaluations used to compute a finite
           difference approximation of the Jacobian should not be counted in
           `nfev`, thus use `fun_single(self, t, y)` or
           `fun_vectorized(self, t, y)` when computing a finite difference
           approximation of the Jacobian.

    Parameters
    ----------
    fun : callable
        Right-hand side of the system. The calling signature is ``fun(t, y)``.
        Here ``t`` is a scalar and there are two options for ndarray ``y``.
        It can either have shape (n,), then ``fun`` must return array_like with
        shape (n,). Or, alternatively, it can have shape (n, n_points), then
        ``fun`` must return array_like with shape (n, n_points) (each column
        corresponds to a single column in ``y``). The choice between the two
        options is determined by `vectorized` argument (see below).
    t0 : float
        Initial time.
    y0 : array_like, shape (n,)
        Initial state.
    t_bound : float
        Boundary time --- the integration won't continue beyond it. It also
        determines the direction of the integration.
    vectorized : bool
        Whether `fun` is implemented in a vectorized fashion.
    support_complex : bool, optional
        Whether integration in a complex domain should be supported.
        Generally determined by a derived solver class capabilities.
        Default is False.

    Attributes
    ----------
    n : int
        Number of equations.
    status : string
        Current status of the solver: 'running', 'finished' or 'failed'.
    t_bound : float
        Boundary time.
    direction : float
        Integration direction: +1 or -1.
    t : float
        Current time.
    y : ndarray
        Current state.
    t_old : float
        Previous time. None if no steps were made yet.
    step_size : float
        Size of the last successful step. None if no steps were made yet.
    nfev : int
        Number of the system's rhs evaluations.
    njev : int
        Number of the Jacobian evaluations.
    nlu : int
        Number of LU decompositions.
    z8Required step size is less than spacing between numbers.Fc           	         s¶   d ˆ _ |ˆ _t|||ƒ\ˆ _ˆ _|ˆ _|ˆ _|rD‡ fdd„}ˆ j}nˆ j}‡ fdd„}‡ fdd„}|ˆ _|ˆ _|ˆ _	||krŠt
 || ¡ndˆ _ˆ jjˆ _dˆ _d	ˆ _d	ˆ _d	ˆ _d S )
Nc                    s   ˆ   | |d d …d f ¡ ¡ S ©N)Ú_funÚravelr   ©Úselfr   r   Ú
fun_single|   s    z&OdeSolver.__init__.<locals>.fun_singlec                    s:   t  |¡}t|jƒD ] \}}ˆ  | |¡|d d …|f< q|S r   )r   Ú
empty_likeÚ	enumerateÚTr   )r   r	   ÚfÚiÚyir   r   r   Úfun_vectorized‚   s    
z*OdeSolver.__init__.<locals>.fun_vectorizedc                    s   ˆ  j d7  _ ˆ  | |¡S )Nr   )Únfevr   r   r   r   r   r   ˆ   s    zOdeSolver.__init__.<locals>.funr   Úrunningr   )Út_oldr   r   r   r	   Út_boundÚ
vectorizedr   r   r&   r   ÚsignÚ	directionÚsizeÚnÚstatusr'   ÚnjevÚnlu)	r   r   Út0r   r*   r+   r   r   r&   r   r   r   Ú__init__s   s(    
zOdeSolver.__init__c                 C   s$   | j d krd S t | j| j  ¡S d S r   )r)   r   Úabsr   r   r   r   r   Ú	step_size˜   s    
zOdeSolver.step_sizec                 C   sˆ   | j dkrtdƒ‚| jdks(| j| jkrD| j| _| j| _d}d| _ n@| j}|  ¡ \}}|sbd| _ n"|| _| j| j| j  dkr„d| _ |S )a  Perform one integration step.

        Returns
        -------
        message : string or None
            Report from the solver. Typically a reason for a failure if
            `self.status` is 'failed' after the step was taken or None
            otherwise.
        r(   z/Attempt to step on a failed or finished solver.r   NÚfinishedÚfailed)r0   ÚRuntimeErrorr/   r   r*   r)   Ú
_step_implr-   )r   Úmessager   Úsuccessr   r   r   ÚstepŸ   s    

zOdeSolver.stepc                 C   sF   | j dkrtdƒ‚| jdks(| j| j kr:t| j | j| jƒS |  ¡ S dS )z½Compute a local interpolant over the last successful step.

        Returns
        -------
        sol : `DenseOutput`
            Local interpolant over the last successful step.
        Nz;Dense output is available after a successful step was made.r   )r)   r9   r/   r   ÚConstantDenseOutputr	   Ú_dense_output_implr   r   r   r   Údense_outputÀ   s
    
zOdeSolver.dense_outputc                 C   s   t ‚d S r   ©ÚNotImplementedErrorr   r   r   r   r:   Ò   s    zOdeSolver._step_implc                 C   s   t ‚d S r   rA   r   r   r   r   r?   Õ   s    zOdeSolver._dense_output_implN)F)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚTOO_SMALL_STEPr4   Úpropertyr6   r=   r@   r:   r?   r   r   r   r   r      s   W ÿ
%
!r   c                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚDenseOutputaO  Base class for local interpolant over step made by an ODE solver.

    It interpolates between `t_min` and `t_max` (see Attributes below).
    Evaluation outside this interval is not forbidden, but the accuracy is not
    guaranteed.

    Attributes
    ----------
    t_min, t_max : float
        Time range of the interpolation.
    c                 C   s(   || _ || _t||ƒ| _t||ƒ| _d S r   )r)   r   ÚminÚt_minÚmaxÚt_max)r   r)   r   r   r   r   r4   å   s    zDenseOutput.__init__c                 C   s&   t  |¡}|jdkrtdƒ‚|  |¡S )ae  Evaluate the interpolant.

        Parameters
        ----------
        t : float or array_like with shape (n_points,)
            Points to evaluate the solution at.

        Returns
        -------
        y : ndarray, shape (n,) or (n, n_points)
            Computed values. Shape depends on whether `t` was a scalar or a
            1-D array.
        r   z#`t` must be a float or a 1-D array.)r   r   r   r   Ú
_call_impl©r   r   r   r   r   Ú__call__ë   s    

zDenseOutput.__call__c                 C   s   t ‚d S r   rA   rO   r   r   r   rN   þ   s    zDenseOutput._call_implN)rC   rD   rE   rF   r4   rP   rN   r   r   r   r   rI   Ù   s   rI   c                       s(   e Zd ZdZ‡ fdd„Zdd„ Z‡  ZS )r>   z“Constant value interpolator.

    This class used for degenerate integration cases: equal integration limits
    or a system with 0 equations.
    c                    s   t ƒ  ||¡ || _d S r   )Úsuperr4   Úvalue)r   r)   r   rR   ©Ú	__class__r   r   r4     s    zConstantDenseOutput.__init__c                 C   sN   |j dkr| jS t | jjd |jd f¡}| jd d …d f |d d …< |S d S )Nr   )r   rR   r   ÚemptyÚshape)r   r   Úretr   r   r   rN     s
    
zConstantDenseOutput._call_impl)rC   rD   rE   rF   r4   rN   Ú__classcell__r   r   rS   r   r>     s   r>   )Únumpyr   r   r   rI   r>   r   r   r   r   Ú<module>   s
    A)