a
    5gh                     @  s  d Z ddlmZ ddlZddlmZ ddlmZ ddlm	Z	m
Z
mZ ddlmZmZmZmZ ddlmZmZmZ ddlZdd	lmZmZ dd
lmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z* ddl+Z+ddl,m-Z- ddl.Z.ddl/Z/e'dZ0dZ1G dd de+j2Z3dddddZ4G dd de3Z5G dd de3Z6G dd de3Z7G dd de3Z8dddd d!Z9G d"d# d#ej:Z;G d$d% d%Z<G d&d' d'Z=G d(d) d)e>Z?G d*d+ d+Z@G d,d- d-eZAeBd.d/d0d1d2d3d4d5ZCG d6d7 d7ZDeBd8d9d:d;d<d=ZEd/d>d>d/d?d@dAZFddCdDdEdFdGdHZGed/dIdJdKdLZHed/dDdMdNdOdLZHdBddPdLZHdQdR ZIdSdT ZJdUdV ZKdWdXdYdZd[ZLd\d\d]d^d_ZMd`dadbdcdddeZNd`dfddcdgdhZOd`didjdcdkdlZPdddmdndoZQdpdq ZRdrdddsdtduZSG dvdw dwZTdxdy ZUdd}d~ZVddDdddZWdddmddZXddDdddZYdDdddZZd\d\dddZ[d\d\d\d\dddZ\dS )z
Data classes and utilities used by :class:`iminuit.Minuit`.

You can look up the interface of data classes that iminuit uses here.
    annotationsN)OrderedDict)	Namespace)
_repr_html
_repr_text_deprecated)Key	UserBoundCostCostGradient)IMinuitWarningHesseFailedWarningPerformanceWarning)NDArray	ArrayLike)overloadAnyListUnionDictIterable	GeneratorTupleOptionalCallable
CollectionSequenceTypeVar	Annotatedget_args
get_origin)	monotonicT)r   r   r   	ValueView	FixedView	LimitViewMatrixFMinParamParamsMErrorMErrorsmake_func_codemake_with_signaturemerge_signaturesdescribegradientis_positive_definitec                   @  s   e Zd ZdZdZd)dddddZd	d
ddZdd
ddZej	dddddZ
ej	ddddddZdddddZddddddZdddd d!Zd"d
d#d$Zd%d
d&d'Zd(S )*	BasicViewz
    Array-like view of parameter state.

    Derived classes need to implement methods _set and _get to access
    specific properties of the parameter state.

    :meta private:
    _minuit_ndimr   r   int)minuitndimc                 C  s   || _ || _d S Nr4   )selfr8   r9    r<   \/mounts/lovelace/software/anaconda3/envs/metaDMG/lib/python3.9/site-packages/iminuit/util.py__init__K   s    zBasicView.__init__r   returnc                 c  s"   t t| D ]}| |V  qdS )zGet iterator over values.N)rangelen_getr;   ir<   r<   r=   __iter__P   s    zBasicView.__iter__c                 C  s   | j jS )zGet number of paramters.)r5   Znparr;   r<   r<   r=   __len__U   s    zBasicView.__len__)idxr@   c                 C  s   t S r:   NotImplemented)r;   rI   r<   r<   r=   rC   Y   s    zBasicView._getNone)rI   valuer@   c                 C  s   t  d S r:   rJ   )r;   rI   rM   r<   r<   r=   _set]   s    zBasicView._setr	   keyr@   c                   s4   t  jj|}t|tr* fdd|D S  |S )a  
        Get values of the view.

        Parameters
        ----------
        key: int, str, slice, list of int or str
            If the key is an int or str, return corresponding value.
            If it is a slice, list of int or str, return the corresponding subset.
        c                   s   g | ]}  |qS r<   rC   .0rE   rG   r<   r=   
<listcomp>m       z)BasicView.__getitem__.<locals>.<listcomp>)
_key2indexr5   _var2pos
isinstancelistrC   )r;   rP   indexr<   rG   r=   __getitem__a   s    

