+
    nDjG                        ^ RI t ^ RIHt ^ RIt^ RIHtHtHt ^ RI	t	^ RI	H
t ^ RIHtHt ^ RIHtHtHt ^ RIHt ^ RIHtHtHtHtHtHt ^ R	IHt R
 tR t ! R R4      t  ! R R4      t! ! R R4      t" ! R R4      t#R t$R t%R# )    N)product)assert_allcloseassert_equalassert_)raises)
MapWrapper_ScalarFunctionWrapper)	csr_array	csc_array	lil_array)xp_result_type)_adjust_scheme_to_boundsapprox_derivativecheck_derivativegroup_columns_eps_for_method_compute_absolute_steprosenc                     . RO. RO. RO. RO. RO. RO. RO.p \         P                  \        \        \        3 F  pV! V 4      p\         P
                  ! ^4      p\         P                  ! . R	O4      p\        W#4      p\        WT4       . R
Op\         P                  ! . RO4      p\        W#4      p\        WT4       K  	  \        X4      p\        V4      p\        Wg4       R# )   N)r   r   r   r   r   r   )r   r   r   r   r   r   )r   r   r   r   r   r   )r   r   r   r   r   r   )r   r   r   r   r   r   )r   r   r   r   r   r   )r   r   r   r   r   r   )r   r      r   r   r   )r   r            r   )r   r   r   r   r   r   )	npasarrayr
   r   r   arangearrayr   r   )	structure	transformAordergroups_truegroupsgroups_1groups_2s           \/data/cameron/venvs/s3viz/lib/python3.14/site-packages/scipy/optimize/tests/test__numdiff.pytest_group_columnsr)      s    I jj)Y	B	i 		!hh12q(V)"hh12q(V) C QHQH$    c                     \         P                  ! \         P                  4      P                  p R V R,          RV R,          RV R,          /pR Fu  p\	        \        \         P                  \         P                  V4      W,          4       \	        \        \         P                  \         P                  V4      W,          4       Kw  	  \         P                  ! \         P                  4      P                  p R V R,          RV R,          RV R,          /pR F  p\	        \        \         P                  \         P                  V4      W,          4       \	        \        \         P                  \         P                  V4      W,          4       \	        \        \         P                  \         P                  V4      W,          4       K  	  R# )2-point      ?3-pointcsNUUUUUU?r,   r.   r/   )r   finfofloat64epsr   r   
complex128float32)EPSrelative_stepmethods      r(   test_correct_fp_epsr:   /   s@   
((2::

"
"CSsSz38%M /BJJ

F;!	# 	BMM2==&A!	
	 / ((2::

"
"CSsSz38%M /BJJ

F;!	
 	BJJ

F;!	
 	BJJ

F;!	
 /r*   c                   2   a  ] tR t^St o R tR tR tRtV tR# )TestAdjustSchemeToBoundsc                
   \         P                  ! ^4      p\         P                  ! ^R4      p\         P                  ! V4      p\         P                  ! V4      pVP	                  \         P
                  ) 4       VP	                  \         P
                  4       \        W^RW44      w  rV\        WR4       \        \         P                  ! V4      4       \        W^RW44      w  rV\        WR4       \        \         P                  ! V4      4       \        W^RW44      w  rV\        WR4       \        \         P                  ! V( 4      4       \        W^RW44      w  rV\        WR4       \        \         P                  ! V( 4      4       R# )r   {Gz?1-sided2-sidedN)
r   zerosfull
empty_likefillinfr   r   r   all)selfx0h	inf_lower	inf_upper
h_adjusted	one_sideds   &      r(   test_no_bounds'TestAdjustSchemeToBounds.test_no_boundsT   s   XXa[GGAtMM"%	MM"%	wrvv 81i!7

&y!" 81i!7

&y!" 81i!7

&	z"# 81i!7

&	z"#r*   c                   \         P                  ! . RO4      p\         P                  ! ^4      ) p\         P                  ! ^4      p\         P                  ! . RO4      R,          p\        W^RW#4      w  rV\	        WT4       \        W^RW#4      w  rV\	        V\         P                  ! . RO4      R,          4       \        W^RW#4      w  rW\	        V\         P
                  ! V4      4       \        \         P                  ! V( 4      4       \        W^RW#4      w  rW\	        V\         P                  ! . RO4      R,          4       \        V\         P                  ! . RO4      4       R# )	        皙?r?   r@   N)rQ   g333333?g333333)r   r   )r   rS   r   )FTT)	r   r   onesr   r   absr   rF   r   )rG   rH   lbubrI   rL   _rM   s   &       r(   test_with_bound(TestAdjustSchemeToBounds.test_with_boundp   s   XX()ggaj[WWQZHHZ 4'09bM

&09bM

BHHZ$84$?@ 81i!)

BFF1I.	z"# 81i!)

BHHZ$84$?@Y)< =>r*   c                   \         P                  ! R
R
.4      p\         P                  ! RR.4      p\         P                  ! RR .4      p\         P                  ! RR.4      p\        W4^RW4      w  rV\        V\         P                  ! RR.4      4       \        W4^RW4      w  rV\        V\         P                  ! RR
.4      4       \        W4^RW4      w  rW\        V\         P                  ! R R
.4      4       \	        V\         P                  ! RR.4      4       \        W4^RW4      w  rW\        V\         P                  ! RR.4      4       \	        V\         P                  ! RR.4      4       R	# )gQ?g?rQ   r?   g?r@   FTgQ?NgQ皙gQgQ)r   r   r   r   r   )rG   rV   rW   rH   rI   rL   rX   rM   s   &       r(   test_tight_bounds*TestAdjustSchemeToBounds.test_tight_bounds   s$   XXuen%XXtTl#XXsDk"HHdD\"09bM

BHHdE]$;<09bM

BHHeU^$<= 81i!)

BHHdE]$;<Y% 78 81i!)

