o
    g,                     @   s  d Z g dZdZddlZddlZddlZzddlmZ W n ey+   ddl	mZ Y nw ddl
ZddlmZ ddlmZmZmZmZ dd	lmZ dd
lmZmZmZmZmZ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$m%Z%m&Z& ddl'm(Z(m)Z) ddl*m+Z+ ddl,Z,ddl-Z-ddl.Z.				doddZ/e)d			dpdddddZ0			dpdddddZ1e)ddd Z2dd Z3e)de.j4dd Z*dqdd Z5d!d" Z6d#d$ Z7d%d& Z8d'd( Z9d)d* Z:drd,d-Z;e; dsd0d1Z<				dodd2d3d4Z=e(e=dd5dddd.d/ej>dddddd/fdd2d6d7Z?d8d9 Z@d:d; ZAd<d= ZBd>d? ZCG d@dA dAZDe)d	C		dtdEdFZEe)d	B	D	dudGdHZFG dIdJ dJZGG dKdL dLZHG dMdN dNZIG dOdP dPZJG dQdR dReJZKG dSdT dTeJZLG dUdV dVZMG dWdX dXZNdvdYdZZOe#e$e%ejPgZQd[d\ ZRd]d^ ZSddde?fd_d`ZT	dwdadbZUe(eUdd5dwdcddZVe; dedf ZWddde?fdgdhZX	dwdidjZYe(eYdd5dwdkdlZZe[e?dme?Z\ej]eXe\dnZ^ej]eTe\dnZ_dS )xzXArray printing function

$Id: arrayprint.py,v 1.9 2005/09/13 13:58:44 teoliphant Exp $

)array2string	array_str
array_reprset_printoptionsget_printoptionsprintoptionsformat_float_positionalformat_float_scientificrestructuredtext    N)	get_ident   )numerictypes)absoluteisinfisfiniteisnat)
multiarray)arraydragon4_positionaldragon4_scientificdatetime_as_stringdatetime_datandarray)any)concatenateasarrayerrstate)longlongintcint_float64
complex128flexible)array_function_dispatch
set_module)format_optionsc              
   C   s  dd t t  D }|durt||d< g d}|	|dg vr/tdddd	 |D  |d
vr7td|
du rAtj|d< nF|
dkrWtj	d|
dt
dd tj|d< n0|
dkr`d|d< n'|
dkrid|d< n|
dkrrd|d< n|
dkr{d|d< n|
du rntj	ddd |durt|tjstdt|rtd| durz
t| |d< W |S  ty } ztd|d}~ww |S )zm
    Make a dictionary out of the non-None arguments, plus conversion of
    *legacy* and sanity checks.
    c                 S   s   i | ]\}}|d ur||qS N ).0kvr'   r'   P/var/www/html/api-tag/env/lib/python3.10/site-packages/numpy/_core/arrayprint.py
<dictcomp>;   s    z&_make_options_dict.<locals>.<dictcomp>Nsuppress)fixeduniquemaxprecmaxprec_equalz floatmode option must be one of , c                 s   s    | ]}d  |V  qdS )z"{}"Nformat)r(   mr'   r'   r+   	<genexpr>C       z%_make_options_dict.<locals>.<genexpr>)N-+ z+sign option must be one of ' ', '+', or '-'FlegacyzPassing `legacy=z` is deprecated.   
stacklevel1.13q   1.21y   1.25}   z2.1   zUlegacy printing option can currently only be '1.13', '1.21', '1.25', '2.1, or `False`zthreshold must be numericzIthreshold must be non-NAN, try sys.maxsize for untruncated representation	precisionzprecision must be an integer)listlocalsitemsbool
ValueErrorjoinsysmaxsizewarningswarnFutureWarning
isinstancenumbersNumber	TypeErrornpisnanoperatorindex)rF   	threshold	edgeitems	linewidthr-   nanstrinfstrsign	formatter	floatmoder;   override_reproptionsmodeser'   r'   r+   _make_options_dict2   s\   	






rf   numpyr;   rb   c
                C   s$   t | |||||||||	|
|d dS )a  
    Set printing options.

    These options determine the way floating point numbers, arrays and
    other NumPy objects are displayed.

    Parameters
    ----------
    precision : int or None, optional
        Number of digits of precision for floating point output (default 8).
        May be None if `floatmode` is not `fixed`, to print as many digits as
        necessary to uniquely specify the value.
    threshold : int, optional
        Total number of array elements which trigger summarization
        rather than full repr (default 1000).
        To always use the full repr without summarization, pass `sys.maxsize`.
    edgeitems : int, optional
        Number of array items in summary at beginning and end of
        each dimension (default 3).
    linewidth : int, optional
        The number of characters per line for the purpose of inserting
        line breaks (default 75).
    suppress : bool, optional
        If True, always print floating point numbers using fixed point
        notation, in which case numbers equal to zero in the current precision
        will print as zero.  If False, then scientific notation is used when
        absolute value of the smallest number is < 1e-4 or the ratio of the
        maximum absolute value to the minimum is > 1e3. The default is False.
    nanstr : str, optional
        String representation of floating point not-a-number (default nan).
    infstr : str, optional
        String representation of floating point infinity (default inf).
    sign : string, either '-', '+', or ' ', optional
        Controls printing of the sign of floating-point types. If '+', always
        print the sign of positive values. If ' ', always prints a space
        (whitespace character) in the sign position of positive values.  If
        '-', omit the sign character of positive values. (default '-')

        .. versionchanged:: 2.0
             The sign parameter can now be an integer type, previously
             types were floating-point types.

    formatter : dict of callables, optional
        If not None, the keys should indicate the type(s) that the respective
        formatting function applies to.  Callables should return a string.
        Types that are not specified (by their corresponding keys) are handled
        by the default formatters.  Individual types for which a formatter
        can be set are:

        - 'bool'
        - 'int'
        - 'timedelta' : a `numpy.timedelta64`
        - 'datetime' : a `numpy.datetime64`
        - 'float'
        - 'longfloat' : 128-bit floats
        - 'complexfloat'
        - 'longcomplexfloat' : composed of two 128-bit floats
        - 'numpystr' : types `numpy.bytes_` and `numpy.str_`
        - 'object' : `np.object_` arrays

        Other keys that can be used to set a group of types at once are:

        - 'all' : sets all types
        - 'int_kind' : sets 'int'
        - 'float_kind' : sets 'float' and 'longfloat'
        - 'complex_kind' : sets 'complexfloat' and 'longcomplexfloat'
        - 'str_kind' : sets 'numpystr'
    floatmode : str, optional
        Controls the interpretation of the `precision` option for
        floating-point types. Can take the following values
        (default maxprec_equal):

        * 'fixed': Always print exactly `precision` fractional digits,
                even if this would print more or fewer digits than
                necessary to specify the value uniquely.
        * 'unique': Print the minimum number of fractional digits necessary
                to represent each value uniquely. Different elements may
                have a different number of digits. The value of the
                `precision` option is ignored.
        * 'maxprec': Print at most `precision` fractional digits, but if
                an element can be uniquely represented with fewer digits
                only print it with that many.
        * 'maxprec_equal': Print at most `precision` fractional digits,
                but if every element in the array can be uniquely
                represented with an equal number of fewer digits, use that
                many digits for all elements.
    legacy : string or `False`, optional
        If set to the string ``'1.13'`` enables 1.13 legacy printing mode. This
        approximates numpy 1.13 print output by including a space in the sign
        position of floats and different behavior for 0d arrays. This also
        enables 1.21 legacy printing mode (described below).

        If set to the string ``'1.21'`` enables 1.21 legacy printing mode. This
        approximates numpy 1.21 print output of complex structured dtypes
        by not inserting spaces after commas that separate fields and after
        colons.

        If set to ``'1.25'`` approximates printing of 1.25 which mainly means
        that numeric scalars are printed without their type information, e.g.
        as ``3.0`` rather than ``np.float64(3.0)``.

        If set to ``'2.1'``, shape information is not given when arrays are
        summarized (i.e., multiple elements replaced with ``...``).

        If set to `False`, disables legacy mode.

        Unrecognized strings will be ignored with a warning for forward
        compatibility.

        .. versionchanged:: 1.22.0
        .. versionchanged:: 2.2

    override_repr: callable, optional
        If set a passed function will be used for generating arrays' repr.
        Other options will be ignored.

    See Also
    --------
    get_printoptions, printoptions, array2string

    Notes
    -----
    `formatter` is always reset with a call to `set_printoptions`.

    Use `printoptions` as a context manager to set the values temporarily.

    Examples
    --------
    Floating point precision can be set:

    >>> import numpy as np
    >>> np.set_printoptions(precision=4)
    >>> np.array([1.123456789])
    [1.1235]

    Long arrays can be summarised:

    >>> np.set_printoptions(threshold=5)
    >>> np.arange(10)
    array([0, 1, 2, ..., 7, 8, 9], shape=(10,))

    Small results can be suppressed:

    >>> eps = np.finfo(float).eps
    >>> x = np.arange(4.)
    >>> x**2 - (x + eps)**2
    array([-4.9304e-32, -4.4409e-16,  0.0000e+00,  0.0000e+00])
    >>> np.set_printoptions(suppress=True)
    >>> x**2 - (x + eps)**2
    array([-0., -0.,  0.,  0.])

    A custom formatter can be used to display array elements as desired:

    >>> np.set_printoptions(formatter={'all':lambda x: 'int: '+str(-x)})
    >>> x = np.arange(3)
    >>> x
    array([int: 0, int: -1, int: -2])
    >>> np.set_printoptions()  # formatter gets reset
    >>> x
    array([0, 1, 2])

    To put back the default options, you can use:

    >>> np.set_printoptions(edgeitems=3, infstr='inf',
    ... linewidth=75, nanstr='nan', precision=8,
    ... suppress=False, threshold=1000, formatter=None)

    Also to temporarily override options, use `printoptions`
    as a context manager:

    >>> with np.printoptions(precision=2, suppress=True, threshold=5):
    ...     np.linspace(0, 10, 10)
    array([ 0.  ,  1.11,  2.22, ...,  7.78,  8.89, 10.  ], shape=(10,))

    rh   N)_set_printoptions)rF   rZ   r[   r\   r-   r]   r^   r`   r_   ra   r;   rb   r'   r'   r+   r   q   s
    5