zBasicView.__getitem__)rP   rM   r@   c                 C  s   | j   t| j j|}t|trt|| jkrH|D ]}| || q4qt|t|kr`t	dt
||D ]\}}| || qjn| || dS )zFAssign new value at key, which can be index, parameter name, or slice.z'length of argument does not match sliceN)r5   Z_copy_state_if_neededrV   rW   rX   rY   r6   rN   rB   
ValueErrorzip)r;   rP   rM   rZ   rE   vr<   r<   r=   __setitem__p   s    

zBasicView.__setitem__objectboolotherr@   c                 C  s"   t | |\}}tt ||kS )z$Return true if all values are equal.)npZbroadcast_arraysra   all)r;   rc   abr<   r<   r=   __eq__   s    zBasicView.__eq__strc                 C  sF   d| j j }t| jj| D ]\}}|d| d| 7 }q|d7 }|S )!Get detailed text representation.< =>)	__class____name__r]   r5   _pos2var)r;   skr^   r<   r<   r=   __repr__   s
    zBasicView.__repr__zDict[str, float]c                   s    fddt  jjD S )zObtain dict representation.c                   s   i | ]\}}|  |qS r<   rQ   )rS   rE   rs   rG   r<   r=   
<dictcomp>   rU   z%BasicView.to_dict.<locals>.<dictcomp>)	enumerater5   rq   rG   r<   rG   r=   to_dict   s    zBasicView.to_dictN)r   )rp   
__module____qualname____doc__	__slots__r>   rF   rH   abcabstractmethodrC   rN   r[   r_   rh   rt   rw   r<   r<   r<   r=   r3   ?   s   	r3   r   r7   objr@   c                 C  s8   d}t | tr4|d7 }| D ]}|d ur|}  qqq4q|S )Nr      rX   r   )r   ndxr<   r<   r=   r6      s    
r6   c                   @  s2   e Zd ZdZdddddZddddd	d
ZdS )r$   z$Array-like view of parameter values.r7   floatrE   r@   c                 C  s   | j j| jS r:   )r5   _last_staterM   rD   r<   r<   r=   rC      s    zValueView._getrL   rE   rM   r@   c                 C  s   | j j|| d S r:   )r5   r   	set_valuer;   rE   rM   r<   r<   r=   rN      s    zValueView._setNrp   rx   ry   rz   rC   rN   r<   r<   r<   r=   r$      s   r$   c                   @  s2   e Zd ZdZdddddZddddd	d
ZdS )	ErrorViewz$Array-like view of parameter errors.r7   r   r   c                 C  s   | j j| jS r:   )r5   r   errorrD   r<   r<   r=   rC      s    zErrorView._getrL   r   c                 C  s0   |dkrt dt t|}| jj|| d S )Nr   zRAssigned errors must be positive. Non-positive values are replaced by a heuristic.)warningswarnr   _guess_initial_stepr5   r   	set_errorr   r<   r<   r=   rN      s    zErrorView._setNr   r<   r<   r<   r=   r      s   r   c                   @  s@   e Zd ZdZdddddZddddd	d
ZddddZdS )r%   z0Array-like view of whether parameters are fixed.r7   ra   r   c                 C  s   | j j| jS r:   )r5   r   is_fixedrD   r<   r<   r=   rC      s    zFixedView._getrL   )rE   fixr@   c                 C  s&   |r| j j| n| j j| d S r:   )r5   r   r   release)r;   rE   r   r<   r<   r=   rN      s    zFixedView._setrY   r?   c                   s    fddt t D S )z#Return list with inverted elements.c                   s   g | ]}  | qS r<   rQ   rR   rG   r<   r=   rT      rU   z(FixedView.__invert__.<locals>.<listcomp>)rA   rB   rG   r<   rG   r=   
__invert__   s    zFixedView.__invert__N)rp   rx   ry   rz   rC   rN   r   r<   r<   r<   r=   r%      s   r%   c                      sH   e Zd ZdZdd fddZdddd	d
ZddddddZ  ZS )r&   z$Array-like view of parameter limits.r   )r8   c                   s   t t| |d d S )Nr   )superr&   r>   )r;   r8   ro   r<   r=   r>      s    zLimitView.__init__r7   Tuple[float, float]r   c                 C  s2   | j j| }|jr|jntj |jr*|jntjfS r:   )r5   r   has_lower_limitlower_limitrd   infhas_upper_limitupper_limit)r;   rE   pr<   r<   r=   rC      s    zLimitView._getr
   rL   )rE   argr@   c                 C  s   | j j}|| j}|| j}|| t|\}}|tj krl|tjkrl||kr\|| q|	||| n0|tj kr|
|| n|tjkr||| ||k r|}n||kr|}||| ||| d S r:   )r5   r   rM   r   Zremove_limits_normalize_limitrd   r   r   Z
set_limitsZset_lower_limitZset_upper_limitr   r   )r;   rE   r   statevalerrlowhighr<   r<   r=   rN      s&    



zLimitView._set)rp   rx   ry   rz   r>   rC   rN   __classcell__r<   r<   r   r=   r&      s   r&   zOptional[Iterable]r   )limr@   c                 C  s\   | d u rt j t jfS | \}}|d u r.t j }|d u r<t j}||krTtd| d||fS )Nzlimit z is invalid)rd   r   r\   )r   rf   rg   r<   r<   r=   r      s    r   c                      s   e Zd ZdZdZddd fddZddd	d
dZddd fddZddddZddddZ	dd Z
 fddZdd Zdd Zd d! Z fd"d#Z fd$d%Z  ZS )&r'   z
    Enhanced Numpy ndarray.

    Works like a normal ndarray in computations, but also supports pretty printing in
    ipython and Jupyter notebooks. Elements can be accessed via indices or parameter
    names.
    )rW   zUnion[Dict, Tuple]r   )
parametersr@   c                   sZ   t |tr|}n&t |tr.dd t|D }ntdt|}t | ||f}||_|S )Nc                 S  s   i | ]\}}||qS r<   r<   )rS   rE   r   r<   r<   r=   ru     rU   z"Matrix.__new__.<locals>.<dictcomp>z parameters must be tuple or dict)	rX   dicttuplerv   	TypeErrorrB   r   __new__rW   )clsr   var2posnr   r   r<   r=   r   
  s    

zMatrix.__new__rL   r~   c                 C  s"   |du ri | _ nt|di | _ dS )zFor internal use.NrW   )rW   getattr)r;   r   r<   r<   r=   __array_finalize__  s    zMatrix.__array_finalize__z3Union[Key, Tuple[Key, Key], Iterable[Key], NDArray]r   rO   c                   s   | j  fdd t|tr6 |}t ||fS t|ttfrTt  |S t|trt|tj	s fdd|D }t |j
}tj	||j
S t |S )zGet matrix element at key.c                   sZ   t | tr|  S t | tr6t | j | j| jS t | trVt fdd| D S | S )Nc                 3  s   | ]} |V  qd S r:   r<   rS   rs   trafor<   r=   	<genexpr>+  rU   z4Matrix.__getitem__.<locals>.trafo.<locals>.<genexpr>)rX   ri   slicestartstopstepr   rP   r   r   r<   r=   r   %  s    


z!Matrix.__getitem__.<locals>.trafoc                   s   g | ]} |qS r<   r<   r   r   r<   r=   rT   6  rU   z&Matrix.__getitem__.<locals>.<listcomp>)rW   rX   r   r   r[   ri   r   r   rd   ndarrayr#   )r;   rP   slindex2tr   r   r=   r[     s    	
zMatrix.__getitem__zDict[Tuple[str, str], float]r?   c                 C  sX   t | j}i }t|D ]<\}}t|t|D ]$}|| }t| ||f |||f< q,q|S )z
        Convert matrix to dict.

        Since the matrix is symmetric, the dict only contains the upper triangular
        matrix.
        )r   rW   rv   rA   rB   r   )r;   namesdrE   pijZpjr<   r<   r=   rw   ;  s    
zMatrix.to_dictz'Tuple[List[List[str]], Tuple[str, ...]]c                   s`   t | j}t| g }t| t|D ].\ }||g fddtD   q(||fS )a  
        Convert matrix to tabular format.

        The output is consumable by the external
        `tabulate <https://pypi.org/project/tabulate>`_ module.

        Examples
        --------
        >>> import tabulate as tab
        >>> from iminuit import Minuit
        >>> m = Minuit(lambda x, y: x ** 2 + y ** 2, x=1, y=2).migrad()
        >>> tab.tabulate(*m.covariance.to_table())
              x    y
        --  ---  ---
        x     1   -0
        y    -0    4
        c                   s   g | ]}  |  qS r<   r<   )rS   r   rE   r   Znumsr<   r=   rT   a  rU   z#Matrix.to_table.<locals>.<listcomp>)r   rW   r   Zmatrix_formatrB   rv   appendrA   )r;   r   tabnamer<   r   r=   to_tableJ  s    

