
    ^Mhb                     0    d dl Z	  G d d          Zd ZdS )    Nc                   &    e Zd ZdZd ZddZd ZdS )DCSRCHa-  
    Parameters
    ----------
    phi : callable phi(alpha)
        Function at point `alpha`
    derphi : callable phi'(alpha)
        Objective function derivative. Returns a scalar.
    ftol : float
        A nonnegative tolerance for the sufficient decrease condition.
    gtol : float
        A nonnegative tolerance for the curvature condition.
    xtol : float
        A nonnegative relative tolerance for an acceptable step. The
        subroutine exits with a warning if the relative difference between
        sty and stx is less than xtol.
    stpmin : float
        A nonnegative lower bound for the step.
    stpmax :
        A nonnegative upper bound for the step.

    Notes
    -----

    This subroutine finds a step that satisfies a sufficient
    decrease condition and a curvature condition.

    Each call of the subroutine updates an interval with
    endpoints stx and sty. The interval is initially chosen
    so that it contains a minimizer of the modified function

           psi(stp) = f(stp) - f(0) - ftol*stp*f'(0).

    If psi(stp) <= 0 and f'(stp) >= 0 for some step, then the
    interval is chosen so that it contains a minimizer of f.

    The algorithm is designed to find a step that satisfies
    the sufficient decrease condition

           f(stp) <= f(0) + ftol*stp*f'(0),

    and the curvature condition

           abs(f'(stp)) <= gtol*abs(f'(0)).

    If ftol is less than gtol and if, for example, the function
    is bounded below, then there is always a step which satisfies
    both conditions.

    If no step can be found that satisfies both conditions, then
    the algorithm stops with a warning. In this case stp only
    satisfies the sufficient decrease condition.

    A typical invocation of dcsrch has the following outline:

    Evaluate the function at stp = 0.0d0; store in f.
    Evaluate the gradient at stp = 0.0d0; store in g.
    Choose a starting step stp.

    task = 'START'
    10 continue
        call dcsrch(stp,f,g,ftol,gtol,xtol,task,stpmin,stpmax,
                   isave,dsave)
        if (task .eq. 'FG') then
           Evaluate the function and the gradient at stp
           go to 10
           end if

    NOTE: The user must not alter work arrays between calls.

    The subroutine statement is

        subroutine dcsrch(f,g,stp,ftol,gtol,xtol,stpmin,stpmax,
                         task,isave,dsave)
        where

    stp is a double precision variable.
        On entry stp is the current estimate of a satisfactory
            step. On initial entry, a positive initial estimate
            must be provided.
        On exit stp is the current estimate of a satisfactory step
            if task = 'FG'. If task = 'CONV' then stp satisfies
            the sufficient decrease and curvature condition.

    f is a double precision variable.
        On initial entry f is the value of the function at 0.
        On subsequent entries f is the value of the
            function at stp.
        On exit f is the value of the function at stp.

    g is a double precision variable.
        On initial entry g is the derivative of the function at 0.
        On subsequent entries g is the derivative of the
           function at stp.
        On exit g is the derivative of the function at stp.

    ftol is a double precision variable.
        On entry ftol specifies a nonnegative tolerance for the
           sufficient decrease condition.
        On exit ftol is unchanged.

    gtol is a double precision variable.
        On entry gtol specifies a nonnegative tolerance for the
           curvature condition.
        On exit gtol is unchanged.

    xtol is a double precision variable.
        On entry xtol specifies a nonnegative relative tolerance
          for an acceptable step. The subroutine exits with a
          warning if the relative difference between sty and stx
          is less than xtol.

        On exit xtol is unchanged.

    task is a character variable of length at least 60.
        On initial entry task must be set to 'START'.
        On exit task indicates the required action:

           If task(1:2) = 'FG' then evaluate the function and
           derivative at stp and call dcsrch again.

           If task(1:4) = 'CONV' then the search is successful.

           If task(1:4) = 'WARN' then the subroutine is not able
           to satisfy the convergence conditions. The exit value of
           stp contains the best point found during the search.

          If task(1:5) = 'ERROR' then there is an error in the
          input arguments.

        On exit with convergence, a warning or an error, the
           variable task contains additional information.

    stpmin is a double precision variable.
        On entry stpmin is a nonnegative lower bound for the step.
        On exit stpmin is unchanged.

    stpmax is a double precision variable.
        On entry stpmax is a nonnegative upper bound for the step.
        On exit stpmax is unchanged.

    isave is an integer work array of dimension 2.

    dsave is a double precision work array of dimension 13.

    Subprograms called

      MINPACK-2 ... dcstep
    MINPACK-1 Project. June 1983.
    Argonne National Laboratory.
    Jorge J. More' and David J. Thuente.

    MINPACK-2 Project. November 1993.
    Argonne National Laboratory and University of Minnesota.
    Brett M. Averick, Richard G. Carter, and Jorge J. More'.
    c                 ,   d | _         d | _        d | _        d | _        d | _        d | _        d | _        d | _        d | _        d | _	        d | _
        d | _        d | _        d | _        || _        || _        || _        || _        || _        || _        || _        d S )N)stageginitgtestgxgyfinitfxfystxstystminstmaxwidthwidth1ftolgtolxtolstpminstpmaxphiderphi)selfr   r   r   r   r   r   r   s           V/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/scipy/optimize/_dcsrch.py__init__zDCSRCH.__init__   s    






 			    Nd   c                    ||                      d          }||                     d          }|}|}d}t          |          D ]u}|                     ||||          \  }	}}}t	          j        |	          sd}d}	 nA|dd         dk    r-|	}|                      |	          }|                     |	          }t nd}	d}|dd         d	k    s|dd
         dk    rd}	|	|||fS )a  
        Parameters
        ----------
        alpha1 : float
            alpha1 is the current estimate of a satisfactory
            step. A positive initial estimate must be provided.
        phi0 : float
            the value of `phi` at 0 (if known).
        derphi0 : float
            the derivative of `derphi` at 0 (if known).
        maxiter : int

        Returns
        -------
        alpha : float
            Step size, or None if no suitable step was found.
        phi : float
            Value of `phi` at the new point `alpha`.
        phi0 : float
            Value of `phi` at `alpha=0`.
        task : bytes
            On exit task indicates status information.

           If task[:4] == b'CONV' then the search is successful.

           If task[:4] == b'WARN' then the subroutine is not able
           to satisfy the convergence conditions. The exit value of
           stp contains the best point found during the search.

           If task[:5] == b'ERROR' then there is an error in the
           input arguments.
        N           START   WARN      FGs6   WARNING: dcsrch did not converge within max iterations      ERROR   )r   r   range_iteratenpisfinite)