r   c
                C   s`   t | |||||||||	|
}||d< ||d< t |B }|| |d dkr+d|d< t|S )Nr`   rb   r;   r@   r8   r_   )rf   r%   getupdateset)rF   rZ   r[   r\   r-   r]   r^   r`   r_   ra   r;   rb   new_optupdated_optr'   r'   r+   ri   *  s   



ri   c                  C   s2   t   } ddddddtjdi| d  | d< | S )	ak  
    Return the current print options.

    Returns
    -------
    print_opts : dict
        Dictionary of current print options with keys

        - precision : int
        - threshold : int
        - edgeitems : int
        - linewidth : int
        - suppress : bool
        - nanstr : str
        - infstr : str
        - sign : str
        - formatter : dict of callables
        - floatmode : str
        - legacy : str or False

        For a full description of these options, see `set_printoptions`.

    See Also
    --------
    set_printoptions, printoptions

    Examples
    --------
    >>> import numpy as np

    >>> np.get_printoptions()
    {'edgeitems': 3, 'threshold': 1000, ..., 'override_repr': None}

    >>> np.get_printoptions()['linewidth']
    75
    >>> np.set_printoptions(linewidth=100)
    >>> np.get_printoptions()['linewidth']
    100

    r@   r?   rB   rA   rD   rC   Fr;   )r%   rj   copyrM   rN   )optsr'   r'   r+   r   >  s   *r   c                   C   s   t  d S )z'Return the legacy print mode as an int.r;   )r%   rj   r'   r'   r'   r+   _get_legacy_print_modeo  s   rq   c               	   o   s6    t | i |}zt V  W t| dS t| w )a  Context manager for setting print options.

    Set print options for the scope of the `with` block, and restore the old
    options at the end. See `set_printoptions` for the full description of
    available options.

    Examples
    --------
    >>> import numpy as np

    >>> from numpy.testing import assert_equal
    >>> with np.printoptions(precision=2):
    ...     np.array([2.0]) / 3
    array([0.67])

    The `as`-clause of the `with`-statement gives the current print options:

    >>> with np.printoptions(precision=2) as opts:
    ...      assert_equal(opts, np.get_printoptions())

    See Also
    --------
    set_printoptions, get_printoptions

    N)ri   r   r%   reset)argskwargstokenr'   r'   r+   r   t  s
   
r   r'   c              	   C   s   t |}|| jkr| | S | j| d| kr5tt| ||tjd|  t| ||tj| d  f|dS t| ||tjdd  S )z
    Keep only the N-D corners (leading and trailing edges) of an array.

    Should be passed a base-class ndarray, since it makes no guarantees about
    preserving subclasses.
       N)axis)lenndimshaper   _leading_trailingrV   	index_exp)ar[   rY   rw   r'   r'   r+   r{     s   
r{   c                 C   s    t | tu r	d}nd}|| S )z@ Object arrays containing lists should be printed unambiguously z
list({!r})z{!r})typerG   r4   )ofmtr'   r'   r+   _object_format  s   
r   c                 C   &   t | tjtjfrt|  S t| S r&   )rR   rV   str_bytes_repritemxr'   r'   r+   repr_format     r   c                 C   r   r&   )rR   rV   r   r   strr   r   r'   r'   r+   
str_format  r   r   c                   s   fdd fdd fdd fdd fdd fdd fdd fd	dd
d dd dd d}dd }	d urfdd  D }
d|
v rp|  D ]
}|	d ||< qed|
v rdD ]
}|	d ||< qvd|
v rdD ]
}|	d ||< qd|
v rdD ]
}|	d ||< qd|
v r|	d |d< |  D ]}||
v r|	| ||< q|S )Nc                         t  S r&   )
BoolFormatr'   datar'   r+   <lambda>      z!_get_formatdict.<locals>.<lambda>c                      s
   t  S r&   )IntegerFormatr'   )r   r_   r'   r+   r     s   
 c                         t  dS Nr;   FloatingFormatr'   r   ra   r;   rF   r_   r-   r'   r+   r         c                      r   r   r   r'   r   r'   r+   r     r   c                      r   r   ComplexFloatingFormatr'   r   r'   r+   r     r   c                      r   r   r   r'   r   r'   r+   r     r   c                      s   t  dS r   )DatetimeFormatr'   )r   r;   r'   r+   r     s    c                      r   r&   )TimedeltaFormatr'   r   r'   r+   r     r   c                   S      t S r&   )r   r'   r'   r'   r+   r         c                   S   r   r&   )r   r'   r'   r'   r+   r     r   c                   S   r   r&   )r   r'   r'   r'   r+   r     r   )rJ   intfloat	longfloatcomplexfloatlongcomplexfloatdatetime	timedeltaobjectvoidnumpystrc                    s    fddS )Nc                      s    S r&   r'   r'   r   r'   r+   r     r   z3_get_formatdict.<locals>.indirect.<locals>.<lambda>r'   r   r'   r   r+   indirect     z!_get_formatdict.<locals>.indirectc                    s   g | ]
} | d ur|qS r&   r'   )r(   r)   )r`   r'   r+   
<listcomp>  s    z#_get_formatdict.<locals>.<listcomp>allint_kind)r   
float_kind)r   r   complex_kind)r   r   str_kindr   )keys)r   rF   ra   r-   r_   r;   r`   rt   
formatdictr   fkeyskeyr'   )r   ra   r`   r;   rF   r_   r-   r+   _get_formatdict  sD   