(zMatrix.to_tablec                 C  s.   |   }t|d }|t||d  }|S )z
        Compute and return correlation matrix.

        If the matrix is already a correlation matrix, this effectively returns a copy
        of the original matrix.
              ?g0.++)copyrd   diagouter)r;   rf   r   r<   r<   r=   correlationd  s    zMatrix.correlationc                   s   t t|  S )rj   )r   r'   __str__rG   r   r<   r=   rt   p  s    zMatrix.__repr__c                 C  s   | j dkrt| S t| S )&Get user-friendly text representation.   )r9   reprr   matrixrG   r<   r<   r=   r   t  s    
zMatrix.__str__c                 C  s
   t | S r:   )r   r   rG   r<   r<   r=   _repr_html_z  s    zMatrix._repr_html_c                 C  s"   |r| d n| t|  d S )Nz<Matrix ...>textri   r;   r   cycler<   r<   r=   _repr_pretty_}  s    zMatrix._repr_pretty_c                   s    t   \}}}|||| jffS )z,Get representation for pickling and copying.)r   
__reduce__rW   )r;   Zrestoreargsr   r   r<   r=   r     s    zMatrix.__reduce__c                   s   |\}| _ t | dS )zRestore from pickled state.N)rW   r   __setstate__)r;   r   r   r<   r=   r     s    
zMatrix.__setstate__)rp   rx   ry   rz   r{   r   r   r[   rw   r   r   rt   r   r   r   r   r   r   r<   r<   r   r=   r'      s   r'   c                   @  s  e Zd ZdZdZdddddddddd	Zedd
ddZedd
ddZedd
ddZ	edd
ddZ
edd
ddZedd
ddZedd
ddZedd
ddZedd
ddZedd
ddZedd
d d!Zedd
d"d#Zedd
d$d%Zedd
d&d'Zedd
d(d)Zedd
d*d+Zedd
d,d-Zedd
d.d/Zedd
d0d1Zd2dd3d4d5Zdd
d6d7Zdd
d8d9Zdd
d:d;Zddd<d=d>d?Zd@S )Ar(   a  
    Function minimum view.

    This object provides detailed metadata about the function minimum. Inspect this to
    check what exactly happened if the fit did not converge. Use the attribute
    :attr:`iminuit.Minuit.fmin` to get the best fit values, their uncertainties, or the
    function value at the minimum. For convenience, you can also get a basic OK from
    :class:`iminuit.Minuit` with the methods :attr:`iminuit.Minuit.valid` and
    :attr:`iminuit.Minuit.accurate`.

    See Also
    --------
    :attr:`iminuit.Minuit.values`
    :attr:`iminuit.Minuit.errors`
    :attr:`iminuit.Minuit.merrors`
    :attr:`iminuit.Minuit.covariance`
    :attr:`iminuit.Minuit.fval`
    :attr:`iminuit.Minuit.valid`
    :attr:`iminuit.Minuit.accurate`
    )_src
_algorithm_has_parameters_at_limit_nfcn_ngrad_ndof	_edm_goal_timer   ri   r7   r   )fmin	algorithmnfcnngradndofedm_goaltimec                 C  s   || _ || _d| _|jD ]h}|js|js*q|j}	|j}
|jrB|j	nt
j }|jrV|jnt
j}|  jt|	| ||	 d|
 k O  _q|| _|| _|| _|| _|| _d S )NFr   )r   r   r   r   r   
has_limitsrM   r   r   r   rd   r   r   r   minr   r   r   r   r   )r;   r   r   r   r   r   r   r   mpr^   eZlbZubr<   r<   r=   r>     s     
&zFMin.__init__r?   c                 C  s   | j S )z<Get algorithm that was used to compute the function minimum.)r   rG   r<   r<   r=   r     s    zFMin.algorithmc                 C  s   | j jS )a  
        Get Estimated Distance to Minimum.

        Minuit uses this criterion to determine whether the fit converged. It depends
        on the gradient and the Hessian matrix. It measures how well the current
        second order expansion around the function minimum describes the function, by
        taking the difference between the predicted (based on gradient and Hessian)
        function value at the minimum and the actual value.
        )r   edmrG   r<   r<   r=   r     s    zFMin.edmc                 C  s   | j S )z
        Get EDM threshold value for stopping the minimization.

        The threshold is allowed to be violated by a factor of 10 in some situations.
        )r   rG   r<   r<   r=   r     s    zFMin.edm_goalc                 C  s   | j jS )z'Get cost function value at the minimum.)r   fvalrG   r<   r<   r=   r     s    z	FMin.fvalc                 C  s2   t | jr,| jdkr,| jdkr,| j| j S t jS )u   
        Get χ²/ndof of the fit.

        This returns NaN if the cost function is unbinned, errordef is not 1,
        or if the cost function does not report the degrees of freedom.
        r   r   )rd   isfiniter   errordefr   nanrG   r<   r<   r=   reduced_chi2  s     zFMin.reduced_chi2ra   c                 C  s   | j S )z
        Return whether any bounded parameter was fitted close to a bound.

        The estimated error for the affected parameters is usually off. May be an
        indication to remove or loosen the limits on the affected parameter.
        )r   rG   r<   r<   r=   has_parameters_at_limit  s    zFMin.has_parameters_at_limitc                 C  s   | j S )z$Get number of function calls so far.)r   rG   r<   r<   r=   r     s    z	FMin.nfcnc                 C  s   | j S )z-Get number of function gradient calls so far.)r   rG   r<   r<   r=   r     s    z
