+
    ,i:                         ^ RI t ^ RIt^RIHtHt ^RIHtHtH	t	 ^ RI
Hu Ht R	tR
tRtRtRt^ t^tRR ltRR ltR tR tR tR# )    N)_RichResult_call_callback_maybe_halt)array_namespacexp_sizexp_result_typec           
     z  a \        V4      pVf
   \        V!  MTp\        VRRRV/ pVP                  ! . VOVO5!  pVRV WR r!V U	u. uF  qP	                  WR7      NK  	  pp	V U	u. uF  qP	                  V ! V	.VO5!  4      NK  	  p
p	V^ ,          P
                  pV
^ ,          P
                  oV'       db   RVRV /V3R llp \        P                  ! SV4      pV U	u. uF  qP                  W4      NK  	  pp	V Uu. uF  qP                  W4      NK  	  ppR	pVe   R
VP                  4        2pV
 Uu. uF  qP
                  V8H  NK  	  pp\        V4      '       g   \        V4      hVP                  ! V
 Uu. uF  qP                  NK  	  upV.,           !  pV'       g$   VP                  VR4      '       g   \        R4      hV U	u. uF  qP	                  V	VRR7      NK  	  pp	V
 Uu. uF  qP	                  VVRR7      NK  	  p
pV U	u. uF  qP                  V	R4      NK  	  pp	V
 Uu. uF  qP                  VR4      NK  	  p
pV Uu. uF%  qP                  VP	                  VRR7      R4      NK'  	  ppWWVVV3# u up	i u up	i u up	i u upi u upi u upi u up	i u upi u up	i u upi u upi )av  Initialize abscissa, function, and args arrays for elementwise function

Parameters
----------
func : callable
    An elementwise function with signature

        func(x: ndarray, *args) -> ndarray

    where each element of ``x`` is a finite real and ``args`` is a tuple,
    which may contain an arbitrary number of arrays that are broadcastable
    with ``x``.
xs : tuple of arrays
    Finite real abscissa arrays. Must be broadcastable.
args : tuple, optional
    Additional positional arguments to be passed to `func`.
preserve_shape : bool, default:False
    When ``preserve_shape=False`` (default), `func` may be passed
    arguments of any shape; `_scalar_optimization_loop` is permitted
    to reshape and compress arguments at will. When
    ``preserve_shape=False``, arguments passed to `func` must have shape
    `shape` or ``shape + (n,)``, where ``n`` is any integer.
xp : namespace
    Namespace of array arguments in `xs`.

Returns
-------
xs, fs, args : tuple of arrays
    Broadcasted, writeable, 1D abscissa and function value arrays (or
    NumPy floats, if appropriate). The dtypes of the `xs` and `fs` are
    `xfat`; the dtype of the `args` are unchanged.
shape : tuple of ints
    Original shape of broadcasted arrays.
xfat : NumPy dtype
    Result dtype of abscissae, function values, and args determined using
    `np.result_type`, except integer types are promoted to `np.float64`.

Raises
------
ValueError
    If the result dtype is not that of a real scalar

Notes
-----
Useful for initializing the input of SciPy functions that accept
an elementwise callable, abscissae, and arguments; e.g.
`scipy.optimize._chandrupatla`.
Nforce_floatingTxpdtypeshapefuncc                l   < R\        S4      \        V4      ,
          ,          pV! W,          .VO5/ VB # )r   )r   )len)xr   r   argskwargsifshapes   &$$*, J/usr/lib/python3/dist-packages/scipy/_lib/_elementwise_iterative_method.pyr   _initialize.<locals>.func`   s1    c&kCJ./A.t.v..    zpThe shape of the array returned by `func` must be the same as the broadcasted shape of `x` and all other `args`.zWhen `preserve_shape=False`, zreal floatingz3Abscissae and function output must be real numbers.)r   copy)r   )r   r   r   broadcast_arraysasarrayr   npbroadcast_shapesbroadcast_tolowerall
ValueErrorresult_typer   isdtypereshape)r   xsr   
complex_okpreserve_shaper
   nxxatxasr   fsr   argmessagefshapes_equalxfatr   s   &&&&&&           @r   _initializer3      s   b 
