o
    i                     @   sV   d Z ddlZddddddd	ZG d
d deZdd Z		dddZ		dddZdS )z- A vendored copy of scipy.optimize.fminbound.    Nz%Optimization terminated successfully.z9Maximum number of function evaluations has been exceeded.z/Maximum number of iterations has been exceeded.z=Desired error not necessarily achieved due to precision loss.zNaN result encountered.z-The result is outside of the provided bounds.)successmaxfevmaxiterpr_lossnanout_of_boundsc                   @   s   e Zd ZdZdd ZdS )OptimizeResultz) Represents the optimization result.
    c              
   C   s.   z| | W S  t y } zt||d }~ww )N)KeyErrorAttributeError)selfnamee r   Y/home/ubuntu/veenaModal/venv/lib/python3.10/site-packages/cupyx/scipy/signal/_optimize.py__getattr__   s   

zOptimizeResult.__getattr__N)__name__
__module____qualname____doc__r   r   r   r   r   r      s    r   c                 C   sR   |dkr|dkrt d|d |dkr|rt d |dkr'|r't dtd  d S )	Nr      zk
Optimization terminated successfully;
The returned value satisfies the termination criteria
(using xtol = )zO
Maximum number of function evaluations exceeded --- increase maxfun argument.
   z
{}r   )printformat_status_message)xflagfvalmaxfunxtoldispr   r   r   	_endprint   s   r!   r   h㈵>  r   c           
      C   sJ   ||d}t | ||f|fi |}	|r!|	d |	d |	d |	d fS |	d S )aU  Bounded minimization for scalar functions.

    Parameters
    ----------
    func : callable f(x,*args)
        Objective function to be minimized (must accept and return scalars).
    x1, x2 : float or array scalar
        Finite optimization bounds.
    args : tuple, optional
        Extra arguments passed to function.
    xtol : float, optional
        The convergence tolerance.
    maxfun : int, optional
        Maximum number of function evaluations allowed.
    full_output : bool, optional
        If True, return optional outputs.
    disp : int, optional
        If non-zero, print messages.
            0 : no message printing.
            1 : non-convergence notification messages only.
            2 : print a message on convergence too.
            3 : print iteration results.

    Returns
    -------
    xopt : ndarray
        Parameters (over given interval) which minimize the
        objective function.
    fval : number
        The function value evaluated at the minimizer.
    ierr : int
        An error flag (0 if converged, 1 if maximum number of
        function calls reached).
    numfunc : int
      The number of function calls made.


    Returns
    -------
    xopt : ndarray
        Parameters (over given interval) which minimize the
        objective function.

    See also
    --------
    scipy.optimize.fminbound


    Notes
    -----
    Finds a local minimizer of the scalar function `func` in the
    interval x1 < xopt < x2 using Brent's method. (See `brent`
    for auto-bracketing.)

    References
    ----------
    .. [1] Forsythe, G.E., M. A. Malcolm, and C. B. Moler. "Computer Methods
           for Mathematical Computations." Prentice-Hall Series in Automatic
           Computation 259 (1977).
    .. [2] Brent, Richard P. Algorithms for Minimization Without Derivatives.
           Courier Corporation, 2013.


    )xatolr   r   funstatusnfev)_minimize_scalar_bounded)
funcx1x2argsr   r   full_outputr    optionsresr   r   r   	fminbound.   s   Br0   c           '   	   K   sP  |}t |dkrtd|\}}	||	krtdd}
d}d}td}dd	td
  }||	}}||||   }||}}d }}|}| |g|R  }d}d||f}tj}| }}d||  }|t| |d	  }d| }|dkrtd t| td||f   t|| |d||   krd} t||kr!d} || ||  }!|| ||  }"|| |" || |!  }#d|"|!  }"|"dkr|# }#t|"}"|}!|}t|#td|" |! k r|#|"||  kr|#|"||  k r|#d |" }|| }d}|| |k s|| |k rt|| || dk }$||$ }nd} | r8||kr.|| }n|| }|| }d}t||dk }$||$tt||  }| |g|R  }|d7 }|||f}|dkrmtd||f   ||kr||krz|}n|}||}}||}}||}}n3||k r|}n|}||ks||kr||}}||}}n||ks||ks||kr||}}d||  }|t| |d	  }d| }||krd}
nt|| |d||   kst	|st	|st	|rd}
|}%|dkrt
||
|%||| t|%|
|
dkddtd d|
d|||d}&|&S )a  
    Options
    -------
    maxiter : int
        Maximum number of iterations to perform.
    disp: int, optional
        If non-zero, print messages.
            0 : no message printing.
            1 : non-convergence notification messages only.
            2 : print a message on convergence too.
            3 : print iteration results.
    xatol : float
        Absolute error in solution `xopt` acceptable for convergence.

    r   zbounds must have two elements.z(The lower bound exceeds the upper bound.r   z2 Func-count     x          f(x)          Procedurez       initialgOd@<g      ?g      @g      @g        r   g       @ z%5.0f   %12.6g %12.6g %sz       parabolicz       goldenzSolution found.z)Maximum number of function calls reached.r   )r   r   r    )r%   r&   r   messager   r'   nit)len
ValueErrorcupysqrtinfabsr   signmaximumisnanr!   r   r   get)'r)   boundsr,   r$   r   r    unknown_optionsr   r*   r+   r   headerstepsqrt_epsgolden_meanabfulcnfcxfratr   r   fxnum	fmin_datafuffulcfnfcxmtol1tol2goldenrqpsir   resultr   r   r   r(   {   s   



 
0











$G
r(   )r   r"   r#   r   r   )r   r"   r#   r   )r   r7   r   dictr   r!   r0   r(   r   r   r   r   <module>   s"    
M