FMin.ngradc                 C  s   | j j}|r| jdk rdS |S )a  
        Return whether Migrad converged successfully.

        For it to return True, the following conditions need to be fulfilled:

          - :attr:`has_reached_call_limit` is False
          - :attr:`is_above_max_edm` is False

        Note: The actual verdict is computed inside the Minuit2 C++ code, so we
        cannot guarantee that is_valid is exactly equivalent to these conditions.
        r   F)r   is_validr   )r;   Zvalidr<   r<   r=   r     s    zFMin.is_validc                 C  s   | j S )z
        Return whether parameters are valid.

        This is the same as :attr:`is_valid` and only kept for backward compatibility.
        )r   rG   r<   r<   r=   has_valid_parameters  s    zFMin.has_valid_parametersc                 C  s   | j jS )a  
        Return whether the covariance matrix is accurate.

        While Migrad runs, it computes an approximation to the current Hessian
        matrix. If the strategy is set to 0 or if the fit did not converge, the
        inverse of this approximation is returned instead of the inverse of the
        accurately computed Hessian matrix. This property returns False if the
        approximation has been returned instead of an accurate matrix computed by
        the Hesse method.
        )r   has_accurate_covarrG   r<   r<   r=   r   (  s    zFMin.has_accurate_covarc                 C  s   | j jS )a  
        Return whether the Hessian matrix is positive definite.

        This must be the case if the extremum is a minimum, otherwise it is a saddle
        point. If it returns False, the fitted result may be correct, but the reported
        uncertainties are false. This may affect some parameters or all of them.
        Possible causes:

            * Model contains redundanted parameters that are 100% correlated. Fix:
              remove the parameters that are 100% correlated.
            * Cost function is not computed in double precision. Fix: try adjusting
              :attr:`iminuit.Minuit.precision` or change the cost function to compute
              in double precision.
            * Cost function is not analytical near the minimum. Fix: change the cost
              function to something analytical. Functions are not analytical if:

                * It does computations based on (pseudo)random numbers.
                * It contains vertical steps, for example from code like this::

                      if cond:
                          return value1
                      else:
                          return value2
        )r   has_posdef_covarrG   r<   r<   r=   r   6  s    zFMin.has_posdef_covarc                 C  s   | j jS )as  
        Return whether the matrix was forced to be positive definite.

        While Migrad runs, it computes an approximation to the current Hessian matrix.
        It can happen that this approximation is not positive definite, but that is
        required to compute the next Newton step. Migrad then adds an appropriate
        diagonal matrix to enforce positive definiteness.

        If the fit has converged successfully, this should always return False. If
        Minuit forced the matrix to be positive definite, the parameter uncertainties
        are false, see :attr:`has_posdef_covar` for more details.
        )r   has_made_posdef_covarrG   r<   r<   r=   r   R  s    zFMin.has_made_posdef_covarc                 C  s   | j jS )z-Return whether the last call to Hesse failed.)r   hesse_failedrG   r<   r<   r=   r   b  s    zFMin.hesse_failedc                 C  s   | j jS )z
        Return whether a covariance matrix was computed at all.

        This is false if the Simplex minimization algorithm was used instead of
        Migrad, in which no approximation to the Hessian is computed.
        )r   has_covariancerG   r<   r<   r=   r   g  s    zFMin.has_covariancec                 C  s   | j jS )z
        Return whether the EDM value is below the convergence threshold.

        Returns True, if the fit did not converge; otherwise returns False.
        )r   is_above_max_edmrG   r<   r<   r=   r   q  s    zFMin.is_above_max_edmc                 C  s   | j jS )z
        Return whether Migrad exceeded the allowed number of function calls.

        Returns True true, the fit was stopped before convergence was reached;
        otherwise returns False.
        )r   has_reached_call_limitrG   r<   r<   r=   r   z  s    zFMin.has_reached_call_limitc                 C  s   | j jS )zFEqual to the value of :attr:`iminuit.Minuit.errordef` when Migrad ran.)r   r   rG   r<   r<   r=   r     s    zFMin.errordefc                 C  s   | j S )zRuntime of the last algorithm.)r   rG   r<   r<   r=   r     s    z	FMin.timer`   rb   c                   s0   dddddddt  fddjD S )	z(Return True if all attributes are equal.ri   r`   ra   )rs   rf   rg   r@   c                 S  s:   t || }t || }t|tr2t|r2t|S ||kS r:   )r   rX   r   rd   isnan)rs   rf   rg   r<   r<   r=   relaxed_equal  s
    


z"FMin.__eq__.<locals>.relaxed_equalc                 3  s   | ]}| V  qd S r:   r<   r   rc   r   r;   r<   r=   r     rU   zFMin.__eq__.<locals>.<genexpr>re   r{   r;   rc   r<   r   r=   rh     s    zFMin.__eq__c                 C  sL   d}t t| D ].}|dr qt| |}|d| d|7 }q|d7 }|S )rj   z<FMin_rl   rm   rn   )sorteddir
startswithr   )r;   rr   rP   r   r<   r<   r=   rt     s    

zFMin.__repr__c                 C  s
   t | S r   )r   r   rG   r<   r<   r=   r     s    zFMin.__str__c                 C  s
   t | S r:   )r   r   rG   r<   r<   r=   r     s    zFMin._repr_html_rL   r   r   r@   c                 C  s"   |r| d n| t|  d S )Nz
<FMin ...>r   r   r<   r<   r=   r     s    zFMin._repr_pretty_N)rp   rx   ry   rz   r{   r>   propertyr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rh   rt   r   r   r   r<   r<   r<   r=   r(     s\   			r(   c                   @  s   e Zd ZdZdZddddZddd	d
dZddddZedd Z	edd Z
edd ZddddZddddddZdS )r)   z#Data object for a single Parameter.)	numberr   rM   r   merrorZis_constr   r   r   z;Union[int, str, float, Optional[Tuple[float, float]], bool]r   c                 G  s<   t |t | jksJ t| j|D ]\}}t| || q"d S r:   rB   r{   r]   setattrr;   r   rs   r   r<   r<   r=   r>     s    zParam.__init__r`   ra   rb   c                   s   t  fddjD S )$Return True if all values are equal.c                 3  s"   | ]}t |t  |kV  qd S r:   r   r   rc   r;   r<   r=   r     rU   zParam.__eq__.<locals>.<genexpr>r  r  r<   r  r=   rh     s    zParam.__eq__ri   r?   c                 C  s@   g }| j D ]"}t| |}|| d| q
dd| d S )rj   rm   zParam(z, ))r{   r   r   join)r;   pairsrs   r^   r<   r<   r=   rt     s
    

zParam.__repr__c                 C  s   | j p
| jS )z8Query whether the parameter has an lower or upper limit.)r   r   rG   r<   r<   r=   r     s    zParam.has_limitsc                 C  s
   | j duS )z*Query whether parameter has a lower limit.N)r   rG   r<   r<   r=   r     s    zParam.has_lower_limitc                 C  s
   | j duS )z+Query whether parameter has an upper limit.N)r   rG   r<   r<   r=   r     s    zParam.has_upper_limitc                 C  s   t | gS r  r   paramsrG   r<   r<   r=   r     s    zParam.__str__r   rL   r  c                 C  s"   |r| d n| t|  d S )Nz
Param(...)r   r   r<   r<   r=   r     s    zParam._repr_pretty_N)rp   rx   ry   rz   r{   r>   rh   rt   r	  r   r   r   r   r   r<   r<   r<   r=   r)     s   	


r)   c                      sD   e Zd ZdZdZdd Zdd Z fddZd	d
 Zdd Z	  Z