RB!#"	B "
9T
9b
9C



)r
)D
)C3BxS,.	/Bq**Q*
"BB	/.0	1b**T!^d^
$bB	1qEKKEU[[F	/ 	/T 	/ ##FE2134Aooa'47;<t+t<DG!1'--/1BC.01bGGu$bL1|!!
 >>b1bWWb1SE9;Dbjj??NOO8:	;1**Qd*
.B	;8:	;1**Qd*
.B	; )+	+1**Q
B	+(*	+1**Q
B	+EIJTcJJrzz#Dz159TDJRudB..I 
0	1 5< 2 2 
<	; 
,	+JsB   
J*!J"JJ9J>JJ$0J)J.2J3+J8c           
        Vf   \        R4      hRp\        P                  ! V4      pVP                  V4      pV UUu/ uF  w  ppVVP	                  VVR7      bK  	  pppVP	                  VVP
                  R7      VR&   VP                  VVP                  \        4      VP                  R7      VR&   VP	                  VVP                  R7      VR&   VP	                  VVP                  R7      VR&   \        V4      pWPn        \        V VVVWV4      pVe&   \        V VVVVWV4      p\        VV4      '       d   RpV P                  V8  Ed   \!        V4      '       Ed   V'       Eg   V'       Ed   V! V 4      pV P                  '       d   V P                  ^ ,          P"                  VP"                  8w  dt   . pV P                   F[  pVP"                  VP"                  ,
          pVP$                  R
V,          ,           pVP'                  VP)                  VV4      4       K]  	  WPn        VP$                  pV'       d   VP)                  VVR,           4      pV! V.V P                  O5!  pVP                  VVR7      pV'       d%   VP)                  VV4      pVP)                  VV4      pT ;P*                  VP"                  ^8X  d   ^MVP$                  R,          ,          un        V! VVV 4       V ;P                  ^,          un        \        V VVVWV4      pVe'   \        V VVVVWV4      p\        VV4      '       d   RpM\!        V4      ^ 8X  d   MV
! V 4       EK%  \,        P.                  ! V P0                  4      R	,          P3                  V'       d   \4        M\6        4      V n        \        V VVVVWV4      # u uppi )a  Main loop of a vectorized scalar optimization algorithm

Parameters
----------
work : _RichResult
    All variables that need to be retained between iterations. Must
    contain attributes `nit`, `nfev`, and `success`. All arrays are
    subject to being "compressed" if `preserve_shape is False`; nest
    arrays that should not be compressed inside another object (e.g.
    `dict` or `_RichResult`).
callback : callable
    User-specified callback function
shape : tuple of ints
    The shape of all output arrays
maxiter :
    Maximum number of iterations of the algorithm
func : callable
    The user-specified callable that is being optimized or solved
args : tuple
    Additional positional arguments to be passed to `func`.
dtype : NumPy dtype
    The common dtype of all abscissae and function values
pre_func_eval : callable
    A function that accepts `work` and returns `x`, the active elements
    of `x` at which `func` will be evaluated. May modify attributes
    of `work` with any algorithmic steps that need to happen
     at the beginning of an iteration, before `func` is evaluated,
post_func_eval : callable
    A function that accepts `x`, `func(x)`, and `work`. May modify
    attributes of `work` with any algorithmic steps that need to happen
     in the middle of an iteration, after `func` is evaluated but before
     the termination check.
check_termination : callable
    A function that accepts `work` and returns `stop`, a boolean array
    indicating which of the active elements have met a termination
    condition.
post_termination_check : callable
    A function that accepts `work`. May modify `work` with any algorithmic
    steps that need to happen after the termination check and before the
    end of the iteration.
customize_result : callable
    A function that accepts `res` and `shape` and returns `shape`. May
    modify `res` (in-place) according to preferences (e.g. rearrange
    elements between attributes) and modify `shape` if needed.
res_work_pairs : list of (str, str)
    Identifies correspondence between attributes of `res` and attributes
    of `work`; i.e., attributes of active elements of `work` will be
    copied to the appropriate indices of `res` when appropriate. The order
    determines the order in which _RichResult attributes will be
    pretty-printed.
preserve_shape : bool, default: False
    Whether to compress the attributes of `work` (to avoid unnecessary
    computation on elements that have already converged).

Returns
-------
res : _RichResult
    The final result object

Notes
-----
Besides providing structure, this framework provides several important
services for a vectorized optimization algorithm.

- It handles common tasks involving iteration count, function evaluation
  count, a user-specified callback, and associated termination conditions.
- It compresses the attributes of `work` to eliminate unnecessary
  computation on elements that have already converged.

zMust provide xp.Fr   successstatusnitnfevT:NNN)   r   r   )NotImplementedErrormathprodarangezerosboolfullr   _EINPROGRESSint32r   r   _check_termination_prepare_resultr   r7   r   ndimr   appendr&   r8   xpxatr6   set
_ECALLBACK	_ECONVERR)workcallbackr   maxiterr   r   r   pre_func_evalpost_func_evalcheck_terminationpost_termination_checkcustomize_resultres_work_pairsr
   r)   cb_terminate