BHHeV_$=>Y% 78r*    N)	__name__
__module____qualname____firstlineno__rN   rY   r]   __static_attributes____classdictcell____classdict__s   @r(   r<   r<   S   s     $8?,9 9r*   r<   c                     a  ] tR t^t o R tR tR tR tR tR t	R t
R tR	 tR
 tR tR.R ltR/R ltR tR tR tR tR tR tR tR t]P4                  P7                  R4      R 4       tR tR tR tR t R t!R t"R t#R t$R  t%R! t&R" t'R# t(]P4                  PS                  R$]*PV                  ]*PX                  ]*PZ                  34      ]P4                  PS                  R%]*PV                  ]*PX                  ]*PZ                  34      ]P4                  PS                  R&R'R(.4      R) 4       4       4       t.R* t/R+ t0R,t1V t2R-# )0TestApproxDerivativesDensec                .    \         P                  ! V4      # Nr   sinhrG   xs   &&r(   fun_scalar_scalar,TestApproxDerivativesDense.fun_scalar_scalar       wwqzr*   c                .    \         P                  ! V4      # rk   r   coshrn   s   &&r(   jac_scalar_scalar,TestApproxDerivativesDense.jac_scalar_scalar   rr   r*   c                    \         P                  ! V^ ,          ^,          \         P                  ! V^ ,          4      \         P                  ! V^ ,          4      .4      # r   r   r   tanexprn   s   &&r(   fun_scalar_vector,TestApproxDerivativesDense.fun_scalar_vector   8    xx1q"&&1,qt=>>r*   c                    \         P                  ! ^V^ ,          ,          \         P                  ! V^ ,          4      R,          \         P                  ! V^ ,          4      .4      P	                  R^4      # r   rS   r   r   cosr|   reshapern   s   &&r(   jac_scalar_vector,TestApproxDerivativesDense.jac_scalar_vector   N    xx1Xrvvad|r)266!A$<8::A'"a.	Ir*   c                    \         P                  ! V^ ,          V^,          ,          4      \         P                  ! V^ ,          4      ,          # ry   r   sinlogrn   s   &&r(   fun_vector_scalar,TestApproxDerivativesDense.fun_vector_scalar   .    vvadQqTk"RVVAaD\11r*   c                    \         P                  ! V^,          \         P                  ! V4      \         P                  ! V4      .4      # r   rz   rn   s   &&r(   wrong_dimensions_fun/TestApproxDerivativesDense.wrong_dimensions_fun   s,    xxArvvay"&&)455r*   c           	        \         P                  ! V^,          \         P                  ! V^ ,          V^,          ,          4      ,          \         P                  ! V^ ,          4      ,          \         P                  ! V^ ,          V^,          ,          4      V^ ,          ,          ,           V^ ,          \         P                  ! V^ ,          V^,          ,          4      ,          \         P                  ! V^ ,          4      ,          .4      # r   r   r   r   r   r   rn   s   &&r(   jac_vector_scalar,TestApproxDerivativesDense.jac_vector_scalar       xxaD266!A$1+&&!5FF1Q4!A$;!A$&'aD266!A$1+&&!5
  	r*   c                   \         P                  ! V^ ,          \         P                  ! V^,          4      ,          V^,          \         P                  ! V^ ,          4      ,          V^ ,          ^,          V^,          R,          ,          .4      # r         ࿩r   r   r   r   rn   s   &&r(   fun_vector_vector,TestApproxDerivativesDense.fun_vector_vector   `    xxaD266!A$<aD266!A$<aDAI!$
  	r*   c                0   V^*8X  g   Q h\         P                  ! V^ ,          \         P                  ! V^,          4      ,          V^,          \         P                  ! V^ ,          4      ,          V^ ,          ^,          V^,          R,          ,          .4      # )=Used to test passing custom arguments with check_derivative()r   r   rG   ro   args   &&&r(   fun_vector_vector_with_arg5TestApproxDerivativesDense.fun_vector_vector_with_arg   sl    byyxxaD266!A$<aD266!A$<aDAI!$
  	r*   c                   \         P                  ! \         P                  ! V^,          4      V^ ,          \         P                  ! V^,          4      ,          .V^,          ) \         P                  ! V^ ,          4      ,          \         P                  ! V^ ,          4      .^V^ ,          ^,          ,          V^,          R,          ,          RV^ ,          ^,          ,          V^,          R,          ,          ..4      # r   r         r   rn   s   &&r(   jac_vector_vector,TestApproxDerivativesDense.jac_vector_vector       xxVVAaD\1Q4"&&1,./dURVVAaD\!266!A$<01]QqTT\)4!A$!)+;addl+JK
  	r*   c                   V^*8X  g   Q h\         P                  ! \         P                  ! V^,          4      V^ ,          \         P                  ! V^,          4      ,          .V^,          ) \         P                  ! V^ ,          4      ,          \         P                  ! V^ ,          4      .^V^ ,          ^,          ,          V^,          R,          ,          RV^ ,          ^,          ,          V^,          R,          ,          ..4      # )r   r   r   r   r   s   &&&r(   jac_vector_vector_with_arg5TestApproxDerivativesDense.jac_vector_vector_with_arg   s    byyxxVVAaD\1Q4"&&1,./dURVVAaD\!266!A$<01]QqTT\)4!A$!)+;addl+JK
  	r*   c                    \         P                  ! \         P                  ! W!^ ,          ,          4      \         P                  ! W1^,          ,          4      .4      # ry   r   r   r|   rG   ro   c0c1s   &&&&r(   fun_parametrized+TestApproxDerivativesDense.fun_parametrized   s4    xxqT	*BFF2!9,=>??r*   c           
         \         P                  ! V\         P                  ! W!^ ,          ,          4      ,          ^ .^ V\         P                  ! W1^,          ,          4      ,          ..4      # ry   r   r   s   &&&&r(   jac_parametrized+TestApproxDerivativesDense.jac_parametrized   sP    xx"&&d##Q'RVVB1I&&'
  	r*   c                \    \         P                  ! V4      R 8:  d   V# \         P                  # ):0yE>r   rU   nanrn   s   &&r(   fun_with_nan'TestApproxDerivativesDense.fun_with_nan   s     FF1I%q12661r*   c                \    \         P                  ! V4      R 8:  d   R# \         P                  # )r         ?r   rn   s   &&r(   jac_with_nan'TestApproxDerivativesDense.jac_with_nan   s     ffQi4's3RVV3r*   c                    \         P                  ! V^ ,          V^,          ,          \         P                  ! V^ ,          V^,          ,          4      .4      # ry   )r   r   r   rn   s   &&r(   fun_zero_jacobian,TestApproxDerivativesDense.fun_zero_jacobian   s7    xx1!bffQqTAaD[&9:;;r*   c           
     6   \         P                  ! V^,          V^ ,          .V^,          ) \         P                  ! V^ ,          V^,          ,          4      ,          V^ ,          ) \         P                  ! V^ ,          V^,          ,          4      ,          ..4      # r   )r   r   r   rn   s   &&r(   jac_zero_jacobian,TestApproxDerivativesDense.jac_zero_jacobian   so    xxqT1Q4LdURVVAaD1Q4K((1Q4%"&&1!2E*EF
  	r*   c                v    \         P                  ! V4      P                  4       p\        P                  ! V4      # rk   )r   r   itemmathr|   )rG   ro   xps   && r(   jac_non_numpy(TestApproxDerivativesDense.jac_non_numpy   s(     ZZ]!xx|r*   c                   R p\        V P                  VRR7      p\        V P                  V4      p\        V P                  VRR7      pV P                  V4      p\        W%RR7       \        W5RR7       \        WERR7       R# )	r   r,   r9   r/   ư>rtol&.>-q=Nr   rp   rv   r   rG   rH   