S )r*   z,Tuple-like holder of parameter data objects.r<   c                 C  s
   t | S r:   )r   r  rG   r<   r<   r=   r     s    zParams._repr_html_c              	   C  s   g d}g }t | D ]\}}|j}||g}|j}|rVtj|j|jg|R  \}}	}
}nt|j|j\}}	d}
d}|||	|
||jdur|j nd|jdur|j nd|j	rdndg7 }|
| q||fS )a  
        Convert parameter data to a tabular format.

        The output is consumable by the external
        `tabulate <https://pypi.org/project/tabulate>`_ module.

        Examples
        --------
        >>> import tabulate as tab
        >>> from iminuit import Minuit
        >>> m = Minuit(lambda x, y: x ** 2 + (y / 2) ** 2 + 1, x=0, y=0)
        >>> m.fixed["x"] = True
        >>> m.migrad().minos()
        >>> tab.tabulate(*m.params.to_table())
          pos  name      value    error  error-    error+    limit-    limit+    fixed
        -----  ------  -------  -------  --------  --------  --------  --------  -------
            0  x             0      0.1                                          yes
            1  y             0      1.4  -1.0      1.0
        )	posr   rM   r   zerror-zerror+zlimit-zlimit+fixed Nyes)rv   r   r  r   Z
pdg_formatrM   r   r   r   r   r   )r;   headerr   rE   r   r   rowmer   r   ZmelZmeur<   r<   r=   r     s,    "	zParams.to_tablec                   s>   t |tr.t| D ]\}}|j|kr q*q|}tt| |S );Get item at key, which can be an index or a parameter name.)rX   ri   rv   r   r   r*   r[   )r;   rP   rE   r   r   r<   r=   r[   /  s    

zParams.__getitem__c                 C  s
   t | S r  r  rG   r<   r<   r=   r   8  s    zParams.__str__c                 C  s"   |r| d n| t|  d S )NzParams(...)r   r   r<   r<   r=   r   <  s    zParams._repr_pretty_)rp   rx   ry   rz   r{   r   r   r[   r   r   r   r<   r<   r   r=   r*     s   6	r*   c                   @  sn   e Zd ZdZdZddddZddd	d
dZddddZddddZddddZ	ddddddZ
dS )r+   a*  
    Minos data object.

    Attributes
    ----------
    number : int
        Parameter index.
    name : str
        Parameter name.
    lower : float
        Lower error.
    upper : float
        Upper error.
    is_valid : bool
        Whether Minos computation was successful.
    lower_valid : bool
        Whether downward scan was successful.
    upper_valid : bool
        Whether upward scan was successful.
    at_lower_limit : bool
        Whether scan reached lower limit.
    at_upper_limit : bool
        Whether scan reached upper limit.
    at_lower_max_fcn : bool
        Whether allowed number of function evaluations was exhausted.
    at_upper_max_fcn : bool
        Whether allowed number of function evaluations was exhausted.
    lower_new_min : float
        Parameter value for new minimum, if one was found in downward scan.
    upper_new_min : float
        Parameter value for new minimum, if one was found in upward scan.
    nfcn : int
        Number of function calls.
    min : float
        Function value at the new minimum.
    )r
  r   lowerupperr   Zlower_validZupper_validZat_lower_limitZat_upper_limitZat_lower_max_fcnZat_upper_max_fcnZlower_new_minZupper_new_minr   r   zUnion[int, str, float, bool]r  c                 G  s<   t |t | jksJ t| j|D ]\}}t| || q"d S r:   r  r  r<   r<   r=   r>   {  s    zMError.__init__r`   ra   rb   c                   s   t  fddjD S )r  c                 3  s"   | ]}t |t  |kV  qd S r:   r  r   r  r<   r=   r     rU   z MError.__eq__.<locals>.<genexpr>r  r  r<   r  r=   rh     s    zMError.__eq__ri   r?   c                 C  sB   d}t | jD ]&\}}t| |}|d| d|7 }q|d7 }|S )rj   z<MErrorrl   rm   rn   )rv   r{   r   )r;   rr   rI   rs   r^   r<   r<   r=   rt     s    
zMError.__repr__c                 C  s   t d| iS )r   Nr   merrorsrG   r<   r<   r=   r     s    zMError.__str__c                 C  s   t d | iS r:   r   r#  rG   r<   r<   r=   r     s    zMError._repr_html_r   rL   r  c                 C  s"   |r| d n| t|  d S )Nz<MError ...>r   r   r<   r<   r=   r     s    zMError._repr_pretty_N)rp   rx   ry   rz   r{   r>   rh   rt   r   r   r   r<   r<   r<   r=   r+   C  s   %	r+   c                   @  s<   e Zd ZdZdZdd Zdd Zdd Zd	d
 Zdd Z	dS )r,   z9Dict-like map from parameter name to Minos result object.r<   c                 C  s
   t | S r:   r$  rG   r<   r<   r=   r     s    zMErrors._repr_html_c                 C  s    dd dd |  D  d S )rj   z<MErrors
  z,
  c                 s  s   | ]}t |V  qd S r:   )r   rS   r   r<   r<   r=   r     rU   z#MErrors.__repr__.<locals>.<genexpr>z
>)r  valuesrG   r<   r<   r=   rt     s    zMErrors.__repr__c                 C  s
   t | S r  r"  rG   r<   r<   r=   r     s    zMErrors.__str__c                 C  s"   |r| d n| t|  d S )Nz<MErrors ...>r   r   r<   r<   r=   r     s    zMErrors._repr_pretty_c                 C  sh   t |tr\|dk r|t| 7 }|dk s2|t| kr:tdt| D ]\}}||krB qXqB|}t| |S )r  r   zindex out of range)rX   r7   rB   
IndexErrorrv   r   r[   )r;   rP   rE   rs   r<   r<   r=   r[     s    
zMErrors.__getitem__N)
rp   rx   ry   rz   r{   r   rt   r   r   r[   r<   r<   r<   r=   r,     s   r,   z0use jacobi.propagate instead from jacobi libraryr   zCollection[float]zCollection[Collection[float]]zTuple[NDArray, NDArray])fnr   covr@   c                 C  s   ddl m} t|}t|dkr,tdt|}|jd |jd krRtdd}t|| d }t	|dks~td	| |}t||| |}	t
d
|	|	|}
|t|dkrt|
n|
fS )a  
    Numerically propagates the covariance into a new space.

    This function is deprecated and will be removed. Please use jacobi.propagate from
    the jacobi library, which is more accurate. The signatures of the two functions are
    compatible, so it is a drop-in replacement.

    Parameters
    ----------
    fn: callable
        Vectorized function that computes y = fn(x).
    x: array-like with shape (N,)
        Input vector.
    cov: array-like with shape (N, N)
        Covariance matrix of input vector.

    Returns
    -------
    y, ycov
        y is the result of fn(x)
        ycov is the propagated covariance matrix.
    r   )approx_fprimer   zcov must be 2D array-liker   zcov must have shape (N, N)g|=r   z;diagonal elements of covariance matrix must be non-negativezij,kl,jl)Zscipy.optimizer*  rd   Z