n_elementsactiver   jres_dictrestempr   r.   
n_new_dims	new_shapex_shaper0   s   &&&&&&&&&&&&&&&              r   _loopr_      s)   R 
z!"455L 5!JYYz"FAOPA288Je844HP((:RWW(=HYRZZ-ERXXVHXhhzh:HUOxx
"((x;HV
h
CIc>6 12GF tS.&%/E$Xt44L
((W
**$9991**aff4 DyyVVchh.
IIZ7	BJJsI67 ! I''

1uu}.ATYYJJqJ&

1g&A

1g&A		!&&A+Q1772;6	q!T"A#D#~v$5rK "4nfe#3RID(488#6?at$&&%a(,,<ZYWDK4nfe+RA Aw Qs    Oc           	      ~   V! V 4      pVP                  V4      '       d   \        WW#WuV4       V'       d	   Ws,          pV( pW8,          pV'       gh   V P                  4        F,  w  rV	R9   d   K  \        V
R^ 4      ^ 8  d	   W,          MT
W	&   K.  	  V P                   Uu. uF  qV,          NK  	  upV n        V# u upi )r   rE   >   nr   )any_update_activeitemsgetattrr   )rL   rZ   rT   rW   rQ   r)   r
   stopproceedkeyvalr.   s   &&&&&&&     r   rC   rC     s    
 T"D	vvd|| 	t.$PRS<D% JJL-',3C,Ca,GCLS		 )
 26;#W;DIM <s   B:c                    V UUu/ uF  w  rxWpV,          bK  	  p	ppV P                   ^ 8H  V	R&   VEe,   V'       d   VP                  V4      p
\        P                  ! V
4      V,          P	                  R4      p
W,          p
V	P                  4        FU  w  r\        VR^ 4      ^ 8  d	   W,          MTp\        P                  ! W,          4      V
,          P	                  V4      W&   KW  	  R# W4,          p
V	P                  4        FU  w  r\        VR^ 4      ^ 8  d	   W,          MTp\        P                  ! W,          4      V
,          P	                  V4      W&   KW  	  R# V	P                  4        F[  w  rV'       d   \        VR^ 4      ^ 8  d	   W,          p\        P                  ! W,          4      V,          P	                  V4      W&   K]  	  R# u uppi )r   r5   NTrE   )r6   
zeros_likerG   rH   rI   rd   re   )rL   rZ   rT   rW   maskr)   r
   key1key2update_dictactive_maskrh   ri   s   &&&&&&&      r   rc   rc   .  su   
 7EEn
4d#nKE![[A-K	---K&&-f599$?K%,K'--/*1#vq*AA*Ec&366#(+K8<<SA 0 !,K'--/#*3#:Q#>ciC66#(+K8<<SA 0 $))+HC'#vq"9A"=kvvch'/33C8CH ,# Fs   Gc           	      B   VP                  4       p\        WW#R Wg4       V! W4      pVP                  4        F4  w  rVP                  W4      p
V
P                  ^ 8X  d
   V
R,          MT
W&   K6  	  R.V UUu. uF  w  rVNK	  	  upp,           VR&   \        R/ VB # u uppi )Nr5   _order_keys )r   rc   rd   r&   rE   r   )rL   rZ   rT   rW   r   rS   r)   r
   rh   ri   r[   r   rX   s   &&&&&&&&     r   rD   rD   J  s    
 ((*C4ndNOS(EIIKzz#%#yyA~484  
 $n'Endan'EEC (Fs   6Br   )FNN)F)r;   numpyr   _utilr   r   
_array_apir   r   r   scipy._lib.array_api_extra_libarray_api_extrarG   	_ESIGNERRrK   
_EVALUEERRrJ   
_EINPUTERR_ECONVERGEDrA   r3   r_   rC   rc   rD   rs   r   r   <module>r      s]      9 @ @ ( (		


`/FMA`<98r   