r   c                 K   sL  | j }|j}t| fi |}|du r|d  S t|tjr"|d  S t|tjr8t|tjr3|d  S |d  S t|tjrNt|tj	rI|d  S |d  S t|tj
rdt|tjr_|d  S |d	  S t|tjtjfrr|d  S t|tjr}|d
  S t|tjr|d  S t|tjr|jdurtj| fi |S |d  S |d  S )z;
    find the right formatting function for the dtype_
    Nr   rJ   r   r   r   r   r   r   r   r   r   )dtyper~   r   
issubclass_ntrJ   integertimedelta64floating
longdoublecomplexfloatingclongdoubler   r   
datetime64object_r   namesStructuredVoidFormat	from_data)r   rc   dtype_dtypeobjr   r'   r'   r+   _get_format_function  s<   













r   ...c                    s    fdd}|S )a  
    Like the python 3.2 reprlib.recursive_repr, but forwards *args and **kwargs

    Decorates a function such that if it calls itself with the same first
    argument, it returns `fillvalue` instead of recursing.

    Largely copied from reprlib.recursive_repr
    c                    s$   t  t  fdd}|S )Nc              	      sT   t | t f}|v rS | z | g|R i |W | S | w r&   )idr   adddiscard)selfrs   rt   r   )f	fillvaluerepr_runningr'   r+   wrapper&  s   
z>_recursive_guard.<locals>.decorating_function.<locals>.wrapper)rl   	functoolswraps)r   r   r   )r   r   r+   decorating_function#  s   
z-_recursive_guard.<locals>.decorating_functionr'   )r   r   r'   r   r+   _recursive_guard  s   
r   r:    c           	   
   C   s   t | }| jdkr|} | j|d krd}t||d }nd}t|fi |}d}|dt| 7 }t| ||d |||d ||d }|S )	Nr'   rZ   r   r[   r   r:   r\   r;   )r   rz   sizer{   r   rx   _formatArray)	r}   rc   	separatorprefixr   summary_insertformat_functionnext_line_prefixlstr'   r'   r+   _array2string7  s   