atleast_1dr9   r\   
atleast_2dshaper   re   ZeinsumZsqueeze)r(  r   r)  r*  ZvxZvcovtoldxyZjacZycovr<   r<   r=   	propagate  s    

r0  c                   @  s$   e Zd Zdd Zdd Zdd ZdS )_Timerc                 C  s   |r
|j nd| _d S )Ng        )r   rM   )r;   r   r<   r<   r=   r>     s    z_Timer.__init__c                 C  s   |  j t 7  _ d S r:   )rM   r"   rG   r<   r<   r=   	__enter__  s    z_Timer.__enter__c                 G  s   t  | j | _d S r:   )r"   rM   r;   r   r<   r<   r=   __exit__  s    z_Timer.__exit__N)rp   rx   ry   r>   r2  r4  r<   r<   r<   r=   r1    s   r1  zUse of ``func_code`` attribute to declare parameters is deprecated. Use ``_parameters`` instead, which is a dict of parameter names to limits.zCollection[str]r   )r  r@   c                 C  s   t t| t| dS )z
    Make a func_code object to fake a function signature.

    Example::

        def f(a, b): ...

        f.func_code = make_func_code(["x", "y"])
    )co_varnamesco_argcount)r   r   rB   )r  r<   r<   r=   r-     s    r-   ri   )callablevarnamesreplacementsr@   c           	        s   t  ddr|t}t|}|t|kr4td||d|< | D ]\}}||}|||< qHfddt|D G  fddd}|S )	a  
    Return new callable with altered signature.

    Parameters
    ----------
    callable:
        Original callable with positional arguments, whose names shall be changed.
    *varnames: sequence of str
        Replace the first N argument names with these.
    **replacements: mapping of str to str, optional
        Replace old argument name (key) with new argument name (value).

    Returns
    -------
    Callable with positional-only arguments.
    Tr   z'varnames longer than original signatureNc                   s   i | ]\}}| | qS r<   r<   )rS   newold)parsr<   r=   ru   '  rU   z'make_with_signature.<locals>.<dictcomp>c                      s(   e Zd Zdd Zddd fddZdS )z#make_with_signature.<locals>.Callerc                 S  s
   || _ d S r:   )_parameters)r;   r   r<   r<   r=   r>   *  s    z,make_with_signature.<locals>.Caller.__init__r   )r   r@   c                   s    | S r:   r<   r3  r7  r<   r=   __call__-  s    z,make_with_signature.<locals>.Caller.__call__N)rp   rx   ry   r>   r?  r<   r>  r<   r=   Caller)  s   r@  )r0   rY   rB   r\   itemsrZ   r]   )	r7  r8  r9  r   r   r;  r:  rE   r@  r<   )r7  r<  r=   r.   
  s    

r.   FzIterable[Callable]ra   zTuple[Any, List[List[int]]])	callablesr   r@   c           
      C  s   g }g }g }| D ]p}g }t t|dd D ]H\}\}}	||v rR||| q,|t| || ||	 q,|| q|rdd t||D |fS ||fS )a  
    Merge signatures of callables with positional arguments.

    This is best explained by an example::

        def f(x, y, z): ...

        def g(x, p): ...

        parameters, mapping = merge_signatures(f, g)
        # parameters is ('x', 'y', 'z', 'p')
        # mapping is ([0, 1, 2], [0, 3])

    Parameters
    ----------
    callables :
        Callables whose parameters can be extracted with :func:`describe`.
    annotations : bool, optional
        Whether to return the annotions. Default is False, for backward
        compatibility.

    Returns
    -------
    tuple(parameters, mapping)
        parameters is the tuple of the merged parameter names.
        mapping contains the mapping of parameters indices from the merged signature to
        the original signatures.
    Tr   c                 S  s   i | ]\}}||qS r<   r<   )rS   rs   rf   r<   r<   r=   ru   b  rU   z$merge_signatures.<locals>.<dictcomp>)rv   r0   rA  r   rZ   rB   r]   )