jac_diff_2
jac_diff_3
jac_diff_4jac_trues   &     r(   test_scalar_scalar-TestApproxDerivativesDense.test_scalar_scalar   su    &t'='=r.79
&t'='=rB
&t'='=r.24
))"-
48
48
59r*   c                   R p\        V P                  VRRR7      p\        V P                  VRR7      p\        V P                  VRRR7      pV P                  V4      p\        W%RR7       \        W5RR7       \        WER	R7       R
# )r   r,   "\O>r9   abs_step)r   r/   r   r   r   r   Nr   r   s   &     r(   test_scalar_scalar_abs_step6TestApproxDerivativesDense.test_scalar_scalar_abs_step  s    &t'='=r.7'K
&t'='=r079
&t'='=r.2WF
))"-
48
48
59r*   c           	        R p\        ^4      ;_uu_ 4       p\        V P                  VRVR7      pRRR4       \        V P                  V\        R7      p\        V P                  VRRR7      pV P	                  \
        P                  ! V4      4      p\        XVRR7       \        WFRR7       \        WVR	R7       R#   + '       g   i     L; i)
r-   r,   r9   workersN)r   r/   r   r   r   r   )r   r   r}   mapr   r   
atleast_1dr   )rG   rH   mapperr   r   r   r   s   &      r(   test_scalar_vector-TestApproxDerivativesDense.test_scalar_vector  s    ]]f*4+A+A22;VMJ  't'='=r3O
&t'='=r.2DB
))"--*;<
H48
48
59 ]s   B<<C	g      @c           
        . R
Op\        ^4      ;_uu_ 4       p\        \        VRVRR7      w  r4\        \        VVRR7      w  rVRRR4       \        \        VR^RR7      w  rx\        \        4      p	\        WRRR7      w  r\	        VR,          V	P
                  4       ^ V	n        \        WRR	7      w  r\	        VR,          V	P
                  4       ^ V	n        \        WRRR7      w  r\	        VR,          V	P
                  4       \	        XR,          VR,          4       \	        XR,          VR,          4       \	        VR,          VR,          4       \	        XV
4       \	        XV4       \	        W~4       R#   + '       g   i     EL=; i)r-   r,   T)r9   r   full_output)r   r   Nr/   )r9   r   nfev)r   )r-   g      ?       @)r   r   r   r	   r   r   )rG   rH   r   md2mdct2md3mdct3md4mdct4sfrd2dct2d3dct3d4dct4s   &               r(   !test_workers_evaluations_and_nfev<TestApproxDerivativesDense.test_workers_evaluations_and_nfev  s=    ]]f*5"2;V7;=JC +5"39tMJC	  'ub.2A379
 %U+$SYDQT&\388,$S$?T&\388,$STtLT&\388,U6]DL1U6]DL1U6]DL1S"S"S9 ]]s   ,E88F		c                2   \         P                  ! R R	.4      p\        V P                  VRR7      p\        V P                  V4      p\        V P                  VRR7      pV P	                  V4      p\        W%RR7       \        W5RR7       \        WERR7       R# )
      Y@r,   r   r/   r   r   Hz>r   Nr   )r   r   r   r   r   r   r   s   &     r(   test_vector_scalar-TestApproxDerivativesDense.test_vector_scalar@  s    XXudm$&t'='=r.79
&t'='=rB
&t'='=r.24
))"-
48
48
59r*   c                X   \         P                  ! R R.4      p\        V P                  VRRR7      p\        V P                  VR\         P                  R7      p\        V P                  VRRR7      pV P                  V4      p\        W%RR7       \        W5RR7       \        WER	R7       R
# )r  r,   r   r   )r   rel_stepr/   r   r   A:)>r   Nr   )r   r   r   r   rE   r   r   r   s   &     r(   test_vector_scalar_abs_step6TestApproxDerivativesDense.test_vector_scalar_abs_stepL  s    XXudm$&t'='=r.7'K
&t'='=r07"&&J
&t'='=r.2WF
))"-
48
48
59r*   c           	        \         P                  ! RR.4      p\        V P                  VRR7      p\        V P                  V4      p\	        ^4      ;_uu_ 4       p\        V P                  VRVR7      pRRR4       V P                  V4      p\        W&RR7       \        W6R	R7       \        XVR
R7       R#   + '       g   i     LK; i)r  皙?r,   r   r/   r   Nh㈵>r   r   r         Y)r   r   r   r   r   r   r   )rG   rH   r   r   r   r   r   s   &      r(   test_vector_vector-TestApproxDerivativesDense.test_vector_vectorZ  s    XXvsm$&t'='=r.79
&t'='=rB
]]f*4+A+A226HJ  ))"-
48
48
H59 ]s   B77C	c                    R p\        \        \        V P                  V4       V P                  \        P
                  ! V4      4      p\        \        \        V P                  WR7       R# )r   )f0N)assert_raisesRuntimeErrorr   r   r   r   