r   r   c                C      | fS r&   r'   )r}   max_line_widthrF   suppress_smallr   r   styler`   rZ   r[   r_   ra   suffixr;   r'   r'   r+   _array2string_dispatcherT  s   r   )modulec                C   s   t |||	||dd|
|||}t  }|| |d dkr8|tju r&t}| jdkr7| j	j
du r7||  S n|tjurEtjdtdd |d dkrU|d  t|8  < | jd	kr\d
S t| |||S )a  
    Return a string representation of an array.

    Parameters
    ----------
    a : ndarray
        Input array.
    max_line_width : int, optional
        Inserts newlines if text is longer than `max_line_width`.
        Defaults to ``numpy.get_printoptions()['linewidth']``.
    precision : int or None, optional
        Floating point precision.
        Defaults to ``numpy.get_printoptions()['precision']``.
    suppress_small : bool, optional
        Represent numbers "very close" to zero as zero; default is False.
        Very close is defined by precision: if the precision is 8, e.g.,
        numbers smaller (in absolute value) than 5e-9 are represented as
        zero.
        Defaults to ``numpy.get_printoptions()['suppress']``.
    separator : str, optional
        Inserted between elements.
    prefix : str, optional
    suffix : str, optional
        The length of the prefix and suffix strings are used to respectively
        align and wrap the output. An array is typically printed as::

          prefix + array2string(a) + suffix

        The output is left-padded by the length of the prefix string, and
        wrapping is forced at the column ``max_line_width - len(suffix)``.
        It should be noted that the content of prefix and suffix strings are
        not included in the output.
    style : _NoValue, optional
        Has no effect, do not use.

        .. deprecated:: 1.14.0
    formatter : dict of callables, optional
        If not None, the keys should indicate the type(s) that the respective
        formatting function applies to.  Callables should return a string.
        Types that are not specified (by their corresponding keys) are handled
        by the default formatters.  Individual types for which a formatter
        can be set are:

        - 'bool'
        - 'int'
        - 'timedelta' : a `numpy.timedelta64`
        - 'datetime' : a `numpy.datetime64`
        - 'float'
        - 'longfloat' : 128-bit floats
        - 'complexfloat'
        - 'longcomplexfloat' : composed of two 128-bit floats
        - 'void' : type `numpy.void`
        - 'numpystr' : types `numpy.bytes_` and `numpy.str_`

        Other keys that can be used to set a group of types at once are:

        - 'all' : sets all types
        - 'int_kind' : sets 'int'
        - 'float_kind' : sets 'float' and 'longfloat'
        - 'complex_kind' : sets 'complexfloat' and 'longcomplexfloat'
        - 'str_kind' : sets 'numpystr'
    threshold : int, optional
        Total number of array elements which trigger summarization
        rather than full repr.
        Defaults to ``numpy.get_printoptions()['threshold']``.
    edgeitems : int, optional
        Number of array items in summary at beginning and end of
        each dimension.
        Defaults to ``numpy.get_printoptions()['edgeitems']``.
    sign : string, either '-', '+', or ' ', optional
        Controls printing of the sign of floating-point types. If '+', always
        print the sign of positive values. If ' ', always prints a space
        (whitespace character) in the sign position of positive values.  If
        '-', omit the sign character of positive values.
        Defaults to ``numpy.get_printoptions()['sign']``.

        .. versionchanged:: 2.0
             The sign parameter can now be an integer type, previously
             types were floating-point types.

    floatmode : str, optional
        Controls the interpretation of the `precision` option for
        floating-point types.
        Defaults to ``numpy.get_printoptions()['floatmode']``.
        Can take the following values:

        - 'fixed': Always print exactly `precision` fractional digits,
          even if this would print more or fewer digits than
          necessary to specify the value uniquely.
        - 'unique': Print the minimum number of fractional digits necessary
          to represent each value uniquely. Different elements may
          have a different number of digits.  The value of the
          `precision` option is ignored.
        - 'maxprec': Print at most `precision` fractional digits, but if
          an element can be uniquely represented with fewer digits
          only print it with that many.
        - 'maxprec_equal': Print at most `precision` fractional digits,
          but if every element in the array can be uniquely
          represented with an equal number of fewer digits, use that
          many digits for all elements.
    legacy : string or `False`, optional
        If set to the string ``'1.13'`` enables 1.13 legacy printing mode. This
        approximates numpy 1.13 print output by including a space in the sign
        position of floats and different behavior for 0d arrays. If set to
        `False`, disables legacy mode. Unrecognized strings will be ignored
        with a warning for forward compatibility.

    Returns
    -------
    array_str : str
        String representation of the array.

    Raises
    ------
    TypeError
        if a callable in `formatter` does not return a string.

    See Also
    --------
    array_str, array_repr, set_printoptions, get_printoptions

    Notes
    -----
    If a formatter is specified for a certain type, the `precision` keyword is
    ignored for that type.

    This is a very flexible function; `array_repr` and `array_str` are using
    `array2string` internally so keywords with the same name should work
    identically in all three functions.

    Examples
    --------
    >>> import numpy as np
    >>> x = np.array([1e-16,1,2,3])
    >>> np.array2string(x, precision=2, separator=',',
    ...                       suppress_small=True)
    '[0.,1.,2.,3.]'

    >>> x  = np.arange(3.)
    >>> np.array2string(x, formatter={'float_kind':lambda x: "%.2f" % x})
    '[0.00 1.00 2.00]'

    >>> x  = np.arange(3)
    >>> np.array2string(x, formatter={'int':lambda x: hex(x)})
    '[0x0 0x1 0x2]'

    Nr;   r@   r'   zT'style' argument is deprecated and no longer functional except in 1.13 'legacy' moderv   r=   r\   r
   z[])rf   r%   rj   ro   rk   rV   _NoValuer   rz   r   r   r   rO   rP   DeprecationWarningrx   r   r   )r}   r   rF   r   r   r   r   r`   rZ   r[   r_   ra   r   r;   	overridesrc   r'   r'   r+   r   ]  s,    



r   c                 C   sX   t |t | |k}|dkrt |t |krd}|r$| | d 7 } |}||7 }| |fS )Nr@   F
)rx   rstrip)slineword
line_widthr   r;   
needs_wrapr'   r'   r+   _extendLine  s   r   c           
      C   s   |  }t|dks|dkrt| |||||S tdd |D }t|| |krAt|t|krA| | d 7 } ||d  }|}nt|d }||d 7 }|dd D ]}| | d 7 } || }qS|t|d	  }	||	d 7 }| |fS )
zS
    Extends line with nicely formatted (possibly multi-line) string ``word``.
    r   r@   c                 s       | ]}t |V  qd S r&   rx   )r(   r   r'   r'   r+   r6   )      z%_extendLine_pretty.<locals>.<genexpr>r   r
   r:   N)
splitlinesrx   r   maxr   )
r   r   r   r   r   r;   wordsmax_word_lengthindentsuffix_lengthr'   r'   r+   _extendLine_pretty!  s"   
r   c                    s4    fddz
d||dW dS dw )zgformatArray is designed for two modes of operation:

    1. Full output

    2. Summarized output

    c                    s  t | } j| }|dkr |  S |d }dkr|}n|t d } j| }o0d |k }|r8}	}
nd}	|}
d}|dkr׈dkrO|t   }n|tt  t d }|}t|	D ]}| |f ||}t|||||\}}|7 }qb|rt||||\}}dkr|d7 }n|7 }t|
dd	D ]}| | f ||}t|||||\}}|7 }qdkr|}| d
 ||}t|||||\}}||7 }ngd} d|d   }t|	D ]}| |f ||}||| | 7 }q|rdkr|| d 7 }n|| | 7 }t|
dd	D ]}| | f ||}||| | 7 }q| d
 ||}||| 7 }d|t |d  d }|S )z
        By using this local function, we don't need to recurse with all the
        arguments. Since this function is not created recursively, the cost is
        not significant
        r
   r:   r@   ]rv   r   r   r2   r   )r   r   z, 
[N)rx   ry   rz   r   r   ranger   r   )rY   hanging_indent
curr_widthrw   	axes_leftnext_hanging_indent
next_widtha_lenshow_summaryleading_itemstrailing_itemsr   
elem_widthr   ir   line_sepnestedr}   
edge_itemsr   r;   recurserr   r   r'   r+   r  E  s   






z_formatArray.<locals>.recurserr'   )rY   r  r  Nr'   )r}   r   r   r   r   r  r   r;   r'   r  r+   r   <  s   	hr   c                 C   s&   | d u rdS | dk rt d|| S )Nr   r
   z{} must be >= 0)rK   r4   )r   namer'   r'   r+   _none_or_positive_arg  s
   r  c                   @   s0   e Zd ZdZdddddZdd Zd	d
 ZdS )r   z' Formatter for subtypes of np.floating FNr   c                C   s   t |tr|r	dnd}|| _| jdkr|jdkr|dkrd}|| _|dkr)d | _n|| _t| jd| _|| _|| _d| _	d| _
| | d S )	Nr9   r8   r@   r'   r:   r/   rF   F)rR   rJ   _legacyrz   ra   rF   r  r   r_   
exp_formatlarge_exponent
fillFormat)r   r   rF   ra   r   r_   r;   r'   r'   r+   __init__  s    

zFloatingFormat.__init__c                    s   |t | }t||dk }t|dkrGt|}t|}tdd |dks5 js8|dk s5|| dkr8d _W d    n1 sBw   Y  t|dkr`d _	d _
d _d	 _d _d  _nۈ jrd
\ jdksq jdkrud\ fdd|D }tdd |D  \}}}	tdd |D  \}
}tdd |	D d  _d _tdd |D  _ j _ _ jdkrd _	n
tdd |
D  _	 jd  j  _
ngd
\ jdkrd\ fdd|D }tdd |D  \}
} jdkr
dtdd |
D   _	n
tdd |
D  _	tdd |D  _
d	 _ _ jdv r5 j
  _ _d _nd _d _ jdkrV jdkrVtt|sV  j	d7  _	|j|jkr jd kplt|t| dk } j