rB  r   r   annsmappingfZamaprE   rs   annr<   r<   r=   r/   3  s     
r/   z	List[str])r7  r@   c                 C  s   d S r:   r<   r>  r<   r<   r=   r0   f  s    r0   z(Dict[str, Optional[Tuple[float, float]]])r7  r   r@   c                 C  s   d S r:   r<   )r7  r   r<   r<   r=   r0   j  s    c                C  sL   t | dkr|ri S g S t| di p:t| p:t| p:t| }|rD|S t|S )a  
    Attempt to extract the function argument names and annotations.

    Parameters
    ----------
    callable : callable
        Callable whose parameter names should be extracted.
    annotations : bool, optional
        Whether to also extract annotations. Default is false.

    Returns
    -------
    list or dict
        If annotate is False, return list of strings with the parameters names if
        successful and an empty list otherwise. If annotations is True, return a dict,
        which maps parameter names to annotations. For parameters without annotations,
        the dict maps to None.

    Notes
    -----
    Parameter names are extracted with the following three methods, which are attempted
    in order. The first to succeed determines the result.

    1.  Using ``obj._parameters``, which is a dict that maps parameter names to
        parameter limits or None if the parameter has to limits. Users are encouraged
        to use this mechanism to provide signatures for objects that otherwise would
        not have a detectable signature. Example::

            def f(*args):  # no signature
                x, y = args
                return (x - 2) ** 2 + (y - 3) ** 2

            f._parameters = {"x": None, "y": (1, 4)}

        Here, the first parameter is declared to have no limits (values from minus to
        plus infinity are allowed), while the second parameter is declared to have
        limits, it cannot be smaller than 1 or larger than 4.

        Note: In the past, the ``func_code`` attribute was used for a similar purpose as
        ``_parameters``. It is still supported for legacy code, but should not be used
        anymore in new code, since it does not support declaring parameter limits.

        If an objects has a ``func_code`` attribute, it is used to detect the
        parameters. Example::

            from iminuit.util import make_func_code

            def f(*args): # no signature
                x, y = args
                return (x - 2) ** 2 + (y - 3) ** 2

            # deprecated, make_func_code will raise a warning
            f.func_code = make_func_code(("x", "y"))

    2.  Using :func:`inspect.signature`. The :mod:`inspect` module provides a general
        function to extract the signature of a Python callable. It works on most
        callables, including Functors like this::

            class MyLeastSquares:
                def __call__(self, a, b):
                    ...

        Limits are supported via annotations, using the Annotated type that was
        introduced in Python-3.9 and can be obtained from the external package
        typing_extensions in Python-3.8. In the following example, the second parameter
        has a lower limit at 0, because it must be positive::

            from typing import Annotated

            def my_cost_function(a: float, b: Annotated[float, 0:]):
                ...

        There are no standard annotations yet at the time of this writing. iminuit
        supports the annotations Gt, Ge, Lt, Le from the external package
        annotated-types, and interprets slice notation as limits.

    3.  Using the docstring. The docstring is textually parsed to detect the parameter
        names. This requires that a docstring is present which follows the Python
        standard formatting for function signatures. Here is a contrived example which
        is parsed correctly: fn(a, b: float, int c, d=1, e: float=2.2, double e=3).

    Ambiguous cases with positional and keyword argument are handled in the following
    way::

        def fcn(a, b, *args, **kwargs): ...
        # describe returns [a, b];
        # *args and **kwargs are ignored

        def fcn(a, b, c=1): ...
        # describe returns [a, b, c];
        # positional arguments with default values are detected
    r   r=  )_address_of_cfuncr   _describe_impl_func_code_describe_impl_inspect_describe_impl_docstringrY   )r7  r   r   r<   r<   r=   r0   p  s    ]c                 C  s.   t | dr*| j}dd |jd |j D S i S )N	func_codec                 S  s   i | ]
}|d qS r:   r<   r%  r<   r<   r=   ru     rU   z,_describe_impl_func_code.<locals>.<dictcomp>)hasattrrK  r5  r6  )r7  fcr<   r<   r=   rH    s    
rH  c                 C  st   zt | }W n ty$   i  Y S 0 i }|j D ]:\}}|jt jju rN qp|jt jju r` qpt	|j
||< q4|S r:   )inspect	signaturer\   r   rA  kind	ParameterVAR_POSITIONALVAR_KEYWORD
_get_limit
annotation)r7  rO  rr   Zparr<   r<   r=   rI    s    
rI  c           
        s6  t | }|d u ri S z
| j}W n ty6   i  Y S 0 |d }||}|dk rVi S |t|7 }d}t||d  D ]6\}}|dkr|d7 }n|dkr|d8 }|dkrv qqvdd ||||  dD }t | r|dd  }z|	d}	|d |	 }W n t
y   Y n0 d	d	d
dd  fdd|D S )N(r   r   r  c                 S  s   g | ]}| d qS )z [])stripr%  r<   r<   r=   rT     rU   z,_describe_impl_docstring.<locals>.<listcomp>,z*argsri   )rr   r@   c                 S  sn   |  d}|dkr| d | } |  d}|dkr@| d |  S |  } |  d}|dkrj| |d   S | S )Nrm   r   :rl   )findrX  )rr   rE   r<   r<   r=   extract/  s    


z)_describe_impl_docstring.<locals>.extractc                   s   i | ]}|d kr |dqS )*Nr<   r%  r\  r<   r=   ru   @  rU   z,_describe_impl_docstring.<locals>.<dictcomp>)rN  getdocrp   AttributeErrorr[  rB   rv   splitismethodrZ   r\   )
r7  docr   tokenr   ZnbraceZichchrA  rE   r<   r^  r=   rJ    s<    




 

rJ  z'Union[type, Annotated[float, Any], str]zOptional[Tuple[float, float]])rU  r@   c                 C  s:  ddl m} t| tr<zt| d |j} W n ty:   Y n0 | tjj	krLd S t
| tur\d S t| ^}}|tu stJ tj }tj}|D ]}t|tr|jd ur|j}|jd ur|j}qt|tr|\}}qt|dd }t|dd }t|dd }	t|dd }
|d ur|}|d ur|}|	d ur$|	}|
d ur|
}q||fS )Nr   )typinggtgeltle)iminuitrf  rX   ri   eval__dict__	NameErrorrN  rQ  emptyr!   r   r    r   rd   r   r   r   r   r   r   )rU  rf  tpconstraintsr   r!  crg  rh  ri  rj  r<   r<   r=   rT  C  sJ    







rT  r   )r   r@   c                 C  s   | dkrdt |  S dS )Nr   {Gz?g?)abs)r   r<   r<   r=   r   }  s    r   zDict[str, int]r   z	List[int])r   rP   r@   c                 C  sf   t |jtr| |j n|j}t |jtr2| |j n|j}t|||jt| \}}}tt	|||S r:   )
rX   r   ri   r   r   r   indicesrB   rY   rA   )r   rP   r   r   r   r<   r<   r=   _key2index_from_slice  s    rv  zUnion[str, int]c                 C  sF   t |tr| | S |}|dk r*|t| 7 }|dk s>|t| krBt|S )Nr   )rX   ri   rB   r'  )r   rP   rE   r<   r<   r=   _key2index_item  s    
rw  r	   zUnion[int, List[int]]c                   s    du rt ttS t tr,t S t tszt trzt d trh fddttD  fdd D S t	 S )N.r   c                   s   g | ]} | r|qS r<   r<   r   r   r<   r=   rT     rU   z_key2index.<locals>.<listcomp>c                   s   g | ]}t  |qS r<   )rw  r   )r   r<   r=   rT     rU   )
rY   rA   rB   rX   r   rv  ri   r   ra   rw  )r   rP   r<   )rP   r   r=   rV     s    

rV   )fcnr@   c                 C  sV   ddl m}m}m}m}m}m} |||||}t| dd } t| |rR|| |j	S dS )Nr   )c_void_pc_doublec_uint32POINTER	CFUNCTYPEcastctypes)
r  ry  rz  r{  r|  r}  r~  r   rX   rM   )rx  ry  rz  r{  r|  r}  Zctypes_castZc_sigr<   r<   r=   rG    s     	
rG  c                 c  s&   t | ts| V  n| D ]
}|V  qd S r:   r   )r   xir<   r<   r=   _iterate  s    
r  zOptional[T])r   r^   r@   c                 C  s   | d u r|S | S r:   r<   )r   r^   r<   r<   r=   _replace_none  s    r  c                   @  sV   e Zd ZU dZdZded< ded< dd Zdd	 Zd
d Zdd Z	dd Z
dd ZdS )ProgressBarzZ
    Simple progress bar.

    Renders as nice HTML progressbar in Jupyter notebooks.
    r   r7   rM   	max_valuec                 C  s(   | j dd| dd | j   d S )Nd   .0f %_outwriteflush)r;   Zfractionr<   r<   r=   _update  s    zProgressBar._updatec                 C  s   | j d | j   d S )Nz     r  rG   r<   r<   r=   _finish  s    zProgressBar._finishc                   s   || _ tj| _zt ( tdt ddlm	} W d   n1 sF0    Y  t
| j|rddlmm   fdd| _ fdd| _W n ty   Y n0 | | j dS )	z
        Initialize bar.

        Parameters
        ----------
        max_value: int
            Total number of entries.
        ignorer   )	OutStreamN)displayHTMLc                   s*    dd|  ddd|  ddddS )Nz<progress value='r  r  z' max='100'></progress> r  Tclearr<   )r^   r  r  r<   r=   <lambda>  s   z&ProgressBar.__init__.<locals>.<lambda>c                     s    dddS )Nr  Tr  r<   r<   r  r<   r=   r    rU   )r  sysstdoutr  r   catch_warningssimplefilterDeprecationWarningZipykernel.iostreamr  rX   IPython.displayr  r  r  r  ModuleNotFoundErrorrM   )r;   r  r  r<   r  r=   r>     s    	
*zProgressBar.__init__c                 G  s   | S )zNoop.r<   r3  r<   r<   r=   r2    s    zProgressBar.__enter__c                 G  s   |    dS )zClean up the bar.N)r  r3  r<   r<   r=   r4    s    zProgressBar.__exit__c                 C  s$   |  j |7  _ | | j | j  | S )zIncrement progress.)rM   r  r  )r;   r^   r<   r<   r=   __add__   s    zProgressBar.__add__N)rp   rx   ry   rz   rM   __annotations__r  r  r>   r2  r4  r  r<   r<   r<   r=   r    s   
"r  c                 C  s   |j dksJ | d u r ||fgS g }d}d}d}t| }||k r| | sR|d7 }q8|d }||k rt| | rt|d7 }qZ||||| |  |||d  f ||| 7 }|d }q8|S )Nr   r   )r9   rB   r   )maskZxeZmaskedsegmentsrf   rg   amr   r<   r<   r=   _histogram_segments  s&    

*
r     {Gzt?
   c                   s  t  }t|||}| |}	t|	}
t|	}dd t||	D  |d d }|dd  }d}t|r|d7 }||krd| dt  d}t|t	 qt  | |krd	| dt  d}t|t	 qd
||  }| |}	t|
t|	}
t|t|	}t||	D ]\}}| |< qd
t
 fdd|D tt
 fdd|D t  }t|	| }t|| }||||
  k||t||  k@ }|| }|| }|| }t||}t||}q`t  }|  t|S )Nc                 S  s   i | ]\}}||qS r<   r<   )rS   r  yir<   r<   r=   ru   %  rU   z#_smart_sampling.<locals>.<dictcomp>r   r   zIteration limit z% in smart sampling reached, produced z pointszTime limit r   c                 3  s   | ]} | V  qd S r:   r<   )rS   Zair/  r<   r=   r   @  rU   z"_smart_sampling.<locals>.<genexpr>c                 3  s   | ]} | V  qd S r:   r<   )rS   Zbir  r<   r=   r   A  rU   )r"   rd   Zlinspacer   maxr]   rB   r   r   RuntimeWarningZfromiterr   rt  r   rY   rA  sortZ	transpose)rE  ZxminZxmaxr   r-  maxiterZmaxtimet0r   ZynewZyminZymaxrf   rg   ZnitermsgZxnewr  r  ZyintZdyr.  r  Zxyr<   r  r=   _smart_sampling  s^    