ValueError)rG   rH   r  s   &  r(   test_wrong_dimensions0TestApproxDerivativesDense.test_wrong_dimensionsg  sP    l$5//	5&&r}}R'89j"3//	<r*   c                    \         P                  ! RR .4      p\        V P                  VRRR7      p\        V P                  VRR7      pV P	                  V4      p\        W$RR7       \        W4RR7       R# )	rR   r,   g-C6?)r9   r  )r  r>   r   Nr\   )r   r   r   r   r   r   )rG   rH   r   r   r   s   &    r(   test_custom_rel_step/TestApproxDerivativesDense.test_custom_rel_stepo  si    XXtSk"&t'='=r.7$H
&t'='=r046
))"-
48
48r*   c                   \         P                  ! R R .4      pRpR pRpRpV P                  WVR7      p\         P                  ! RR.4      pV P                  WV4      p\	        V P                  VRVWb3\        VR7      WE3R7      p	\	        V P                  WWb3\        VR7      WE3R7      p
\        WRR	7       \        WR
R	7       R# )r   rQ   r   )r   r   r  r,   )r9   r  r  argskwargsbounds)r  r  r  r  r  r   r   N      gư)r   r   r   r   r   dictr   )rG   rH   r   r   rV   rW   r  r  r   r   r   s   &          r(   test_options'TestApproxDerivativesDense.test_optionsy  s    XXsCj!""2b"188UDM*((4&!!2i(dbk2(D
 '!!2dbk2(D
 	
48
48r*   c                v   \         P                  ! ^4      ) p\         P                  ! ^4      p\         P                  ! R	R.4      p\        \        \
        V P                  W1V3R7       \         P                  ! R
R.4      p\        V P                  VRW3R7      pV P                  V4      p\        WERR7       R# )r   r  r  r   r,   r9   r  r   r   Ng       r  )	r   rT   r   r  r  r   r   r   r   )rG   rV   rW   rH   jac_diffr   s   &     r(   test_with_bounds_2_point3TestApproxDerivativesDense.test_with_bounds_2_point  s    ggaj[WWQZXXtSk"j"3,,bb	C XXtSk"$T%;%;R,5rhH))"-6r*   c                    \         P                  ! R R .4      p\         P                  ! RR.4      p\         P                  ! R R.4      pV P                  V4      p\        V P                  V4      p\        WTRR7       \        V P                  VV\         P                  3R7      p\        WTRR7       \        V P                  V\         P                  ) V3R7      p\        WTRR7       \        V P                  VW3R7      p\        WTRR7       R# )r   r   r   r   r#  N)r   r   r   r   r   r   rE   )rG   rV   rW   rH   r   r%  s   &     r(   test_with_bounds_3_point3TestApproxDerivativesDense.test_with_bounds_3_point  s    XXsCj!XXsCj!XXsCj!))"-$T%;%;R@6$T%;%;R-/L:6$T%;%;R.0ffWbM;6$T%;%;R-/H66r*   c                   \         P                  ! R R .4      pVR,
          pVR,           pV P                  V4      p\        V P                  VRW#3R7      p\        WTRR7       \        V P                  VRRW#3R7      p\        WTRR7       \        V P                  WV3R7      p\        WTRR7       \        V P                  VRW#3R	7      p\        WERR7       R
# )      $@r  g&.!>r,   r$  r   r   r9   r  r  r#  r  r  N)r   r   r   r   r   r   )rG   rH   rV   rW   r   r%  s   &     r(   r]   ,TestApproxDerivativesDense.test_tight_bounds  s    XXtTl#$Y$Y))"-$""By"K6$""By2(, 	6$""BBx96$""BrhH6r*   c                   R	pR pRpV P                  V4      p\        V P                  VRRW3R7      p\        V P                  VRW3R7      p\        WTRR7       \        WdRR7       R pV P                  V4      p\        V P                  VRRW3R7      p\        V P                  VRW3R7      p\        WTRR7       \        WdRR7       R# )
r   rQ   r,   r   r-  r.  r   r   N:0yE)r   r   r   r   )rG   rV   rW   rH   r   r   r   s   &      r(   test_bound_switches.TestApproxDerivativesDense.test_bound_switches  s    $$R(&r)d8
 'rD"C

48
48$$R(&r)d8
 'rD"C

48
48r*   c                   R pV P                  V4      p\        V P                   VRR7      p\        V P                   V4      p\        W2RR7       \        WBRR7       \        \        \        V P                   V3/ \        RR7      B  R# )r   r,   r   r   r   r   r/   N)r   r   r   r  	TypeErrorr  )rG   rH   r   r   r   s   &    r(   test_non_numpy)TestApproxDerivativesDense.test_non_numpy  sz    %%b)&t'9'92.79
&t'9'92>

48
48 	i!2D4F4F 	+D)	+r*   c                l  aaaa \         P                  P                  ^4      pR oV3R lo\         P                  ! ^ ^^d\         P                  R7      oVP                  ^d\         P                  R7      o\         P
                  ! RR.4      p\        SVRSS3R7      p\        SVP                  \         P                  4      RSS3R7      pS! VSS4      P                  \         P                  8X  g   Q h\        WCRR	7       VVV3R
 lp\        WRP                  \         P                  4      RR7      p\        WCRR	7       VP                  \         P                  8X  g   Q hR pR pR pR p	\         P                  \         P                  \         P                  3 F  p
