L i=ddlmZddlmZddlZddlmZmZeje jZ dZ dZdZdZd Zd ZGd d Ze d zZe dzZe dzZde zZdZdZddZdZdZy))groupby)warnN)find coo_matrixcr|dkr td|tj||z kDr td|S)z.Assert that first_step is valid and return it.rz`first_step` must be positive.z`first_step` exceeds bounds.) ValueErrornpabs) first_stept0t_bounds a/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/scipy/integrate/_ivp/common.pyvalidate_first_stepr s<Q9::BFF7R<((788 c&|dkr td|S)z,Assert that max_Step is valid and return it.rz`max_step` must be positive.)r)max_steps rvalidate_max_steprs1}788 OrcX|r(tddjd|Dddyy)aeDisplay a warning for extraneous keyword arguments. The initializer of each solver class is expected to collect keyword arguments that it doesn't understand and warn about them. This function prints a warning for each key in the supplied dictionary. Parameters ---------- extraneous : dict Extraneous keyword arguments zz"warn_extraneous..(s7qAaS(7s. stacklevelN)rjoin) extraneouss rwarn_extraneousr!s6 K 7J778; rcvtj|dtzkr5tddtzddtj|dtz}tj |}|j dkDr|j|fk7r tdtj|dkr td||fS) zValidate tolerance values.dzNAt least one element of `rtol` is too small. Setting `rtol = np.maximum(rtol, z)`.rrrz`atol` has wrong shape.z`atol` must be positive.) r anyEPSrmaximumasarrayndimshaper)rtolatolns r validate_tolr-,s vvdS3Y 114s 3@ zz$c * ::d D yy1}t+233 vvdQh344 :rc`tjj||jdzz S)zCompute RMS norm.?)r linalgnormsize)rs rr1r1?s" 99>>! qvv} ,,rc |jdk(rtjSt||z } | dk(ry| tj||zz} t || z } t || z } | dks| dkrd}nd| z| z }t || }|||z|zz}||||zz|}t ||z | z |z }| dkr|dkrt d|dz}ndt | |z d|dzz z}t d |z|| |S) aEmpirically select a good initial step. The algorithm is described in [1]_. Parameters ---------- fun : callable Right-hand side of the system. t0 : float Initial value of the independent variable. y0 : ndarray, shape (n,) Initial value of the dependent variable. t_bound : float End-point of integration interval; used to ensure that t0+step<=tbound and that fun is only evaluated in the interval [t0,tbound] max_step : float Maximum allowable step size. f0 : ndarray, shape (n,) Initial value of the derivative, i.e., ``fun(t0, y0)``. direction : float Integration direction. order : float Error estimator order. It means that the error controlled by the algorithm is proportional to ``step_size ** (order + 1)`. rtol : float Desired relative tolerance. atol : float Desired absolute tolerance. Returns ------- h_abs : float Absolute value of the suggested initial step. References ---------- .. [1] E. Hairer, S. P. Norsett G. Wanner, "Solving Ordinary Differential Equations I: Nonstiff Problems", Sec. II.4. rggh㈵>gư>g{Gz?gV瞯2U8??4>>8$))LA !"A37??Q3FDOOa//0~~*X5H  %h/ $NGU#c$u+&66I*!!'*8K +JKA IIaL#K  $ YYr] 7 ^ rN)F)__name__ __module__ __qualname____doc__r\rcrsrrrrHrHs#H&8 -+rrHg?g?g?g@@ g?c tj|}|jd}|dk(rtjd|fS|tj|t dz}n|j }dtj|dk\jtzdz }|tj|tj|z} ||| zz|z } tj| dk(dD];} | | dk(s || xxdzcc<|| || | | zz|| z | | <| | dk(r0=|t||||| || S|\} } t||||| || | | S)aAFinite differences Jacobian approximation tailored for ODE solvers. This function computes finite difference approximation to the Jacobian matrix of `fun` with respect to `y` using forward differences. The Jacobian matrix has shape (n, n) and its element (i, j) is equal to ``d f_i / d y_j``. A special feature of this function is the ability to correct the step size from iteration to iteration. The main idea is to keep the finite difference significantly separated from its round-off error which approximately equals ``EPS * np.abs(f)``. It reduces a possibility of a huge error and assures that the estimated derivative are reasonably close to the true values (i.e., the finite difference approximation is at least qualitatively reflects the structure of the true Jacobian). Parameters ---------- fun : callable Right-hand side of the system implemented in a vectorized fashion. t : float Current time. y : ndarray, shape (n,) Current state. f : ndarray, shape (n,) Value of the right hand side at (t, y). threshold : float Threshold for `y` value used for computing the step size as ``factor * np.maximum(np.abs(y), threshold)``. Typically, the value of absolute tolerance (atol) for a solver should be passed as `threshold`. factor : ndarray with shape (n,) or None Factor to use for computing the step size. Pass None for the very evaluation, then use the value returned from this function. sparsity : tuple (structure, groups) or None Sparsity structure of the Jacobian, `structure` must be csc_matrix. Returns ------- J : ndarray or csc_matrix, shape (n, n) Jacobian matrix. factor : ndarray, shape (n,) Suggested `factor` for the next evaluation. r)rrr/rJr4rx)r r'r)emptyfullr%copyrealastypefloatr&r nonzero_dense_num_jac_sparse_num_jac)r8r`rrf thresholdfactorsparsityr,f_signy_scalehi structuregroupss rnum_jacr spV 1 A  AAvxx'' ~C3J' "''!*/))%0 01 4Frzz)RVVAY77G Vg  "AZZQ  ":dai 1IOIaD6!9wqz11QqT9AaDdai: c1aAvw??$ 6sAq!Q(&2 2rc|jd}tj|}|||dddf|z} | |dddfz } tjtj| d} tj |} tj| | | f} tj tj|| tj| | | f}| t|zk}tj|rtj|\}t||z}|||||zz||z }||||f<|||dddf|dd|fz} | |dddfz }tjtj|d} tj |jd} tj|| | f}tj tj|| tj| | | f}| ||z|||zk}tj|rLtj|\}||}||||<||||<|dd|f| dd|f<||||<||| |<| |z} || t|zkxxtzcc<|| t|zkDxxtzcc<tj |t}| |fS)Nraxis)r)r diagargmaxr rgr&NUM_JAC_DIFF_REJECTr$rNUM_JAC_FACTOR_INCREASENUM_JAC_DIFF_SMALLNUM_JAC_DIFF_BIGNUM_JAC_FACTOR_DECREASENUM_JAC_MIN_FACTOR)r8r`rrrrrrr,h_vecsf_newrNmax_indrmax_diffr>diff_too_smallra new_factorh_newdiff_new max_diff_new scale_newupdate update_inds rrrWs  A WWQZF 1QW:& 'E 1QW: Diit 1-G ! Avvd7A:&'H JJrvvaj)266% 2C+D EE 3e ;;N vvnzz.),vc{: 3*ws|33qv= sCxAqDzF1c6N231QW:%))BFF8,15 IIciil #vvhwz23 JJrvvaj1266% :K3LM #*\E#J-FF 66&>jj(GFVJ!+F!3F: !&MAjM"*1f9"5DJ  )& 1E* #/#7HZ AID 8(50 015LL1 8&. ./3JJ/ ZZ 2 3F <rc  |jd} tj|dz} tj| | f} t | D] } tj | |} || z| | <"| j } |||dddf| z}||dddfz }t|\}}}t||||f||ff| | fj}tjt|jdj}tj| }tjtj|||fj}tj tj||tj||||f}|t"|zk}tj$|rtj&|\}t(||z}|||||zz||z }tj*| }|||<tj,||}tj| t.}tj|jd| f} t1|D](\}} tj | |} || z| |<||| <*| j } |||dddf| z}||dddfz }t|dd|f\}}}t||||||f||ff| |jdfj} tjt| jdj}!tj|jd}tjtj| |!|fj}"tj tj||!tj||!|||f}#|||#z|"||zk}$tj$|$rLtj&|$\}$||$}%||$||%<||$||%<| dd|$f|dd|%f<|#|$||%<|"|$||%<|xj2tj4|tj6|j8zc_||t:|zkxxt(zcc<||t<|zkDxxt>zcc<tj |t@}||fS)Nrr4)r)r)dtype)!r)r r7rzrangeequalTrrtocscarrayr rravelrgr'r&rr$rrzerosuniqueint enumeratedatarepeatrNindptrrrrr)&r8r`rrrrrrrrr,n_groupsrrperdfrj_rNrrrr>rrarr h_new_all groups_unique groups_mapkr max_ind_newrrrrs& rrrs  Avvf~!H XXxm $Fx HHUF #Au XXF 1QW:& 'E 1d7 B9oGAq! r!VAY,'!Q0A ? E E GDhhs4y''Q'/0668G ! Azz"&&gqj!12399;H JJrvvaj)vveGVAY$678 :E 3e ;;N vvnzz.),vc{: 3*ws|33qv=HHQK  # &+. XXhc2 =..q1156!-0 "HAu'A!A F1I !Ju  "AqDzF*+ Qq$wZ yC()1ar!Zs1v%?"?@ !1v'/0#))A,.?AAF hhs8}333;<BBD IIciil #zz"&&+q.)A"BCIIK JJ FF1[> " FF5j&==> ?A #*\E#J-FF 66&>jj(GFVJ!+F!3F: !&MAjM"*1f9"5DJ  )& 1E* #/#7HZ II1bggdkk233I 8(50 015LL1 8&. ./3JJ/ ZZ 2 3F <r)N) itertoolsrwarningsrnumpyr scipy.sparserrfinforepsr%rrr!r-r1rFrHrrrrrrrrrrrrrs)bhhuo$&- B8JxxvUlD[$;3YH2V'TBr