$r  r   )r   r@   c                 C  sd   t | } | d dkrdS t | }t t | }t |t | }t |t | }||k S )Nr   F)rd   r  difflogZstdmean)r   Zd_linZd_logZlin_rel_stdZlog_rel_stdr<   r<   r=   _detect_log_spacingT  s    

r  r   zOptional[CostGradient]c                 C  s2   t | dd}t | dd}|r.t|tr.|r.|S dS )ah  
    Return a callable which computes the gradient of fcn or None.

    Parameters
    ----------
    fcn: Cost
        Cost function which may provide a callable gradient. How the gradient
        is detected is specified below in the Notes.

    Notes
    -----
    This function checks whether the following attributes exist: `fcn.grad` and
    `fcn.has_grad`. If `fcn.grad` exists and is a CostGradient, it is returned unless
    `fcn.has_grad` exists and is False. If no useable gradient is detected, None is
    returned.

    Returns
    -------
    callable or None
        The gradient function or None
    gradNhas_gradT)r   rX   r   )rx  r  r  r<   r<   r=   r1   `  s
    r1   r   )mr@   c                 C  sL   t | } t | j| krHzt j|  W n t jjyB   Y dS 0 dS dS )aE  
    Return True if argument is a positive definite matrix.

    This test is somewhat expensive, because we attempt a cholesky decomposition.

    Parameters
    ----------
    m : array-like
        Matrix to be tested.

    Returns
    -------
    bool
        True if matrix is positive definite and False otherwise.
    FT)rd   r+  re   r#   ZlinalgZcholeskyZLinAlgError)r  r<   r<   r=   r2   }  s    
r2   r?   c                  C  sJ   zddl m}  |  }|dW S  ty2   Y dS  tyD   Y dS 0 dS )Nr   )get_ipythonZkernelF)ZIPythonr  Z	has_traitImportErrorr`  )r  ipr<   r<   r=   
is_jupyter  s    r  c                 C  s.   | dk rdnd}t | tjkr*|tjj S | S )Nr   r  r   )rt  rd   r   r  
float_infor  )r   signr<   r<   r=   _make_finite  s    r  )r   vminvmaxr@   c                 C  s$   t |r t |r d||  S dS )Nrs  )rd   r   )r   r  r  r<   r<   r=   _widget_guess_initial_step  s    r  )F)r  r  r  r  )]rz   
__future__r   rN  collectionsr   argparser   rk  r   r   r   Ziminuit.typingr	   r
   r   r   Ziminuit.warningsr   r   r   numpyrd   Znumpy.typingr   r   rf  r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r|   r   r"   r   r  r#   __all__ABCr3   r6   r$   r   r%   r&   r   r   r'   r(   r)   r   r*   r+   r,   
deprecatedr0  r1  r-   r.   r/   r0   rH  rI  rJ  rT  r   rv  rw  rV   rG  r  r  r  r  r  r  r1   r2   r  r  r  r<   r<   r<   r=   <module>   s   HS
'   &>RY$-* 3m	K:C
5