
    -i                         S r SSKrSSKJr  SSKJr  \\\R                  4r
\R                  " \R                  5      R                  rS rg)a   
This module provides the _project function that attempts to project the initial guess
onto the feasible set.

Adapted from the corresponding function in the PDFO package (https://www.pdfo.net) by
Tom M. Ragonneau (https://ragonneau.github.io) and Zaikun Zhang (https://www.zhangzk.net).
    N   LinearConstraint)OptimizeResultc           	        ^ Sn[        U [        5      (       a  U /mO.[        U S5      (       a  U mO[        SR	                  U5      5      e [
        R                  " T[
        R                  S9m[        TR                  5      S:w  a  [        SR	                  U5      5      eTR                  n[        U[        5      (       a  U/nO.[        US5      (       a  UnO[        SR	                  U5      5      e [
        R                  " U[
        R                  S9n[        UR                  5      S:w  d  UR                  U:w  a  [        S	R	                  U5      5      e[        U[        5      (       a  U/nO.[        US5      (       a  UnO[        S
R	                  U5      5      e [
        R                  " U[
        R                  S9n[        UR                  5      S:w  d  UR                  U:w  a  [        SR	                  U5      5      e[        U[        5      (       a=  SS1[        UR                  5       5      ::  a  [        US   [        5      (       d   US   b  [        SR	                  U5      5      eSnUS   c5  [
        R                  " [
        R                   " TU4SS9U4SS9n	[#        U	S9$ [%        [
        R&                  " [
        R(                  " US   R*                  US   R,                  -
  5      [.        5      5      (       a  [
        R0                  " U5      U* ::  a  [
        R2                  " U5      U:  a  US   R4                  n
US   R,                  US   R*                  -   S-  n[
        R6                  R9                  X[
        R:                  " U
T5      -
  SS9u  n    n[
        R                  " [
        R                   " TU-   U4SS9U4SS9n	[#        U	S9$ US   Gb<   SSKJn  SSKJ n  SSKJn  US   n[        5       [        5       nn[
        R                  " / /5      [
        R                  " / /5      sUS'   US'   US   RC                  SUR4                  R                  S   5      US'   US   RC                  SUR4                  R                  S   5      US'   [
        R                  " / 5      [
        R                  " / 5      sUS'   US'   [
        R                  " / 5      [
        R                  " / 5      sUS'   US'   [E        UR,                  R                  5       GH,  nUR,                  U   UR*                  U   :w  a  [
        RF                  " US   UR4                  UUS-   2SS24   4SS9US'   [
        RH                  US   UR,                  U   4   US'   [
        RH                  US   UR*                  U   4   US'   M  [
        RF                  " US   UR4                  UUS-   2SS24   4SS9US'   [
        RH                  US   UR,                  U   4   US'   [
        RH                  US   UR*                  U   4   US'   GM/     US   R                  S:  a7  US   R                  S:  a$  US   R                  S:  a  U" S0 UD6U" S0 UD6/nOMUS   R                  S:  a  US   R                  S:  a	  U" S0 UD6nOUS   R                  S:  a	  U" S0 UD6nOSn[
        R:                  " US   T5      n[
        R:                  " US   T5      n[
        RJ                  " UUS   5      RM                  5       (       d  [
        RJ                  " US   U5      RM                  5       (       d  [
        RN                  " UUS   5      RM                  5       (       dT  [
        RJ                  " TU5      RM                  5       (       d*  [
        RJ                  " UT5      RM                  5       (       a  U" U4S jTU4S jU" Xg5      US 9$ [#        TS9$ [#        TS9$ ! [         a    [        SR	                  U5      5      ef = f! [         a    [        SR	                  U5      5      ef = f! [         a    [        SR	                  U5      5      ef = f! [P         a    [#        TS9s $ f = f)!a(  Projection of the initial guess onto the feasible set.

Parameters
----------
x0: ndarray, shape (n,)
    The same as in prepdfo.
lb: ndarray, shape (n,)
    The same as in prepdfo.
ub: ndarray, shape (n,)
    The same as in prepdfo.
constraints: dict
    The general constraints of the problem, defined as a dictionary with
    fields:
        linear: LinearConstraint
            The linear constraints of the problem.
        nonlinear: dict
            The nonlinear constraints of the problem. When ``_project`` is called, the nonlinear constraints are
            None.

Returns
-------
result: OptimizeResult
    The result of the projection.

Authors
-------
Tom M. RAGONNEAU (ragonneau.github.io)
and Zaikun ZHANG (www.zhangzk.net)

Dedicated to the late Professor M. J. D. Powell FRS (1936--2015).
prima__len__z,{}: UNEXPECTED ERROR: x0 should be a vector.)dtypez5{}: UNEXPECTED ERROR: x0 should contain only scalars.r   z,{}: UNEXPECTED ERROR: lb should be a vector.z5{}: UNEXPECTED ERROR: lb should contain only scalars.z={}: UNEXPECTED ERROR: the size of lb is inconsistent with x0.z,{}: UNEXPECTED ERROR: ub should be a vector.z5{}: UNEXPECTED ERROR: ub should contain only scalars.z={}: UNEXPECTED ERROR: the size of ub is inconsistent with x0.linear	nonlinearNz6{}: UNEXPECTED ERROR: The constraints are ill-defined.g@xDr   )axis)x   )rcond)minimize)Boundsr   Albub c                 D   > [         R                  " U T-
  U T-
  5      S-  $ )Nr   )npdotr   x0_cs    U/var/www/html/venv/lib/python3.13/site-packages/scipy/_lib/pyprima/common/_project.py<lambda>_project.<locals>.<lambda>   s    "&&T1t8*Dq*H    c                    > U T-
  $ )Nr   r   s    r   r   r      s    _`cg_gr   )jacboundsconstraints))
isinstancescalar_typeshasattr
ValueErrorformatr   asarrayfloat64lenshapesizedictsetkeysr   nanminnanmaxr   all
less_equalabsr   r   epsmaxminr   linalglstsqr   scipy.optimizer   r   reshaperangeconcatenater_greaterany	not_equalImportError)x0r   r   r#   invokerlenx0lb_cub_cmax_conx_projabxi_r   ScipyBoundsScipyLinearConstraintr   pc_args_ineq
pc_args_eqiproject_constraintsax_ineqax_eqr   s                           @r   _projectrW      s   @ G "l##t	Y		GNNwWXXbzz$bjj1 4::!GNNwWXXIIE "l##t	Y		GNNwWXXbzz$bjj1 4::!tyyE1X__`ghii "l##t	Y		GNNwWXXbzz$bjj1 4::!tyyE1X__`ghii k4(((K1HCP[P`P`PbLc1cK13CDDT\H]HeQXXY`abbG 8$BIItTl;TBK''	R]]266+h"7":":[=R=U=U"UVX[\	]	]FF4LWH$)@ !##"%%H(=(@(@@AEiiooaRVVAt_)<DoIAq! BIItby$&7a@$GaP''8(1	*/<P *F (,vtv*L13RD1A2::rdCS.Lz# ,S 1 9 9!VXX^^A=N OL(o55a9JKJsO35::b>2::b>0L
4 035::b>2::b>0L
4 0699>>*99Q<699Q</(*S8I688TUVWXYVYTY[\T\K]7^ef(gL%)+|D/A699Q</O)PL&)+|D/A699Q</O)PL&&(nnjovxxPQRSTURUPUWXPXGY5Zab&cJsO')uuZ-=vyy|-K'LJt$')uuZ-=vyy|-K'LJt$ + C %%)l4.@.E.E.IjY]N^NcNcfgNg'<'L|'LNcNqfpNq&r#c"''!+T0B0G0G!0K&;&Kl&K#C%%)&;&Ij&I#&(# ff\#.5GFF:c?D1Ezz'<#56::<<

<X\K]_f@g@k@k@m@mLL
4(89==??JJtT*..00BJJtT4J4N4N4P4P H$Th'24'>L_a a &--
 D!!c  bPWWX_`aab  bPWWX_`aab  bPWWX_`aabb  	*!D))	*s=   #`2 6#a $#b .P1b*  b* 2%a%a?%b'*c ?c )__doc__numpyr   _linear_constraintsr   r;   r   intfloatgenericr%   finfor*   r6   rW   r   r   r   <module>r_      sE     1 ) UBJJ'hhrzz\"r   