r   alpha1phi0derphi0maxiterphi1derphi1taskistps
             r   __call__zDCSRCH.__call__   s!   B <88C==D?kk#&&Gw 	M 	MA'+}}gt( ($Cw ;s## BQBx5  xx}}++c** CLD8x48w#6#6CD$$$r   c                    d}d}d}d}|dd         dk    r)|| j         k     rd}|| j        k    rd	}|d
k    rd}| j        d
k     rd}| j        d
k     rd}| j        d
k     rd}| j         d
k     rd}| j        | j         k     rd}|dd         dk    r||||fS d| _        d| _        || _        || _        | j        | j        z  | _	        | j        | j         z
  | _
        | j
        |z  | _        d| _        | j        | _        | j        | _        d| _        | j        | _        | j        | _        d
| _        |||z  z   | _        d}||||fS | j        || j	        z  z   }	| j        dk    r||	k    r|d
k    rd| _        | j        r|| j        k    s|| j        k    rd}| j        r"| j        | j        z
  | j        | j        z  k    rd}|| j        k    r||	k    r|| j	        k    rd}|| j         k    r||	k    s|| j	        k    rd}||	k    r#t)          |          | j        | j         z  k    rd}|dd         dk    s|dd         dk    r||||fS | j        dk    r>|| j        k    r2||	k    r+||| j	        z  z
  }
| j        | j        | j	        z  z
  }| j        | j        | j	        z  z
  }|| j	        z
  }| j        | j	        z
  }| j        | j	        z
  }t+          j        dd           5  t/          | j        ||| j        ||||