d }t }t j	t|d! | t|d" | |  _	d S d S )#Nr
   ignore)overg    חAg-C6?g     @@T.r   )r  Tr.   r@   )r)   Fc                 3   s*    | ]}t | j jd kdV  qdS )r9   )rF   r/   trimr_   N)r   rF   r_   r(   r   r   r  r/   r'   r+   r6     s    z,FloatingFormat.fillFormat.<locals>.<genexpr>c                 s       | ]}| d V  qdS )re   N)	partitionr(   r   r'   r'   r+   r6     r7   c                 s   r  r  Nsplitr   r'   r'   r+   r6     r7   c                 s   r   r&   r   r   r'   r'   r+   r6     r   r   r)   c                 s   r   r&   r   r   r'   r'   r+   r6     r   r<   c                 s   r   r&   r   r   r'   r'   r+   r6     r   rv   c              	   3   s,    | ]}t | jd  jdkdV  qdS )Tr9   )rF   
fractionalr/   r  r_   N)r   rF   r_   r  r  r'   r+   r6     s    c                 s   r  r!  r"  r   r'   r'   r+   r6     r7   c                 s   s    | ]
}t |d V  qdS )z-+N)rx   lstripr   r'   r'   r+   r6     s    c                 s   r   r&   r   r   r'   r'   r+   r6     r   c                 s   r   r&   r   r   r'   r'   r+   r6     r   )r.   r1   r:   r8   r]   r^   )r   r   rx   rV   r   minr   r   r  pad_left	pad_rightr  exp_sizer/   
min_digitsra   r  ziprF   r_   r   signbitr   r   r%   rj   )r   r   finite_valsabs_non_zeromax_valmin_valstrs	frac_strs_exp_strsint_part	frac_partneginfoffsetcurrent_optionsr'   r  r+   r    s   



 

zFloatingFormat.fillFormatc                 C   s  t |sXtddF t }t |r$| jdkrdnd}||d  }n|dk r*dn| jdkr1dnd}||d  }d	| j| j d
 t	|  | W  d    S 1 sSw   Y  | j
rpt|| j| j| j| j| jdk| j| jdS t|| j| j| jd| j| jdk| j| jd	S )Nr  )invalidr9   r   r]   r
   r8   r^   r:   r   )rF   r*  r/   r  r_   r'  
exp_digitsT)rF   r*  r/   r$  r  r_   r'  r(  )rV   r   r   r%   rj   rW   r_   r'  r(  rx   r  r   rF   r*  r/   r  r)  r   )r   r   r9  r_   retr'   r'   r+   __call__1  sD   

 	zFloatingFormat.__call__F)__name__
