Ë
    âQ(h­;  ã                   ót   — d dl Z d dlZddlmZmZ ddlmZmZ dZ	dZ
dZdZd	Zd ZdZdd
„Z	 dd„Zd„ Zd„ Zd„ Zy)é    Né   )Ú_RichResultÚ_call_callback_maybe_halt)Úarray_namespaceÚxp_sizeéÿÿÿÿéþÿÿÿéýÿÿÿéüÿÿÿéûÿÿÿc           	      ó®  ‡— t        |«      }|€t        |Ž n|} |j                  g |¢|¢­Ž } |j                  |D �cg c]  }|j                  ‘Œ c}Ž }	|j                  |	d«      r|j                  d«      j                  n|	}	|d| ||d }}|D �
cg c]  }
|j                  |
|	¬«      ‘Œ }}
|D �
cg c]  }
|j                   | |
g|¢­Ž «      ‘Œ }}
|d   j                  }|d   j                  Š|r]|| dœˆfd„
} t        j                  ‰|«      }|D �
cg c]  }
|j                  |
|«      ‘Œ }}
|D �cg c]  }|j                  ||«      ‘Œ }}d}|�d	|j                  «       › �}|D �cg c]  }|j                  |k(  ‘Œ }}t        |«      st        |«      ‚ |j                  |D �cg c]  }|j                  ‘Œ c}|	gz   Ž }|s|j                  |d
«      st        d«      ‚|D �
cg c]  }
|j                  |
|d¬«      ‘Œ }}
|D �cg c]  }|j                  ||d¬«      ‘Œ }}|D �
cg c]  }
|j                  |
d«      ‘Œ }}
|D �cg c]  }|j                  |d«      ‘Œ }}|D �cg c]%  }|j                  |j                  |d¬«      d«      ‘Œ' }}| ||||||fS c c}w c c}
w c c}
w c c}
w c c}w c c}w c c}w c c}
w c c}w c c}
w c c}w c c}w )a  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Úintegralg      ð?©Údtyper   )ÚshapeÚfuncc                óV   •— dt        ‰«      t        |«      z
  z  } || |   g|¢­i |¤ŽS )N)r   )Úlen)Úxr   r   ÚargsÚkwargsÚiÚfshapes         €úf/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/scipy/_lib/_elementwise_iterative_method.pyr   z_initialize.<locals>.func`   s3   ø€ Ø”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.T)r   Úcopy©r   )r   )r   r   Úbroadcast_arraysÚresult_typer   ÚisdtypeÚasarrayr   ÚnpÚbroadcast_shapesÚbroadcast_toÚlowerÚallÚ
ValueErrorÚreshape)r   Úxsr   Ú
complex_okÚpreserve_shapeÚxpÚnxÚxasÚxaÚxatr   Úfsr   ÚargÚmessageÚfÚshapes_equalÚxfatr   s                     @r   Ú_initializer7      sÕ  ø€ ôb 
ˆR‹€BØ!# Œ˜"Ñ	°€Bð ˆ"×
Ñ
Ð
)˜rÐ
) DÒ
)€CØ
ˆ"�.‰.¨cÖ2¨˜2Ÿ8›8Ò2Ð
3€CØ"$§*¡*¨S°*Ô"=ˆ"�*‰*�R‹.×
Ò
À3€CØ�3�Bˆx˜˜R˜S˜ˆ€BØ,.Ö	/ qˆ"�*‰*�Q˜cˆ*Õ
"Ð	/€BÐ	/Ø.0Ö	1¨ˆ"�*‰*‘T˜!�^˜d’^Õ
$Ð	1€BÐ	1Øˆq‰E�K‰K€EØ�‰U�[‰[€Fáà!&¨Tö 	/ô ×#Ñ# F¨EÓ2ˆØ13Ö4¨Aˆb�o‰o˜a Õ'Ð4ˆÐ4Ø7;Ö<°�—‘  UÕ+Ð<ˆÐ<ðD€GàÐ!Ø1°'·-±-³/Ð1BÐCˆØ.0Ö1¨�A—G‘G˜uÓ$Ð1€LÐ1Üˆ|ÔÜ˜Ó!Ð!ð
 ˆ2�>‰>¨bÖ1¨˜QŸW›WÒ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¸cˆB�J‰J�r—z‘z #¨D�zÓ1°5Õ9ÐJ€DÐJØ��R˜˜u d¨BÐ.Ð.ùòO 3ùò 
0ùÚ	1ùò 5ùÚ<ùò 2ùò 2ùò 
<ùÚ	;ùò 
,ùÚ	+ùÚJsG   ½JÂJ Â1J%ÄJ*Ä4J/Å*J4Æ(J9Ç&J>ÈKÈ(KÉKÉ&*Kc           
      ó¬  — |€t        d«      ‚d}t        j                  |«      }|j                  |«      }|D ��ci c]  \  }}||j	                  ||¬«      “Œ }}}|j	                  ||j
                  ¬«      |d<   |j                  ||j                  t        «      |j                  ¬«      |d<   |j	                  ||j                  ¬«      |d<   |j	                  ||j                  ¬«      |d<   t        |«      }|| _        t        | ||||	||«      }|� t        | |||||||«      }t        ||«      rd	}| j                  |k  �rÞt!        |«      �rÒ|�sÏ|�rÌ || «      }| j                  rŒ| j                  d
   j"                  |j"                  k7  rfg }| j                  D ]N  }|j"                  |j"                  z
  }|j$                  d|z  z   }|j'                  |j)                  ||«      «       ŒP || _        |j$                  }|r|j)                  ||dz   «      } ||g| j                  ¢­Ž }|j                  ||¬«      }|r$|j)                  ||«      }|j)                  ||«      }| xj*                  |j"                  dk(  rdn|j$                  d   z  c_         |||| «       | xj                  dz  c_        t        | ||||	||«      }|�!t        | |||||||«      }t        ||«      rd	}n7t!        |«      d
k(  rn( |
| «       | j                  |k  rt!        |«      r|s|r�ŒÌ|rt,        nt.        | j0                  dd t        | |||||||«      S c c}}w )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<   Ú
_ECALLBACKÚ	_ECONVERRr:   )Ú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   r2   Ú
n_new_dimsÚ	new_shapeÚx_shaper4   s                                r   Ú_loopr_   €   s2  € ðR 
€zÜ!Ð"4Ó5Ð5à€Lô —‘˜5Ó!€JØ�Y‰Y�zÓ"€FØAO×P¹¸¸A��2—8‘8˜J¨e�8Ó4Ñ4ÐP€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Ø€D„Iä  c¨>¸6Ø 1°>À2óG€Fð ÐÜ˜t S¨.¸&À%Ø/°ÀóEˆä$ X¨tÔ4ØˆLà
�(‰(�WÓ
¤¨¥ºÊ*Ù˜$Óˆà�9Š9˜Ÿ™ 1™×*Ñ*¨a¯f©fÒ4ð ˆDØ—y‘yò 8�ØŸV™V c§h¡hÑ.�
ØŸI™I¨¨Z©Ñ7�	Ø—‘˜BŸJ™J s¨IÓ6Õ7ð8ð ˆDŒ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Ø#�ØÜ�6‹?˜aÒØá˜tÔ$ðO �(‰(�WÒ
¤¨¤¹Ë*ñR $0•Z´Y€D‡K�K‘€NÜ˜4  n°f¸eØ+¨^¸RóAð Aùów Qs   »Mc           	      óV  —  || «      }|j                  |«      rkt        | ||||||«       |r||   }| }||   }|sI| j                  «       D ]  \  }	}
|	dk(  rŒ	 |
|   | |	<   Œ | j                  D �cg c]  }||   ‘Œ	 c}| _        |S # t        t        t
        f$ r |
| |	<   Y ŒVw xY wc c}w )Nr   )ÚanyÚ_update_activeÚitemsÚ
IndexErrorÚ	TypeErrorÚKeyErrorr   )rL   rZ   rT   rW   rQ   r+   r,   ÚstopÚproceedÚkeyÚvalr2   s               r   rF   rF     sÊ   € ñ
 ˜TÓ"€Dà	‡v�vˆd„|ô 	�t˜S .°&¸$ÀÐPRÔSáØ˜‘<ˆDà�%ˆØ˜‘ˆáà ŸJ™J›Lò $‘��Sð ˜&’=Øð$Ø # G¡�D˜’Ið$ð 26·±Ö;¨#˜˜W›Ò;ˆDŒIà€Møô	 #¤I¬xÐ8ò $Ø #�D˜“Ið$üâ;s   ÁBÁ1B&ÂB#Â"B#c                 óL  — |D ��ci c]  \  }}|| |   “Œ }	}}| j                   dk(  |	d<   |�l|r@|j                  |«      }
d|
|<   |
|z  }
|	j                  «       D ]  \  }}	 ||
   ||   |
<   Œ y ||   }
|	j                  «       D ]  \  }}	 ||   ||   |
<   Œ y |	j                  «       D ]  \  }}|r	 ||   }|||   |<   Œ y c c}}w # t        t        t
        f$ r |||   |
<   Y ŒŒw xY w# t        t        t
        f$ r |||   |
<   Y Œ„w xY w# t        t        t
        f$ r Y Œkw xY w)Nr   r9   r   )r:   Ú
zeros_likerc   rd   re   rf   )rL   rZ   rT   rW   Úmaskr+   r,   Úkey1Úkey2Úupdate_dictÚactive_maskri   rj   s                r   rb   rb   2  s  € ð
 7E×E©
¨¨d�4˜˜d™Ñ#ÐE€KÑEØ!Ÿ[™[¨AÑ-€K�	ÑàÐÙØŸ-™-¨Ó-ˆKØ"#ˆK˜ÑØ%¨Ñ,ˆKØ'×-Ñ-Ó/ò 0‘��Sð0Ø,/°Ñ,<�C˜‘H˜[Ò)ñ0ð ! ™,ˆKØ'×-Ñ-Ó/ò 0‘��Sð0Ø,/°©I�C˜‘H˜[Ò)ñ0ð $×)Ñ)Ó+ò 	#‰HˆC�ÙðØ˜f™+�Cð  #ˆC�‰H�VÒñ	#ùó+ Føô #¤I¬xÐ8ò 0Ø,/�C˜‘H˜[Ó)ð0ûô #¤I¬xÐ8ò 0Ø,/�C˜‘H˜[Ó)ð0ûô #¤I¬xÐ8ò Ùðús;   †CÁ!CÂC*Â2DÃC'Ã&C'Ã*D	ÄD	ÄD#Ä"D#c           	      ó6  — |j                  «       }t        | |||d ||«        |||«      }|j                  «       D ]0  \  }}	|j                  |	|«      }
|
j                  dk(  r|
d   n|
||<   Œ2 dg|D ��cg c]  \  }}|‘Œ	 c}}z   |d<   t        di |¤ŽS c c}}w )Nr   © r9   Ú_order_keys)r   rb   rc   r(   rH   r   )rL   rZ   rT   rW   r   rS   r+   r,   ri   rj   r[   r   rX   s                r   rG   rG   U  s§   € ð
 �(‰(‹*€CÜ�4˜˜n¨f°d¸NÈBÔOá˜S %Ó(€Eà—I‘I“Kò 8‰ˆˆSà�z‰z˜#˜uÓ%ˆØ#Ÿy™y¨Aš~�4˜’8°4ˆˆCŠð8ð
 $˜°n×'E©d¨a°ªÓ'EÑE€CˆÑÜÑ˜ÑÐùó (Fs   Á5B)FNN)F)r>   Únumpyr"   Ú_utilr   r   Ú
_array_apir   r   Ú	_ESIGNERRrK   Ú
_EVALUEERRrJ   Ú
_EINPUTERRÚ_ECONVERGEDrD   r7   r_   rF   rb   rG   rs   r   r   ú<module>r|      s]   ðó Û ß 9ß 0à€	Ø€	Ø€
Ø€
Ø€
Ø€Ø€óa/ðL @EóMAò`òD #óFr   