|| j        | j        | j                  }|\  | _        }}| _        }}}| _        ddd           n# 1 swxY w Y   || j        | j	        z  z   | _        || j        | j	        z  z   | _        || j	        z   | _        || j	        z   | _        nt+          j        dd           5  t/          | j        | j        | j        | j        | j        | j        |||| j        | j        | j                  }ddd           n# 1 swxY w Y   |\  | _        | _        | _        | _        | _        | _        }| _        | j        rot)          | j        | j        z
            || j        z  k    r| j        || j        | j        z
  z  z   }| j
        | _        t)          | j        | j        z
            | _
        | j        r?t1          | j        | j                  | _        t3          | j        | j                  | _        n*|||| j        z
  z  z   | _        |||| j        z
  z  z   | _        t+          j        || j         | j                  }| j        r|| j        k    s2|| j        k    s'| j        r'| j        | j        z
  | j        | j        z  k    r| j        }d}||||fS )!a  
        Parameters
        ----------
        stp : float
            The current estimate of a satisfactory step. On initial entry, a
            positive initial estimate must be provided.
        f : float
            On first call f is the value of the function at 0. On subsequent
            entries f should be the value of the function at stp.
        g : float
            On initial entry g is the derivative of the function at 0. On
            subsequent entries g is the derivative of the function at stp.
        task : bytes
            On initial entry task must be set to 'START'.

        On exit with convergence, a warning or an error, the
           variable task contains additional information.


        Returns
        -------
        stp, f, g, task: tuple

            stp : float
                the current estimate of a satisfactory step if task = 'FG'. If
                task = 'CONV' then stp satisfies the sufficient decrease and
                curvature condition.
            f : float
                the value of the function at stp.
            g : float
                the derivative of the function at stp.
            task : bytes
                On exit task indicates the required action:

               If task(1:2) == b'FG' then evaluate the function and
               derivative at stp and call dcsrch again.

               If task(1:4) == b'CONV' then the search is successful.

               If task(1:4) == b'WARN' then the subroutine is not able
               to satisfy the convergence conditions. The exit value of
               stp contains the best point found during the search.

              If task(1:5) == b'ERROR' then there is an error in the
              input arguments.
        g      ?Q?g?g      @Nr&   r"   s   ERROR: STP .LT. STPMINs   ERROR: STP .GT. STPMAXr   s   ERROR: INITIAL G .GE. ZEROs   ERROR: FTOL .LT. ZEROs   ERROR: GTOL .LT. ZEROs   ERROR: XTOL .LT. ZEROs   ERROR: STPMIN .LT. ZEROs   ERROR: STPMAX .LT. STPMINr'   F   r!   r%   r$   s)   WARNING: ROUNDING ERRORS PREVENT PROGRESSs   WARNING: XTOL TEST SATISFIEDs   WARNING: STP = STPMAXs   WARNING: STP = STPMINs   CONVERGENCEr(   r#   s   CONVignore)invalidover)r   r   r   r   r   bracktr   r   r   r   r   r   r   r   r	   r   r   r
   r   r   absr+   errstatedcstepminmaxclip)r   r5   fgr3   p5p66xtraplxtrapuftestfmfxmfymgmgxmgymtups                    r   r*   zDCSRCH._iterate  s   ^ 8xT[  0T[  0Avv4y1}}/y1}}/y1}}/{Q1{T[((3BQBx8##Aq$&  DKDJDJDJTZ/DJt{2DJ*r/DK DHjDGjDGDHjDGjDGDJv|+DJD1d?" 
S4:--:??qEzza1ffDJ ; 	@C4:--
1B1B?D; 	34:
2di$*6LLL2D$+!u**dj+D$+1u99TZ+D ::#a&&DI$;;;!D 8w$rr(g"5"51d?"
 :??qDG||E		S4:%%B'DHtz11C'DHtz11CTZB'DJ&C'DJ&C
 XH=== O OHHKJJ  LOH#sDHc3T[O O O O O O O O O O O O O O O$ DHtz11DGDHtz11DGDJ&DGDJ&DGG XH===  HGGHGGKJJ               0 	 ; 	248dh&''3+<<<htx$(':!;;*DKTX011DJ ; 	9TXtx00DJTXtx00DJJvtx88DJvtx88DJ gc4;44
 K	
""cTZ&7&7 '8 J+ty4:/EEE (C Aq$s&   AL22L69L6 AO44O8;O8)NNr   )__name__
__module____qualname____doc__r   r6   r*    r   r   r   r      s]        Z Zx  6B% B% B% B%Hf f f f fr   r   c           
      (	   t          j        |          }t          j        |          }||z  }||k    rd||z
  z  || z
  z  |z   |z   }t          t          |          t          |          t          |                    }|t          j        ||z  dz  ||z  ||z  z  z
            z  }|| k     r|dz  }||z
  |z   }||z
  |z   |z   }||z  }| ||| z
  z  z   }| |||z
  || z
  z  |z   z  dz  || z
  z  z   }t          || z
            t          || z
            k    r|}n|||z
  dz  z   }d}	n=|dk     rd||z
  z  || z
  z  |z   |z   }t          t          |          t          |          t          |                    }|t          j        ||z  dz  ||z  ||z  z  z
            z  }|| k    r|dz  }||z
  |z   }||z
  |z   |z   }||z  }||| |z
  z  z   }||||z
  z  | |z
  z  z   }t          ||z
            t          ||z
            k    r|}n|}d}	nTt          |          t          |          k     rd||z
  z  || z
  z  |z   |z   }t          t          |          t          |          t          |                    }|t          j        t          d||z  dz  ||z  ||z  z  z
                      z  }|| k    r| }||z
  |z   }|||z
  z   |z   }||z  }|dk     r|dk    r||| |z
  z  z   }n|| k    r|}n|
}||||z
  z  | |z
  z  z   }|	rft          ||z
            t          ||z
            k     r|}n|}|| k    rt          |d	||z
  z  z   |          }nt          |d	||z
  z  z   |          }nt          ||z
            t          ||z
            k    r|}n|}t          j        ||