\         P                  ! V
4      P                  p\         P
                  ! R4      P                  V
4      p\        RW! V4      R4      pV	! WWhV4      p\        WlRVR7      V! V4      ,
          o\        S4      V8  d   K  Q h	  R# )r   c                 >    V ^ ,          V ^,          V,          ,           # ry   r_   )pro   s   &&r(   func0TestApproxDerivativesDense.test_fp.<locals>.func  s    Q4!A$(?"r*   c                 "   < S! W4      V,
          # rk   r_   )r:  ro   yr;  s   &&&r(   err/TestApproxDerivativesDense.test_fp.<locals>.err  s    :>!r*   dtype)sizerB  r   r,   )r9   r  MbP?)atolc                    < V P                   \        P                  8X  g   Q hS! V SS4      P                  \        P                  4      # rk   )rB  r   r6   astype)r:  r?  ro   r>  s   &r(   err_fp324TestApproxDerivativesDense.test_fp.<locals>.err_fp32  s6    77bjj(((q!Q<&&rzz22r*   r   c                 .    \         P                  ! V 4      # rk   r   r   ro   s   &r(   f-TestApproxDerivativesDense.test_fp.<locals>.f	      66!9r*   c                 .    \         P                  ! V 4      # rk   )r   r   rL  s   &r(   g-TestApproxDerivativesDense.test_fp.<locals>.g  rO  r*   c                 0    \         P                  ! V 4      ) # rk   rK  rL  s   &r(   hess0TestApproxDerivativesDense.test_fp.<locals>.hess  s    FF1I:r*   c           
      `   V ^,          \        \        P                  ! V! V4      4      \        P                  ! V! W,           4      4      4      ,          pW@,          \        \        P                  ! V! V4      4      \        P                  ! V! W,           4      4      4      ,          pWV,           # r   )maxr   rU   )rI   rH   rM  rT  r7   t0t1s   &&&&&  r(   	calc_atol5TestApproxDerivativesDense.test_fp.<locals>.calc_atol  sj    QRVVDH-rvvd26l/CDDB 3rvvae}bffQrvY.?@@B7Nr*   Nr   r  )r   randomdefault_rnglinspacer3   r   r   rG  r6   rB  r   float16r2   r4   r   rU   )rG   rngp0jac_fp64jac_fprH  rM  rQ  rT  rZ  rB  r7   rH   rI   rE  r?  r;  ro   r>  s   &              @@@@r(   test_fp"TestApproxDerivativesDense.test_fp  s    ii##A&	#	" KK1c4JJCrzzJ2XXtTl#$S"YaVL #3		"**(=*31a&B2q!}""bjj000t4	3 #8YYrzz-B*35t4||rzz)))				 jj"**bjj9E((5/%%C#%%e,B&tR2	BAQAS1D#A)-.023B%8Cs8d?"? :r*   x0_dtypef0_dtyper9   r,   r.   c                  a \         P                  ! . R
OVR7      pV3R lp\        VV! V4      R\         R7      p\        WTVR7      pVP                  V8X  g   Q h\        WT\         P
                  ! R4      VR7      pVP                  V8X  g   Q h\        WT\         P
                  ! R4      VR7      pVP                  V8X  g   Q hR	# )r   rA  c                 &   < S! \        V 4      4      # rk   r   )ro   rg  s   &r(   rM  6TestApproxDerivativesDense.test_check_dtype.<locals>.f-  s    E!H%%r*   T)force_floatingr   r   rR   )r  r9   )r   r9   N)r   g      @g      @)r   r   r   r   rB  r_  )rG   rf  rg  r9   ro   rM  promoted_typerQ  s   &&f&    r(   test_check_dtype+TestApproxDerivativesDense.test_check_dtype#  s     HH_H5	& '	aD	
 a62ww-''' aRZZ_VLww-'''aRZZ_VLww-'''r*   c                   \         P                  ! R^
.4      p\        V P                  V P                  V4      p\        VR8  4       \        V P                  V P                  V4      p\        VR8  4       \         P                  ! RR.4      p\        V P                  V P                  V4      p\        V^ 8H  4       \        V P                  V P                  V4      p\        V^ 8H  4       R# )r,  r   r   rQ   N      $)r   r   r   r   r   r   r   r   rG   rH   accuracys   &  r(   test_check_derivative0TestApproxDerivativesDense.test_check_derivative@  s    XXubk"#D$:$:$($:$:B@4 #D$:$:$($:$:B@4 XXsCj!#D$:$:$($:$:B@A#D$:$:$($:$:B@Ar*   c                    \         P                  ! R^
.4      p\        V P                  V P                  VR^*/R7      p\        VR8  4       R# )r,  r   )r  r   Nrp  )r   r   r   r   r   r   rq  s   &  r(   !test_check_derivative_with_kwargs<TestApproxDerivativesDense.test_check_derivative_with_kwargsQ  sG    XXubk"#D$C$C$($C$C$&,12;8 	4 r*   r_   N)r   )rR   )3r`   ra   rb   rc   rp   rv   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   pytestmark	fail_slowr   r  r  r  r  r  r   r&  r)  r]   r2  r6  rd  parametrizer   r_  r6   r3   rm  rs  rv  rd   re   rf   s   @r(   ri   ri      sd    ?I26@24<
::: [[3    D
:::<99$77,7(9.+9#x [[Z"**bjj"**)MN[[Z"**bjj"**)MN[[X	9'=>( ? O O(4"! !r*   ri   c                      a  ] tR tRt o R tR tR tR t]P                  P                  ^4      R 4       tR tR tR	 tR
tV tR# )TestApproxDerivativeSparseiZ  c                N   \         P                  P                  R 4      V n        ^2V n        R^\         P
                  ! V P                  4      ,           ,          V n        R^\         P
                  ! V P                  4      ,           ,          V n        \         P                  ! V P                  4      V n	        RV P                  R,          ,          V P                  R&   RV P                  R,          ,          V P                  R&   V P                  V P                  4      V n        R# )i7rR   NNr   :r   Nr   Nr\   gP?)r   r\  r]  r`  nr   rV   rW   emptyrH   jacJ_true)rG   s   &r(   setup_method'TestApproxDerivativeSparse.setup_method\  s    99((3!bii//0RYYtvv../((466" DGGCL0!TWWT]2hhtww'r*   c                    VR ,          ^,          VRR ^,          ,
          p\         P                  ! ^ ^V,          34      \         P                  ! ^V,          ^ 34      ,           # ):r   NNNrS   )r   hstack)rG   ro   es   && r(   funTestApproxDerivativeSparse.fung  sK    bE1Hq"vqy yy!QU$ryy!a%'<<<r*   c                "   VP                   p\        P                  ! W"34      pRV^ ,          ,          VR&   ^V^,          ^,          ,          VR&   \        ^V^,
          4       Fz  pRW^,
          ,          ,          W4V^,
          3&   ^	W,          ^,          ,          ^W,          ,          ,
          W4V3&   ^W^,           ,          ^,          ,          W4V^,           3&   K|  	  ^	VR,          ^,          ,          VR&   RVR,          ,          VR&   V# )	r   r   r   r   r   irS   rS   rS   r   rS   r   )rC  r   rA   range)rG   ro   r  Jis   &&   r(   r  TestApproxDerivativeSparse.jack  s    FFHHaVqt)$adAg+$q!a%Aq1v+AQhK!$'kAH,AdGa!fai-AQhK ! "qL&	2J&	r*   c                    \         P                  ! W3\        R 7      p^VR&   ^VR&   \        ^V^,
          4       F  p^W#V^,
          V^,           13&   K  	  ^VR&   ^VR&   V# )rA  r  r  r  r  )r   rA   intr  )rG   r  r"   r  s   &&  r(   r    $TestApproxDerivativeSparse.structurey  si    HHaV3'$$q!a%A!"AQAo !&	&	r*   c                   V P                  V P                  4      p\        P                  ! V P                  4      p\	        W4      pV P
                  P                  V4       \	        W4      p\        ^4      ;_uu_ 4       p\        . R	OW4.\        P                  ) V P                  .\        P                  V P                  .\        V.4       F  w  rgrp
\        V P                  V P                  VW3W3V
R7      p\!        \#        V\$        4      4       \'        VP)                  4       V P*                  RR7       \        P,                  ! V P                  R4      pVR;;,          R
,          uu&   \        V P                  V P                  VWV3V
R7      p\'        VP)                  4       V P*                  RR7       K  	  RRR4       R#   + '       g   i     R# ; i)r   )r9   r  sparsityr   r   r   r   r  )r9   r  r  r   r  Nr1   rS   )r    r  r   r   r   r`  shuffler   r   rE   rV   rW   r   r   r  rH   r   
isinstancer
   r   toarrayr  	full_like)rG   r"   r#   r&   r'   r   r9   r%   lumfr  r  s   &            r(   test_all#TestApproxDerivativeSparse.test_all  sS   NN466"		$&&! * *]]f,3082FffWdgg&(9C=-J(b &dhh./Vqk.02 
1i01		T[[tD<<6#%dhh/7f+.02  		T[[tD-J ]]]s    EGG	c                    V P                  V P                  4      p\        V P                  V P                  VR 7      p\        VP                  4       V P                  RR7       R# ))r  r   r   N)r    r  r   r  rH   r   r  r  )rG   r"   r  s   &  r(   test_no_precomputed_groups5TestApproxDerivativeSparse.test_no_precomputed_groups  s@    NN466"dhh!<		T[[t<r*   c                   \         P                  ! V P                  V P                  3\        R 7      p\         P                  ! V P                  4      pR Fe  p\        V P                  V P                  VR7      p\        V P                  V P                  W3VR7      p\        WEP                  4       RRR7       Kg  	  R# )rA  r   )r  r9   gV瞯<gVs<)r   rE  Nr1   )
r   rT   r  r  r   r   r  rH   r   r  )rG   r    r%   r9   J_denseJ_sparses   &     r(   test_equivalence+TestApproxDerivativeSparse.test_equivalence  s    GGTVVTVV,C8	466"2F'$''&IG($''Y,?PHG%5%5%7!&U4	 3r*   c                0  a  V 3R  lp\        S P                  VS P                  S P                  S P                  3R7      p\        VR8  4       \        S P                  VS P                  S P                  S P                  3R7      p\        VR8  4       R# )c                 8   < \        SP                  V 4      4      # rk   )r
   r  )ro   rG   s   &r(   r  =TestApproxDerivativeSparse.test_check_derivative.<locals>.jac  s    TXXa[))r*   r#  r   N)r   r  rH   rV   rW   r   )rG   r  rr  s   f  r(   rs  0TestApproxDerivativeSparse.test_check_derivative  sr    	* $DHHc477,0GGTWW+=?4 #DHHc477,0GGTWW+=?4 r*   )r  rV   r  r`  rW   rH   N)r`   ra   rb   rc   r  r  r  r    rx  ry  rz  r  r  r  rs  rd   re   rf   s   @r(   r}  r}  Z  sR     	(=	 [[1E E0=
4
! 
!r*   r}  c                   n   a  ] tR tRt o R tR tR tR tR tR t	R t
R	 tR
 tR tR tR tR tRtV tR# )"TestApproxDerivativeLinearOperatori  c                .    \         P                  ! V4      # rk   rl   rn   s   &&r(   rp   4TestApproxDerivativeLinearOperator.fun_scalar_scalar  rr   r*   c                .    \         P                  ! V4      # rk   rt   rn   s   &&r(   rv   4TestApproxDerivativeLinearOperator.jac_scalar_scalar  rr   r*   c                    \         P                  ! V^ ,          ^,          \         P                  ! V^ ,          4      \         P                  ! V^ ,          4      .4      # ry   rz   rn   s   &&r(   r}   4TestApproxDerivativeLinearOperator.fun_scalar_vector  r   r*   c                    \         P                  ! ^V^ ,          ,          \         P                  ! V^ ,          4      R,          \         P                  ! V^ ,          4      .4      P	                  R^4      # r   r   rn   s   &&r(   r   4TestApproxDerivativeLinearOperator.jac_scalar_vector  r   r*   c                    \         P                  ! V^ ,          V^,          ,          4      \         P                  ! V^ ,          4      ,          # ry   r   rn   s   &&r(   r   4TestApproxDerivativeLinearOperator.fun_vector_scalar  r   r*   c           	        \         P                  ! V^,          \         P                  ! V^ ,          V^,          ,          4      ,          \         P                  ! V^ ,          4      ,          \         P                  ! V^ ,          V^,          ,          4      V^ ,          ,          ,           V^ ,          \         P                  ! V^ ,          V^,          ,          4      ,          \         P                  ! V^ ,          4      ,          .4      # r   r   rn   s   &&r(   r   4TestApproxDerivativeLinearOperator.jac_vector_scalar  r   r*   c                   \         P                  ! V^ ,          \         P                  ! V^,          4      ,          V^,          \         P                  ! V^ ,          4      ,          V^ ,          ^,          V^,          R,          ,          .4      # r   r   rn   s   &&r(   r   4TestApproxDerivativeLinearOperator.fun_vector_vector  r   r*   c                   \         P                  ! \         P                  ! V^,          4      V^ ,          \         P                  ! V^,          4      ,          .V^,          ) \         P                  ! V^ ,          4      ,          \         P                  ! V^ ,          4      .^V^ ,          ^,          ,          V^,          R,          ,          RV^ ,          ^,          ,          V^,          R,          ,          ..4      # r   r   rn   s   &&r(   r   4TestApproxDerivativeLinearOperator.jac_vector_vector  r   r*   c                   R p\        V P                  VRRR7      p\        V P                  VRR7      p\        V P                  VRRR7      pV P                  V4      p\        P                  P                  R4      p\        ^
4       F  pVP                  R^
RR7      p\        VP                  V4      WX,          RR	7       \        VP                  V4      WX,          R
R	7       \        VP                  V4      WX,          R
R	7       K  	  R# )r   r,   Tr9   as_linear_operatorr  r/      nV)rC  r  r   h㈵>Nr   )
r   rp   rv   r   r\  r]  r  uniformr   dot	rG   rH   r   r   r   r   r`  r  r:  s	   &        r(   r   5TestApproxDerivativeLinearOperator.test_scalar_scalar  s    &t'='=r.7:>@
 't'='=r:>@
&t'='=r.2:>@
 ))"-ii##N3rAC$/AJNN1-xz!%'JNN1-xz!%'JNN1-xz!%' r*   c                z   R p\        V P                  VRRR7      p\        V P                  VRR7      p\        V P                  VRRR7      pV P                  \        P                  ! V4      4      p\        P
                  P                  R4      p\        ^
4       F  pVP                  R^
RR7      p\        VP                  V4      VP                  V4      RR	7       \        VP                  V4      VP                  V4      R
R	7       \        VP                  V4      VP                  V4      R
R	7       K  	  R# )r-   r,   Tr  r  r/   r  r  r  r   r  Nr  r   )r   r}   r   r   r   r\  r]  r  r  r   r  r  s	   &        r(   r   5TestApproxDerivativeLinearOperator.test_scalar_vector  s   &t'='=r.7:>@
 't'='=r:>@
&t'='=r.2:>@
 ))"--*;<ii##N3rAC$/AJNN1-x||A!%'JNN1-x||A!%'JNN1-x||A!%' r*   c           	     
   \         P                  ! R R.4      p\        V P                  VRRR7      p\        V P                  VRR7      p\        V P                  VRRR7      pV P	                  V4      p\         P
                  P                  R4      p\        ^
4       F  pVP                  R^
VP                  R7      p\        VP                  V4      \         P                  ! VP                  V4      4      RR	7       \        VP                  V4      \         P                  ! VP                  V4      4      R
R	7       \        VP                  V4      \         P                  ! VP                  V4      4      RR	7       K  	  R# )r  r,   Tr  r  r/   r  r  r  r   r  r  Nr   r  )r   r   r   r   r   r\  r]  r  r  shaper   r  r   r  s	   &        r(   r  5TestApproxDerivativeLinearOperator.test_vector_scalar
  s+   XXudm$&t'='=r.7:>@
 't'='=r:>@
&t'='=r.2:>@
 ))"-ii##N3rAC"((3AJNN1-r}}X\\!_/M!%'JNN1-r}}X\\!_/M!%'JNN1-r}}X\\!_/M!%' r*   c                   \         P                  ! RR.4      p\        V P                  VRRR7      p\        V P                  VRR7      p\        V P                  VRRR7      pV P	                  V4      p\         P
                  P                  R4      p\        ^
4       F  pVP                  R^
VP                  R7      p\        VP                  V4      VP                  V4      R	R
7       \        VP                  V4      VP                  V4      RR
7       \        VP                  V4      VP                  V4      RR
7       K  	  R# )r  r  r,   Tr  r  r/   r  r  r  r   r   r  Nr  r  )r   r   r   r   r   r\  r]  r  r  r  r   r  r  s	   &        r(   r  5TestApproxDerivativeLinearOperator.test_vector_vector  s   XXvsm$&t'='=r.7:>@
 't'='=r:>@
&t'='=r.2:>@
 ))"-ii##N3rAC"((3AJNN1-x||ATJJNN1-x||ATJJNN1-x||ATJ	 r*   c           	         \         P                  ! RR.4      p\        \        \        V P
                  VR^\         P                  3R7       R# )r  r  r,   r$  Nr  )r   r   r  r  r   r   rE   )rG   rH   s   & r(   test_exception1TestApproxDerivativeLinearOperator.test_exception1  s9    XXvsm$j"3,,b&266{	<r*   r_   N)r`   ra   rb   rc   rp   rv   r}   r   r   r   r   r   r   r   r  r  r  rd   re   rf   s   @r(   r  r    sM     ?I2'*'*'*K$< <r*   r  c                     R  p \        V RR.RRR7      p\        VRR.4       \        V RR.RR	R7      p\        VRR.4       \        V RR.RRR.R7      p\        VRR.4       \        V RR.RRR	.R7      p\        VRR.4       \        V RR.RR	R.R7      p\        VRR.4       \        V RR.RR\        P                  ) R3R7      p\        VRR.4       \        V RR.RR	R\        P                  3R7      p\        VRR.4       R# )
c                     \         P                  ! V ^ ,          ^,           4      ) \         P                  ! V ^,          ^,           4      ,           # ry   )r   rU   rL  s   &r(   rM  "test_absolute_step_sign.<locals>.fA  s2    qtax  266!A$(#333r*   r,   r   r   r   )r9   r   r  NrS   r  r1  )r   r   r   rE   )rM  grads     r(   test_absolute_step_signr  8  s;   4 QRTJDD4+& QRUKDD3+& 	B8ItD D4+& 	B8IuD D4,'	B8ID D3*% 	B8I}D D3+&	B8Ir266lD D4+&r*   c                     . ROp \         P                  ! . RO4      p\         P                  ! \         P                  4      P                  pR VR,          RVR	,          RVR,          /p\         P                  ! R4      pV  F  pW5,          p\         P                  ! VVR,          VR,          V\         P
                  ! V^,          4      ,          .4      p\        RWV4      p\        W4       V) ^ 8  P                  \        4      ^,          ^,
          p	\        RV) WE4      p\        WV,          4       K  	  \         P                  ! . R