__module____qualname____doc__r  r  r=  r'   r'   r'   r+   r     s    Vr   Tr)   Fc              
   C   s`   t |d}t |d}t |d}t |d}|dkr$|dkr$||kr$tdt| |||||||dS )a
  
    Format a floating-point scalar as a decimal string in scientific notation.

    Provides control over rounding, trimming and padding. Uses and assumes
    IEEE unbiased rounding. Uses the "Dragon4" algorithm.

    Parameters
    ----------
    x : python float or numpy floating scalar
        Value to format.
    precision : non-negative integer or None, optional
        Maximum number of digits to print. May be None if `unique` is
        `True`, but must be an integer if unique is `False`.
    unique : boolean, optional
        If `True`, use a digit-generation strategy which gives the shortest
        representation which uniquely identifies the floating-point number from
        other values of the same type, by judicious rounding. If `precision`
        is given fewer digits than necessary can be printed. If `min_digits`
        is given more can be printed, in which cases the last digit is rounded
        with unbiased rounding.
        If `False`, digits are generated as if printing an infinite-precision
        value and stopping after `precision` digits, rounding the remaining
        value with unbiased rounding
    trim : one of 'k', '.', '0', '-', optional
        Controls post-processing trimming of trailing digits, as follows:

        * 'k' : keep trailing zeros, keep decimal point (no trimming)
        * '.' : trim all trailing zeros, leave decimal point
        * '0' : trim all but the zero before the decimal point. Insert the
          zero if it is missing.
        * '-' : trim trailing zeros and any trailing decimal point
    sign : boolean, optional
        Whether to show the sign for positive values.
    pad_left : non-negative integer, optional
        Pad the left side of the string with whitespace until at least that
        many characters are to the left of the decimal point.
    exp_digits : non-negative integer, optional
        Pad the exponent with zeros until it contains at least this
        many digits. If omitted, the exponent will be at least 2 digits.
    min_digits : non-negative integer or None, optional
        Minimum number of digits to print. This only has an effect for
        `unique=True`. In that case more digits than necessary to uniquely
        identify the value may be printed and rounded unbiased.

        .. versionadded:: 1.21.0

    Returns
    -------
    rep : string
        The string representation of the floating point value

    See Also
    --------
    format_float_positional

    Examples
    --------
    >>> import numpy as np
    >>> np.format_float_scientific(np.float32(np.pi))
    '3.1415927e+00'
    >>> s = np.float32(1.23e24)
    >>> np.format_float_scientific(s, unique=False, precision=15)
    '1.230000071797338e+24'
    >>> np.format_float_scientific(s, exp_digits=4)
    '1.23e+0024'
    rF   r'  r;  r*  r
   2min_digits must be less than or equal to precision)rF   r/   r  r_   r'  r;  r*  )r  rK   r   )r   rF   r/   r  r_   r'  r;  r*  r'   r'   r+   r   T  s   
F


r   c	           	      C   sv   t |d}t |d}t |d}t |d}|s|dkrtd|dkr.|dkr.||kr.tdt| ||||||||d	S )	a  
    Format a floating-point scalar as a decimal string in positional notation.

    Provides control over rounding, trimming and padding. Uses and assumes
    IEEE unbiased rounding. Uses the "Dragon4" algorithm.

    Parameters
    ----------
    x : python float or numpy floating scalar
        Value to format.
    precision : non-negative integer or None, optional
        Maximum number of digits to print. May be None if `unique` is
        `True`, but must be an integer if unique is `False`.
    unique : boolean, optional
        If `True`, use a digit-generation strategy which gives the shortest
        representation which uniquely identifies the floating-point number from
        other values of the same type, by judicious rounding. If `precision`
        is given fewer digits than necessary can be printed, or if `min_digits`
        is given more can be printed, in which cases the last digit is rounded
        with unbiased rounding.
        If `False`, digits are generated as if printing an infinite-precision
        value and stopping after `precision` digits, rounding the remaining
        value with unbiased rounding
    fractional : boolean, optional
        If `True`, the cutoffs of `precision` and `min_digits` refer to the
        total number of digits after the decimal point, including leading
        zeros.
        If `False`, `precision` and `min_digits` refer to the total number of
        significant digits, before or after the decimal point, ignoring leading
        zeros.
    trim : one of 'k', '.', '0', '-', optional
        Controls post-processing trimming of trailing digits, as follows:

        * 'k' : keep trailing zeros, keep decimal point (no trimming)
        * '.' : trim all trailing zeros, leave decimal point
        * '0' : trim all but the zero before the decimal point. Insert the
          zero if it is missing.
        * '-' : trim trailing zeros and any trailing decimal point
    sign : boolean, optional
        Whether to show the sign for positive values.
    pad_left : non-negative integer, optional
        Pad the left side of the string with whitespace until at least that
        many characters are to the left of the decimal point.
    pad_right : non-negative integer, optional
        Pad the right side of the string with whitespace until at least that
        many characters are to the right of the decimal point.
    min_digits : non-negative integer or None, optional
        Minimum number of digits to print. Only has an effect if `unique=True`
        in which case additional digits past those necessary to uniquely
        identify the value may be printed, rounding the last additional digit.

        .. versionadded:: 1.21.0

    Returns
    -------
    rep : string
        The string representation of the floating point value

    See Also
    --------
    format_float_scientific

    Examples
    --------
    >>> import numpy as np
    >>> np.format_float_positional(np.float32(np.pi))
    '3.1415927'
    >>> np.format_float_positional(np.float16(np.pi))
    '3.14'
    >>> np.format_float_positional(np.float16(0.3))
    '0.3'
    >>> np.format_float_positional(np.float16(0.3), unique=False, precision=10)
    '0.3000488281'
    rF   r'  r(  r*  r
   z4precision must be greater than 0 if fractional=FalserC  )rF   r/   r$  r  r_   r'  r(  r*  )r  rK   r   )	r   rF   r/   r$  r  r_   r'  r(  r*  r'   r'   r+   r     s   
N


r   c                   @   s   e Zd ZdddZdd ZdS )r   r8   c                 C   s   |j dkr5t|}t|}tt|}|dkr|dk rd}|dkr+|dv r+|d7 }t|tt|}nd}d| | d| _d S )Nr
   r:   r8   z+ r   z{:zd})r   rV   r   r&  rx   r   r4   )r   r   r_   data_maxdata_mindata_max_str_lenmax_str_lenr'   r'   r+   r    s   



zIntegerFormat.__init__c                 C   s   | j  |S r&   r3   r   r   r'   r'   r+   r=    r   zIntegerFormat.__call__N)r8   r?  r@  rA  r  r=  r'   r'   r'   r+   r     s    
r   c                   @   s   e Zd Zdd Zdd ZdS )r   c                 K   s   |j dkr
d| _d S d| _d S )Nr'   z TrueTrue)rz   truestr)r   r   rt   r'   r'   r+   r    s   zBoolFormat.__init__c                 C   s   |r| j S dS )NFalse)rK  rH  r'   r'   r+   r=       zBoolFormat.__call__NrI  r'   r'   r'   r+   r     s    r   c                   @   s*   e Zd ZdZ	d	ddddZdd ZdS )
r   z. Formatter for subtypes of np.complexfloating FNr   c          	      C   sb   t |tr|r	dnd}| }}|dkrd}d}t|j|||||d| _t|j|||d|d| _d S )Nr9   r8   r@   r1   r0   )r_   r;   )rR   rJ   r   realreal_formatimagimag_format)	r   r   rF   ra   r   r_   r;   floatmode_realfloatmode_imagr'   r'   r+   r     s   


zComplexFloatingFormat.__init__c                 C   sH   |  |j}| |j}t| }|d | d ||d   }|| S )Nj)rO  rN  rQ  rP  rx   r   )r   r   rr  spr'   r'   r+   r=  4  s
   zComplexFloatingFormat.__call__r>  )r?  r@  rA  rB  r  r=  r'   r'   r'   r+   r     s    r   c                   @   $   e Zd Zdd Zdd Zdd ZdS )_TimelikeFormatc                 C   s~   |t |  }t|dkr#tt| t|t| t|}nd}t||jk r1t|d}d|| _d	|| _
d S )Nr
      z%{}sz'NaT')r   rx   r   _format_non_natrV   r&  r   r4   _formatrjust_nat)r   r   non_natrG  r'   r'   r+   r  @  s   
z_TimelikeFormat.__init__c                 C   s   t r&   )NotImplementedErrorrH  r'   r'   r+   rZ  N  s   z_TimelikeFormat._format_non_natc                 C   s   t |r| jS | j| | S r&   )r   r]  r[  rZ  rH  r'   r'   r+   r=  R  s   z_TimelikeFormat.__call__N)r?  r@  rA  r  rZ  r=  r'   r'   r'   r+   rX  ?  s    rX  c                       s6   e Zd Z		d
 fdd	Z fddZdd	 Z  ZS )r   N	same_kindFc                    s\   |d u r|j jdkrt|j d }nd}|d u rd}|| _|| _|| _|| _t | d S )NMr
   r   naive)	r   kindr   timezoneunitcastingr;   superr  )r   r   re  rd  rf  r;   	__class__r'   r+   r  Z  s   zDatetimeFormat.__init__c                    s    | j dkr
| |S t |S )Nr@   )r;   rZ  rg  r=  rH  rh  r'   r+   r=  m  s   

zDatetimeFormat.__call__c                 C   s   dt || j| j| jd S )N'%s')re  rd  rf  )r   re  rd  rf  rH  r'   r'   r+   rZ  r  s
   zDatetimeFormat._format_non_nat)NNr`  F)r?  r@  rA  r  r=  rZ  __classcell__r'   r'   rh  r+   r   Y  s    r   c                   @   s   e Zd Zdd ZdS )r   c                 C   s   t |dS )Ni8)r   astyperH  r'   r'   r+   rZ  z  rM  zTimedeltaFormat._format_non_natN)r?  r@  rA  rZ  r'   r'   r'   r+   r   y  s    r   c                   @   rW  )SubArrayFormatc                 K   s   || _ |d | _|d | _d S )NrZ   r[   )r   rZ   r  )r   r   rc   r'   r'   r+   r    s   
