L i$ddlZddlZddlmZmZddlmZddl m Z m Z m Z m Z mZmZmZGddeZdZdZdZd ZGd d ZGd d Zy)N)TestCaseassert_array_equal)BoundsLinearConstraintNonlinearConstraintPreparedConstraintnew_bounds_to_oldold_bound_to_new strict_boundsc$eZdZdZdZdZdZy)TestStrictBoundsc~d}d}d}d}t||||\}}t|tj tj tj gt|tjtjtjgd}t||||\}}t|gdt|gdy)NFT)rrr)rrrr rnpinfselfmlbubenforce_feasibility strict_lb strict_ubs k/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/scipy/optimize/tests/test_constraints.py+test_scalarvalue_unique_enforce_feasibilityz?",R-@-. 0 9 9i09i0cd}gd}gd}d}t||||\}}t|tj tj tj gt|tjtjtjgd}t||||\}}t|gdt|gdy)Nrrr)rFTrrs r+test_vectorvalue_unique_enforce_feasibilityz?",R.A./ 1 9 9i09i0rcd}d}d}gd}t||||\}}t|tj dtj gt|tjdtjgy)Nrrr)FTFrrs r+test_scalarvalue_vector_enforce_feasibilityz.fun]suuQxrcSr:r-r<s rjacz2test_prepare_constraint_infeasible_x0..jac`src,tjdS)N)rr)sps csr_array)r=vs rhessz3test_prepare_constraint_infeasible_x0..hesscs}}V$$r)rarrayrboolrpytestraises ValueErrorr violationanyallrr) rrx0rboundspclinearr?rArF nonlinearr>s @r%test_prepare_constraint_infeasible_x0rTFs  + B 3# $B ) B((#6dC B/ 0F MM*0&"= F2rNI 6B LL #a ' , , .. . LL (A - 2 2 44 4 , B , l;.cons_fps8xx1QqT)1Q419qt+;<==rg333333rr1r"g333333?g?g{Gz?rg333333gRQ?g{Gz?g= ףp=?)rrrrLrtestingassert_almost_equal)rWnlcrQs rtest_violationr]os> fr7maV ? XXsRVVGn %rxxbff '> XXtUm $ &  LDT]F4 ./G vyy'** 5 vyy'** 5 v33W5J5J K Lrctddgddg}t|jtjsJt|j tjsJy)NrYrt)rr)r isinstancerrndarrayr)rbs r test_arrayzTestBounds.test_arraysF sCjc3Z 0!$$ +++!$$ +++rc"t}ttjtj tjtj}|j|jk(sJ|j |j k(sJyr:)rrasarrayrrr)rb1b2s r test_defaultszTestBounds.test_defaultssY X BJJw'BFF); <uu~~uu~~rc d}tjt|5tt j ddgddgdddtjt|5tddgt j ddgdddd}tjt|5tddgddgt j ddgdddd}tjt|5tddggd dddy#1swYxYw#1swYxYw#1swYXxYw#1swYyxYw) Nz,Lower and upper bounds must be dense arrays.matchr"rz&`keep_feasible` must be a dense array.Trxz6`lb`, `ub`, and `keep_feasible` must be broadcastable.r!)rIrJrKrrC coo_array)rmessages rtest_input_validationz TestBounds.test_input_validations@ ]]:W 5 2 3==!Q(1a& 1 2 ]]:W 5 2 Aq63==!Q0 1 2; ]]:W 5 N Aq6Aq6d|1L M NK ]]:W 5 & Aq69 % & & 2 2 2 2 N N & &s/$D%$D!.(D-;D9D!D*-D69Ectdd}ddg}tjj|j |ddgddgfy)NrrXrr"r#)rrrZassert_allcloseresidual)rrPrOs r test_residualzTestBounds.test_residuals@A!W ""6??2#6!Q!Q8HIrN)r*r+r,r{rrrrr-rrrqrqsL ,  &JrrqceZdZdZdZdZy)TestLinearConstraintctjd}t|}t|tj tj}t |j |j t |j |j y)Nr)reyerrrrr)rr>lclc2s rrz"TestLinearConstraint.test_defaultssU FF1I a q266'2662255#&&)255#&&)rc ftjd}d}tjt|5t |ddggddddd}tjt|5t |t jddgddgdddtjt|5t |ddgt jddgdddd }tjt|5t jd d g}t |ddgddg| dddtjd }d }tjt|5t |dddy#1swY3xYw#1swYxYw#1swYxYw#1swYuxYw#1swYyxYw)Nrz5`lb`, `ub`, and `keep_feasible` must be broadcastablerr"rr!z&Constraint limits must be dense arraysrz%`keep_feasible` must be a dense arrayTr)rrr#z%`A` must have exactly two dimensions.) rrrIrJrKrrCrempty)rr>rrxs rrz*TestLinearConstraint.test_input_validationsi FF1II ]]:W 5 3 QA 2 3; ]]:W 5 ? Q q!f 51v > ? ]]:W 5 ? QA q!f(= > ?: ]]:W 5 MMM4,7M QAAm L M HHY 9 ]]:W 5 Q   ! 3 3 ? ? ? ? M M   s;E6*%F2%F<+F! F'6FF FF$'F0ctjd}t|dd}ddg}tjj |j |ddgddgfy)NrrrrXr"r#)rrrrZrr)rr>rrOs rrz"TestLinearConstraint.test_residualsO FF1I aQ '!W ""2;;r?aVaV4DErN)r*r+r,rrrr-rrrrs* ,Frr)rIrur numpy.testingrr scipy.sparsesparserCscipy.optimize._constraintsrrrrr r r r rTr]rkrorqrr-rrrs] 6888 9;x9;x&7RI$N4 ( /J/Jd"F"Fr