ó
    Eñi¯:  ã                   óŽ   • S SK r S SKrSSKJrJr  SSKJrJrJ	r	  S SK
Js  Jr  SrSrSrSrS	rS rSrSS
 jr SS jrS rS rS rg)é    Né   )Ú_RichResultÚ_call_callback_maybe_halt)Úarray_namespaceÚxp_sizeÚxp_result_typeéÿÿÿÿéþÿÿÿéýÿÿÿéüÿÿÿéûÿÿÿc           
      óF  ^• [        U5      nUc  [        U6 OUn[        USUS.6nUR                  " / UQUQ76 nUSU X†S p!U V	s/ s H  o•R	                  X—S9PM     nn	U V	s/ s H  o•R	                  U " U	/UQ76 5      PM     n
n	US   R
                  nU
S   R
                  mU(       aa  X°S.U4S jjn [        R                  " TU5      nU V	s/ s H  o•R                  X›5      PM     nn	U Vs/ s H  oÅR                  XË5      PM     nnSnUb  S	UR                  5        3nU
 Vs/ s H  oîR
                  U:H  PM     nn[        U5      (       d  [        U5      eUR                  " U
 Vs/ s H  oîR                  PM     snU/-   6 nU(       d"  UR                  US
5      (       d  [        S5      eU V	s/ s H  o•R	                  U	USS9PM     nn	U
 Vs/ s H  oåR	                  UUSS9PM     n
nU V	s/ s H  o•R                  U	S5      PM     nn	U
 Vs/ s H  oåR                  US5      PM     n
nU Vs/ s H"  oÅR                  UR	                  USS9S5      PM$     nnXX¢UUU4$ s  sn	f s  sn	f s  sn	f s  snf s  snf s  snf s  sn	f s  snf s  sn	f s  snf s  snf )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`.
NT)Úforce_floatingÚxp©Údtyper   )ÚshapeÚfuncc                óT   >• S[        T5      [        U5      -
  -  nU" X   /UQ70 UD6$ )N)r   )Úlen)Úxr   r   ÚargsÚkwargsÚiÚfshapes         €Úe/home/mande/repo/quber/.venv/lib/python3.13/site-packages/scipy/_lib/_elementwise_iterative_method.pyr   Ú_initialize.<locals>.func`   s1   ø€ Ø”c˜&“k¤C¨£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   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   Ú_initializer8      sŒ  ø€ ôb 
ˆR‹€BØ!#¡Œ˜"Ñ	°€Bô ˜"¨T°bÒ
9€CØ
×
Ò
Ð
)˜rÐ
) DÒ
)€CØ�3�Bˆx˜˜S˜ˆÙ,.Ó	/ªB q�*‰*�Qˆ*Ó
"©B€BÐ	/Ù.0Ó	1ªb¨�*‰*‘T˜!�^˜d’^Ö
$©b€BÐ	1Øˆq‰E�K‰K€EØ�‰U�[‰[€Fæà!&÷ 	/ð 	/ô ×#Ò# F¨EÓ2ˆÙ13Ó4²¨A�o‰o˜aÖ'±ˆÐ4Ù7;Ó<²t°—‘ Ö+±tˆÐ<ðD€GàÑ!Ø1°'·-±-³/Ð1BÐCˆÙ.0Ó1ªb¨—G‘G˜uÔ$©b€LÐ1Üˆ|×ÑÜ˜Ó!Ð!ð
 �>Š>©bÓ1ªb¨ŸWœW©bÑ1°S°EÑ9Ð;€DÞ˜bŸj™j¨¨×?Ñ?ÜÐNÓOÐOÙ8:Ó	;º°1�*‰*�Q˜d¨ˆ*Ó
.¹€BÐ	;Ù8:Ó	;º°1�*‰*�Q˜d¨ˆ*Ó
.¹€BÐ	;ñ )+Ó	+ª 1�*‰*�Q˜Ö
©€BÐ	+Ù(*Ó	+ª 1�*‰*�Q˜Ö
©€BÐ	+ÙEIÓJÂT¸c�J‰J�r—z‘z #¨D�zÐ1°5Ö9ÁT€DÐJØ�R˜u d¨BÐ.Ð.ùòI 
0ùÚ	1ùò 5ùÚ<ùò 2ùò 2ùò 
<ùÚ	;ùò 
,ùÚ	+ùÚJsB   ÁI,Á$!I1ÃI6Ã1I;Ä)J Å.JÆ8J
ÇJÇ8JÈJÈ:)Jc           
      ó`  • Uc  [        S5      eSn[        R                  " U5      nUR                  U5      nU VVs0 s H  u  nnUUR	                  UUS9_M     nnnUR	                  UUR
                  S9US'   UR                  UUR                  [        5      UR                  S9US'   UR	                  UUR                  S9US'   UR	                  UUR                  S9US'   [        U5      nXPl        [        U UUUXžU5      nUb$  [        U UUUUX¾U5      n[        UU5      (       a  S	nU R                  U:  Ga  [!        U5      (       Ga  U(       Gdù  U(       Gañ  U" U 5      nU R                  (       aŽ  U R                  S
   R"                  UR"                  :w  ag  / nU R                   HO  nUR"                  UR"                  -
  nUR$                  SU-  -   nUR'                  UR)                  UU5      5        MQ     XPl        UR$                  nU(       a  UR)                  UUS-   5      nU" U/U R                  Q76 nUR                  UUS9nU(       a$  UR)                  UU5      nUR)                  UU5      nU =R*                  UR"                  S:X  a  SOUR$                  S   -  sl        U" UUU 5        U =R                  S-  sl        [        U UUUXžU5      nUb%  [        U UUUUX¾U5      n[        UU5      (       a  S	nOI[!        U5      S
:X  a  O9U
" U 5        U R                  U:  a!  [!        U5      (       a  U(       d
  U(       a  GMñ  [,        R.                  " U R0                  5      SS R3                  U(       a  [4        O[6        5      U l        [        U UUUUX¾U5      $ s  snnf )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.

NzMust provide xp.Fr   ÚsuccessÚstatusÚnitÚnfevTr   )r   r    r   r	   )ÚNotImplementedErrorÚmathÚprodÚarangeÚzerosÚboolÚfullr"   Ú_EINPROGRESSÚint32r   r   Ú_check_terminationÚ_prepare_resultr   r<   r   Úndimr   Úappendr+   r=   ÚxpxÚatr;   Ú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   r3   Ú
n_new_dimsÚ	new_shapeÚx_shaper5   s                                r   Ú_looprc   €   sC  € ðR 
�zÜ!Ð"4Ó5Ð5à€Lô —’˜5Ó!€JØ�Y‰Y�zÓ"€FÙAOÔPÂ¹¸¸A��2—8‘8˜J¨e�8Ð4Ò4Á€HÑPØŸ(™( :°R·W±W˜(Ð=€HˆYÑØŸ™ ¨R¯Z©Z¼Ó-EÈRÏXÉX˜ÐV€HˆXÑØ—h‘h˜z°·±�hÐ:€HˆU�OØ—x‘x 
°"·(±(�xÐ;€HˆVÑÜ
�hÓ
€CØ„Iä  c¨>¸6Ø 1À2óG€Fð ÑÜ˜t S¨.¸&À%Ø/ÀóEˆä$ X¨t×4Ñ4ØˆLà
�(‰(�WÔ
¤¨§¢¿Ï*Ù˜$Óˆà�9�9˜Ÿ™ 1™×*Ñ*¨a¯f©fÓ4ð ˆDØ—y”y�ØŸV™V c§h¡hÑ.�
ØŸI™I¨¨Z©Ñ7�	Ø—‘˜BŸJ™J s¨IÓ6Ö7ñ !ð ŒIà—'‘'ˆÞØ—
‘
˜1˜u u™}Ó.ˆAÙ�Ð�T—Y‘YÒˆØ�J‰J�q ˆJÐ&ˆÞØ—
‘
˜1˜gÓ&ˆAØ—
‘
˜1˜gÓ&ˆAØ�	Š	˜!Ÿ&™& A›+‘Q¨1¯7©7°2©;Ñ6�	á�q˜!˜TÔ"à�Š�A‰�Ü# D¨#¨~¸vØ$5ÀróKˆð ÑÜ" 4¨¨n¸fÀeØ#3ÀRóIˆDä(¨°4×8Ñ8Ø#�ØÜ�6‹?˜aÓØá˜tÔ$ðO �(‰(�WÓ
¤¨§¡¾Ï*É*ôR —&’&˜Ÿ™Ó%¡aÐ(×,Ñ,¾<­ZÌYÓW€D„KÜ˜4  n°f¸eØ+¸RóAð Aùów Qs   ½N*c           	      óV  • U" U 5      nUR                  U5      (       a…  [        XX#XuU5        U(       a  Xs   nU) nX8   nU(       d^  U R                  5        H&  u  pšU	S;   a  M  [        U
SS5      S:”  a  X¨   OU
X	'   M(     U R                   Vs/ s H  o»U   PM	     snU l        U$ s  snf )N>   Únr   rI   r   )ÚanyÚ_update_activeÚitemsÚgetattrr   )rP   r^   rX   r[   rU   r.   r   ÚstopÚproceedÚkeyÚvalr3   s               r   rG   rG     s§   € ñ
 ˜TÓ"€Dà	‡v�vˆd‡|�|ô 	�t .¸$ÐPRÔSæØ‘<ˆDà�%ˆØ‘ˆæà ŸJ™JžL‘�à˜-Ó'ÙÜ,3°C¸ÀÓ,CÀaÓ,G˜CšLÈS�“	ñ	 )ð
 26·²Ó;²¨#˜Wœ±Ñ;ˆDŒIà€Mùò <s   ÂB&c                 ó4  • U VVs0 s H
  u  pxXpU   _M     n	nnU R                   S:H  U	S'   UGb  U(       aš  UR                  U5      n
[        R                  " U
5      U   R	                  S5      n
X¤-  n
U	R                  5        HH  u  p¼[        USS5      S:”  a  XÊ   OUn[        R                  " X   5      U
   R	                  U5      X'   MJ     g X4   n
U	R                  5        HH  u  p¼[        USS5      S:”  a  XÄ   OUn[        R                  " X   5      U
   R	                  U5      X'   MJ     g U	R                  5        HM  u  p¼U(       a  [        USS5      S:”  a  XÃ   n[        R                  " X   5      U   R	                  U5      X'   MO     g s  snnf )Nr   r:   TrI   )r;   Ú
zeros_likerK   rL   rM   rh   ri   )rP   r^   rX   r[   Úmaskr.   r   Úkey1Úkey2Úupdate_dictÚactive_maskrl   rm   s                r   rg   rg   .  su  € ñ
 7EÔE²n©
¨�4˜d™Ò#±n€KÑEØ!Ÿ[™[¨AÑ-€K�	ÑàÒÞØŸ-™-¨Ó-ˆKÜŸ&š& Ó-¨fÑ5×9Ñ9¸$Ó?ˆKØ%Ñ,ˆKØ'×-Ñ-Ö/‘�Ü*1°#°v¸qÓ*AÀAÓ*E�cÒ&È3�ÜŸ6š6 #¡(Ó+¨KÑ8×<Ñ<¸SÓA�“ò 0ð !™,ˆKØ'×-Ñ-Ö/‘�Ü#*¨3°¸Ó#:¸QÓ#>�c’iÀC�ÜŸ6š6 #¡(Ó+¨KÑ8×<Ñ<¸SÓA�“ò 0ð $×)Ñ)Ö+‰HˆCÞ¤'¨#¨v°qÓ"9¸AÓ"=Ø‘k�Ü—v’v˜c™hÓ'¨Ñ/×3Ñ3°CÓ8ˆC‹Hò ,ùó# Fs   †Fc           	      ó2  • UR                  5       n[        XX#S Xg5        U" X5      nUR                  5        H/  u  p‰UR                  X”5      n
U
R                  S:X  a  U
S   OU
X'   M1     S/U VVs/ s H  u  p¼UPM	     snn-   US'   [        S0 UD6$ s  snnf )Nr   © r:   Ú_order_keys)r   rg   rh   r+   rI   r   )rP   r^   rX   r[   r   rW   r.   r   rl   rm   r_   r   r\   s                r   rH   rH   J  s–   € ð
 �(‰(‹*€CÜ�4˜n°d¸NÔOá˜SÓ(€Eà—I‘I–K‰ˆà�z‰z˜#Ó%ˆØ#Ÿy™y¨A›~�4˜’8°4ˆ‹ñ  ð
 $˜±nÔ'E²n©d¨a«±nÒ'EÑE€CˆÑÜÑ˜ÑÐùó (Fs   Á1B)FNN)F)r?   Únumpyr#   Ú_utilr   r   Ú
_array_apir   r   r   Úscipy._lib.array_api_extraÚ_libÚarray_api_extrarK   Ú	_ESIGNERRrO   Ú
_EVALUEERRrN   Ú
_EINPUTERRÚ_ECONVERGEDrE   r8   rc   rG   rg   rH   rv   r   r   Ú<module>r‚      sd   ðó Û ß 9ß @Ñ @ß (Ð (à€	Ø€	Ø€
Ø€
Ø€
Ø€Ø€ô`/ðJ @EôMAò`ò<9ó8r   