zSubArrayFormat.__init__c                 C   s    |j | jkrdnd| _| |S )Nr   r   )r   rZ   r   format_array)r   r}   r'   r'   r+   r=    s   
zSubArrayFormat.__call__c                    s   t |dkr |S  jr;|jd d j kr; fdd|d  j D  jg  fdd| j d  D  }n	 fdd|D }dd| d	 S )
Nr
   rv   c                       g | ]}  |qS r'   ro  r(   a_r   r'   r+   r         z/SubArrayFormat.format_array.<locals>.<listcomp>c                    rp  r'   rq  rr  rt  r'   r+   r     ru  c                    rp  r'   rq  rr  rt  r'   r+   r     ru  r   r2   r   )rV   ry   r   r   rz   r  rL   )r   r}   	formattedr'   rt  r+   ro    s   
zSubArrayFormat.format_arrayN)r?  r@  rA  r  r=  ro  r'   r'   r'   r+   rn  ~  s    rn  c                   @   s,   e Zd ZdZdd Zedd Zdd ZdS )	r   z
    Formatter for structured np.void objects.

    This does not work on structured alias types like
    np.dtype(('i4', 'i2,i2')), as alias scalars lose their field information,
    and the implementation relies upon np.void.__getitem__.
    c                 C   s
   || _ d S r&   )format_functions)r   rw  r'   r'   r+   r    s   
zStructuredVoidFormat.__init__c                 K   sX   g }|j jD ]!}t|| fi |}|j | jdkr"t|fi |}|| q| |S )z
        This is a second way to initialize StructuredVoidFormat,
        using the raw data as input. Added to avoid changing
        the signature of __init__.
        r'   )r   r   r   rz   rn  append)clsr   rc   rw  
field_namer   r'   r'   r+   r     s   zStructuredVoidFormat.from_datac                 C   s@   dd t || jD }t|dkrd|d S dd|S )Nc                 S   s   g | ]\}}||qS r'   r'   )r(   fieldr   r'   r'   r+   r     s    z1StructuredVoidFormat.__call__.<locals>.<listcomp>r   z({},)r
   z({})r2   )r+  rw  rx   r4   rL   )r   r   