O4      p\         P                  ! V^ ,          V^ ,          ,          VR ,          V^,          R,          V^,          \         P
                  ! V^,          4      ,          .4      p\        WaVR 4      p\        W4       V) ^ 8  P                  \        4      ^,          ^,
          p	\        Wa) VR 4      p\        WV,          4       \         P                  ! . RO\         P                  R7      p\        RWR4      pVP                  \         P                  8X  g   Q h\        RWR 4      pVP                  \         P                  8X  g   Q h\         P                  ! . RO\         P                  R7      p\        RWR4      pVP                  \         P                  8X  g   Q h\        RWR 4      pVP                  \         P                  8X  g   Q h\         P                  ! . RO\         P                  R7      p\         P                  ! R\         P                  R7      p\        WaVR 4      pVP                  \         P                  8X  g   Q h\         P                  ! . RO\         P                  R7      p\        WaVR 4      pVP                  \         P                  8X  g   Q h\         P                  ! . RO\         P                  R7      p\        WaVR 4      pVP                  \         P                  8X  g   Q hR# )r,   r.   r/   r-   r   NrA  r1   )r  r   r   g     j@r0   )rR   r   
   d   )rR   r   r   2   )rD  r   r   r  )r   r   r2   r3   r4   rU   r   r   rG  floatr6   rB  r_  )