|          }n|	rd||z
  z  ||z
  z  |z   |z   }t          t          |          t          |          t          |                    }|t          j        ||z  dz  ||z  ||z  z  z
            z  }||k    r| }||z
  |z   }||z
  |z   |z   }||z  }||||z
  z  z   }|}n|| k    r|}n|
}||k    r|}|}|}n|dk     r| }|}|}|} |}|}|}| |||||||	fS )
a  
    Subroutine dcstep

    This subroutine computes a safeguarded step for a search
    procedure and updates an interval that contains a step that
    satisfies a sufficient decrease and a curvature condition.

    The parameter stx contains the step with the least function
    value. If brackt is set to .true. then a minimizer has
    been bracketed in an interval with endpoints stx and sty.
    The parameter stp contains the current step.
    The subroutine assumes that if brackt is set to .true. then

        min(stx,sty) < stp < max(stx,sty),

    and that the derivative at stx is negative in the direction
    of the step.

    The subroutine statement is

      subroutine dcstep(stx,fx,dx,sty,fy,dy,stp,fp,dp,brackt,
                        stpmin,stpmax)

    where

    stx is a double precision variable.
        On entry stx is the best step obtained so far and is an
          endpoint of the interval that contains the minimizer.
        On exit stx is the updated best step.

    fx is a double precision variable.
        On entry fx is the function at stx.
        On exit fx is the function at stx.

    dx is a double precision variable.
        On entry dx is the derivative of the function at
          stx. The derivative must be negative in the direction of
          the step, that is, dx and stp - stx must have opposite
          signs.
        On exit dx is the derivative of the function at stx.

    sty is a double precision variable.
        On entry sty is the second endpoint of the interval that
          contains the minimizer.
        On exit sty is the updated endpoint of the interval that
          contains the minimizer.

    fy is a double precision variable.
        On entry fy is the function at sty.
        On exit fy is the function at sty.

    dy is a double precision variable.
        On entry dy is the derivative of the function at sty.
        On exit dy is the derivative of the function at the exit sty.

    stp is a double precision variable.
        On entry stp is the current step. If brackt is set to .true.
          then on input stp must be between stx and sty.
        On exit stp is a new trial step.

    fp is a double precision variable.
        On entry fp is the function at stp
        On exit fp is unchanged.

    dp is a double precision variable.
        On entry dp is the derivative of the function at stp.
        On exit dp is unchanged.

    brackt is an logical variable.
        On entry brackt specifies if a minimizer has been bracketed.
            Initially brackt must be set to .false.
        On exit brackt specifies if a minimizer has been bracketed.
            When a minimizer is bracketed brackt is set to .true.

    stpmin is a double precision variable.
        On entry stpmin is a lower bound for the step.
        On exit stpmin is unchanged.

    stpmax is a double precision variable.
        On entry stpmax is an upper bound for the step.
        On exit stpmax is unchanged.

    MINPACK-1 Project. June 1983
    Argonne National Laboratory.
    Jorge J. More' and David J. Thuente.

    MINPACK-2 Project. November 1993.
    Argonne National Laboratory and University of Minnesota.
    Brett M. Averick and Jorge J. More'.

    g      @r$   g       @Tr!      r   r8   )r+   signrB   r>   sqrtrA   rC   )r   r   dxr   r   dyr5   fpdpr=   r   r   sgn_dpsgn_dxsgndthetasgammapqrstpcstpqstpfs                           r   r@   r@     s   x WR[[FWR[[F F?D 
BwwrBw39-2R7E

CGGSWW--BGUQY1,Q26/BBCCC99RKERZ5 bjE!R'EQ#)_$rb2g#)4r9:cAcCiPPtcz??c$*oo--DD4$;#--D	
 R"Ws+b025E

CGGSWW--BGUQY1,Q26/BBCCC99RKERZ5 bjE!R'EQ#)_$bBGns33tcz??S__,,DDD	R3r77		 R"Ws+b025E

CGGSWW-- BGCEAI!#3rAv"q&6I#IJJKKK99FERZ5 b2g%'Eq55UaZZcCi(DD3YYDDDbBGns33 	1 4#:TCZ00Syy3s!33T::3s!33T::
 4#:TCZ007400DD  	27OsSy1B6;ECJJBR11Aq 0BFrAv3F FGGGESyyu$A"*%+AAAcCi(DDD3YYDDD 
Bww!88CBB CBRS&00r   )numpyr+   r   r@   rV   r   r   <module>rm      se       	b b b b b b b bJb1 b1 b1 b1 b1r   