str_fieldsr'   r'   r+   r=    s   
zStructuredVoidFormat.__call__N)r?  r@  rA  rB  r  classmethodr   r=  r'   r'   r'   r+   r     s    
r   c                 C   s   t   }|d dkrtjt| fi || S |ddu r$i |d< |d dt tjt| fi || }|s=|S t| }|j	
ddd |j }ttj| jf}| d	| d
|dS )z
    Implements the repr for structured-void scalars. It is called from the
    scalartypes.c.src code, and is placed here because it uses the elementwise
    formatters defined above.
    r;   rD   r`   Nr   rg   rV   r  (z, dtype=))r%   rj   ro   r   r   r   
setdefaultr   r~   r@  replacer?  rV   r   r   )r   is_reprrc   val_reprry  cls_fqn
void_dtyper'   r'   r+   _void_scalar_to_string  s   r  c                 C   sL   t | } t d dkr| jt jkrdS | jdurdS | js!dS | jtv S )a@  
    Determine if the given dtype is implied by the representation
    of its values.

    Parameters
    ----------
    dtype : dtype
        Data type

    Returns
    -------
    implied : bool
        True if the dtype is implied by the representation of its values.

    Examples
    --------
    >>> import numpy as np
    >>> np._core.arrayprint.dtype_is_implied(int)
    True
    >>> np.array([1, 2, 3], int)
    array([1, 2, 3])
    >>> np._core.arrayprint.dtype_is_implied(np.int8)
    False
    >>> np.array([1, 2, 3], np.int8)
    array([1, 2, 3], dtype=int8)
    r;   r@   FN)	rV   r   r%   rj   r~   rJ   r   isnative_typelessdata)r   r'   r'   r+   dtype_is_implied  s   


r  c                 C   s   t | jtjjkrt| S | jdurt| S t| j tr"dt|  S | j	}| j
s.dt|  S |r>|d  r:| s>t|}|S )z
    Convert a dtype to a short form which evaluates to the same dtype.

    The intent is roughly that the following holds

    >>> from numpy import *
    >>> dt = np.int64([1, 2]).dtype
    >>> assert eval(dtype_short_repr(dt)) == dt
    Nrj  r
   )r~   __repr__rV   r   r   r   r   r   r"   r  r  isalphaisalnum)r   typenamer'   r'   r+   dtype_short_repr  s   

r  c              	   C   s  t  }|d }|dur|| S |du r|d }t| tur$t| j}nd}|d }|d dkr@| jdkr@| jjs@t| 	 }	n|| |||d	|d
d}	g }
| j
dkrW| jdksd|d dkrm| j
|d krm|
d| j  t| jrw| j
dkr|
dt| j  |
s||	 d
 S ||	 d }d	|
d
 }t||dd  }d}|d dkrt| jjtrddt|  }n|t| d |krddt|  }|| | S )zEInternal version of array_repr() that allows overriding array2string.rb   Nr\   r   r~  r;   r@   r'   r2   r  )r   r
   )r
      rZ   zshape=zdtype=,r   r   r:   )r%   rj   r~   r   r?  rz   r   r   r   r   r   rx  r  r  rL   rx   rfindr   r"   )arrr   rF   r   r   r9  rb   
class_namer   r   extrasarr_str	extra_strlast_line_lenspacerr'   r'   r+   _array_repr_implementation!  sH   
r  c                 C   r   r&   r'   r  r   rF   r   r'   r'   r+   _array_repr_dispatcherW     r  c                 C      t | |||S )a(  
    Return the string representation of an array.

    Parameters
    ----------
    arr : ndarray
        Input array.
    max_line_width : int, optional
        Inserts newlines if text is longer than `max_line_width`.
        Defaults to ``numpy.get_printoptions()['linewidth']``.
    precision : int, optional
        Floating point precision.
        Defaults to ``numpy.get_printoptions()['precision']``.
    suppress_small : bool, optional
        Represent numbers "very close" to zero as zero; default is False.
        Very close is defined by precision: if the precision is 8, e.g.,
        numbers smaller (in absolute value) than 5e-9 are represented as
        zero.
        Defaults to ``numpy.get_printoptions()['suppress']``.

    Returns
    -------
    string : str
      The string representation of an array.

    See Also
    --------
    array_str, array2string, set_printoptions

    Examples
    --------
    >>> import numpy as np
    >>> np.array_repr(np.array([1,2]))
    'array([1, 2])'
    >>> np.array_repr(np.ma.array([0.]))
    'MaskedArray([0.])'
    >>> np.array_repr(np.array([], np.int32))
    'array([], dtype=int32)'

    >>> x = np.array([1e-6, 4e-7, 2, 3])
    >>> np.array_repr(x, precision=6, suppress_small=True)
    'array([0.000001,  0.      ,  2.      ,  3.      ])'

    )r  r  r'   r'   r+   r   \  s   .r   c                 C   s   t | tr	t| S t| S r&   )rR   bytesr   r   )r*   r'   r'   r+   _guarded_repr_or_str  s   
r  c                 C   s\   t  d dkr| jdkr| jjst|  S | jdkr%ttj	
| dS || |||ddS )zDInternal version of array_str() that allows overriding array2string.r;   r@   r'   r:   r   )r%   rj   rz   r   r   r   r   r  rV   r   __getitem__)r}   r   rF   r   r   r'   r'   r+   _array_str_implementation  s   
r  c                 C   r   r&   r'   r}   r   rF   r   r'   r'   r+   _array_str_dispatcher  r  r  c                 C   r  )a|  
    Return a string representation of the data in an array.

    The data in the array is returned as a single string.  This function is
    similar to `array_repr`, the difference being that `array_repr` also
    returns information on the kind of array and its data type.

    Parameters
    ----------
    a : ndarray
        Input array.
    max_line_width : int, optional
        Inserts newlines if text is longer than `max_line_width`.
        Defaults to ``numpy.get_printoptions()['linewidth']``.
    precision : int, optional
        Floating point precision.
        Defaults to ``numpy.get_printoptions()['precision']``.
    suppress_small : bool, optional
        Represent numbers "very close" to zero as zero; default is False.
        Very close is defined by precision: if the precision is 8, e.g.,
        numbers smaller (in absolute value) than 5e-9 are represented as
        zero.
        Defaults to ``numpy.get_printoptions()['suppress']``.

    See Also
    --------
    array2string, array_repr, set_printoptions

    Examples
    --------
    >>> import numpy as np
    >>> np.array_str(np.arange(3))
    '[0 1 2]'

    )r  r  r'   r'   r+   r     s   %r   __wrapped__)r   )NNNNNNNNNNNN)
NNNNNNNNNN)r'   )r   )r:   r   )NTr)   FNNN)NTTr)   FNNN)T)NNN)`rB  __all____docformat__r   rS   rM   _threadr   ImportError_dummy_threadrg   rV   r   r   r   umathr   r   r   r   r   r   r   r   r   r   r   fromnumericr   numericr   r   r   r   r   r   r    r!   r"   r   r#   r$   r   r%   rX   rO   
contextlibrf   r   ri   r   rq   contextmanagerr{   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r   r   r   r   r   rX  r   r   rn  r   r  rJ   r  r  r  r  r  r   r  r  r  r   getattr_array2string_implpartial_default_array_str_default_array_reprr'   r'   r'   r+   <module>   s      
? 9
0
"2
)
	 6| P[
! 
%*!
7

1



)