methodsrH   r7   r8   r  r9   r  correct_stepr   sign_x0s
             r(   test__compute_absolute_stepr  m  s+   *G	#	$B
((2::

"
"C383:c3hM
 
#B (xx!)B!)B!)BFF2a5M!9!; <
 *$?/3!8##E*Q.2)$R@L"89  xx)*H88Xa[2a50*95%a[2-%a[266"Q%=8: ;L
 &hB	BHH+sax&*Q.G%hRCHH45 
#2::	6B%dBI>H>>RZZ'''%dBI>H>>RZZ'''	/	4B%dBI>H>>RZZ'''%dBI>H>>RZZ'''	""**	5B	#RZZ	(B%hB	BH>>RZZ'''	#2::	6B%hB	BH>>RZZ'''	""**	5B%hB	BH>>RZZ'''r*   )&r   	itertoolsr   numpyr   numpy.testingr   r   r   rx  r   r  scipy._lib._utilr   r	   scipy.sparser
   r   r   scipy._lib._array_apir   scipy.optimize._numdiffr   r   r   r   r   r   scipy.optimizer   r)   r:   r<   ri   r}  r  r  r  r_   r*   r(   <module>r     s       @ @  * ? 8 8 0< < !%8!
HG9 G9Tz! z!z\! \!~|< |<~2'jC(r*   