HEX
Server: LiteSpeed
System: Linux standart9.isimtescil.net 3.10.0-962.3.2.lve1.5.26.7.el7.x86_64 #1 SMP Wed Oct 2 07:53:12 EDT 2019 x86_64
User: karalev (5310)
PHP: 8.2.29
Disabled: NONE
Upload Files
File: //opt/alt/python37/lib64/python3.7/site-packages/numpy/core/__pycache__/records.cpython-37.pyc
B

<�Fd�r�@sdZddlmZmZmZddlZddlZddlmZ	ddlm
Zddlm
Z
mZmZdd	d
gZe	jZddd
ddd
ddddd
dddd�ZejZdd�ZGdd
�d
�ZGdd�dej�ZGdd	�d	e�Zd$dd�Zd%dd�Zd&dd�Zdd�Zd'dd �Zd(d"d#�ZdS))a�
Record Arrays
=============
Record arrays expose the fields of structured arrays as properties.

Most commonly, ndarrays contain elements of a single type, e.g. floats,
integers, bools etc.  However, it is possible for elements to be combinations
of these using structured types, such as::

  >>> a = np.array([(1, 2.0), (1, 2.0)], dtype=[('x', int), ('y', float)])
  >>> a
  array([(1, 2.0), (1, 2.0)],
        dtype=[('x', '<i4'), ('y', '<f8')])

Here, each element consists of two fields: x (and int), and y (a float).
This is known as a structured array.  The different fields are analogous
to columns in a spread-sheet.  The different fields can be accessed as
one would a dictionary::

  >>> a['x']
  array([1, 1])

  >>> a['y']
  array([ 2.,  2.])

Record arrays allow us to access fields as properties::

  >>> ar = np.rec.array(a)

  >>> ar.x
  array([1, 1])

  >>> ar.y
  array([ 2.,  2.])

�)�division�absolute_import�print_functionN�)�numeric)�numerictypes)�	isfileobj�bytes�long�record�recarray�
format_parser�>�<�=�s�|)�b�l�n�B�L�N�Srrrrr�I�icCsPg}xFtt|��D]6}||||dd�kr|||kr|�||�qW|S)z@Find duplication in a list, return a list of duplicated elementsrN)�range�len�append)�list�dupr�r!�E/opt/alt/python37/lib64/python3.7/site-packages/numpy/core/records.py�find_duplicateJsr#c@s4eZdZdZd
dd�Zddd�Zd	d
�Zdd�ZdS)r
a�
    Class to convert formats, names, titles description to a dtype.

    After constructing the format_parser object, the dtype attribute is
    the converted data-type:
    ``dtype = format_parser(formats, names, titles).dtype``

    Attributes
    ----------
    dtype : dtype
        The converted data-type.

    Parameters
    ----------
    formats : str or list of str
        The format description, either specified as a string with
        comma-separated format descriptions in the form ``'f8, i4, a5'``, or
        a list of format description strings  in the form
        ``['f8', 'i4', 'a5']``.
    names : str or list/tuple of str
        The field names, either specified as a comma-separated string in the
        form ``'col1, col2, col3'``, or as a list or tuple of strings in the
        form ``['col1', 'col2', 'col3']``.
        An empty list can be used, in that case default field names
        ('f0', 'f1', ...) are used.
    titles : sequence
        Sequence of title strings. An empty list can be used to leave titles
        out.
    aligned : bool, optional
        If True, align the fields by padding as the C-compiler would.
        Default is False.
    byteorder : str, optional
        If specified, all the fields will be changed to the
        provided byte-order.  Otherwise, the default byte-order is
        used. For all available string specifiers, see `dtype.newbyteorder`.

    See Also
    --------
    dtype, typename, sctype2char

    Examples
    --------
    >>> np.format_parser(['f8', 'i4', 'a5'], ['col1', 'col2', 'col3'],
    ...                  ['T1', 'T2', 'T3']).dtype
    dtype([(('T1', 'col1'), '<f8'), (('T2', 'col2'), '<i4'),
           (('T3', 'col3'), '|S5')])

    `names` and/or `titles` can be empty lists. If `titles` is an empty list,
    titles will simply not appear. If `names` is empty, default field names
    will be used.

    >>> np.format_parser(['f8', 'i4', 'a5'], ['col1', 'col2', 'col3'],
    ...                  []).dtype
    dtype([('col1', '<f8'), ('col2', '<i4'), ('col3', '|S5')])
    >>> np.format_parser(['f8', 'i4', 'a5'], [], []).dtype
    dtype([('f0', '<f8'), ('f1', '<i4'), ('f2', '|S5')])

    FNcCs.|�||�|�||�|�|�|j|_dS)N)�
_parseFormats�_setfieldnames�_createdescr�_descr�dtype)�self�formats�names�titles�aligned�	byteorderr!r!r"�__init__�s
zformat_parser.__init__rcs�|dkrtd��t|t�r:t|�dkr0|�d�d�|�}t�||�}|j��dkrlt�d|fg|�}|j�|j	}�fdd�|D�|_
�fd	d�|D�|_t|�|_dS)
z Parse the field formats NzNeed formats argument���,�f1csg|]}�|d�qS)rr!)�.0�key)�fieldsr!r"�
<listcomp>�sz/format_parser._parseFormats.<locals>.<listcomp>csg|]}�|d�qS)rr!)r4r5)r6r!r"r7�s)
�
ValueError�
isinstancerrr�join�sbr(r6r+�
_f_formats�_offsets�_nfields)r)r*r-r(�keysr!)r6r"r$�s


zformat_parser._parseFormatscCs�|rXt|�ttgkrn&t|t�r,|�d�}ntdt|���dd�|d|j�D�|_	ng|_	|j	dd�t
t|j	�|j�D�7_	t|j	�}|r�t
d|��|r�dd�|d|j�D�|_n
g|_g}|jt|�kr�|jdg|jt|�7_dS)	zQconvert input field names into a list and assign to the _names
        attribute r2zillegal input names %scSsg|]}|���qSr!)�strip)r4rr!r!r"r7�sz0format_parser._setfieldnames.<locals>.<listcomp>NcSsg|]}d|�qS)zf%dr!)r4rr!r!r"r7�szDuplicate field names: %scSsg|]}|���qSr!)r@)r4rr!r!r"r7�s)�typer�tupler9�str�split�	NameError�reprr>�_namesrrr#r8�_titles)r)r+r,Z_dupr!r!r"r%�s&

zformat_parser._setfieldnamescCsDt�|j|j|j|jd��}|dk	r:t|d}|�|�}||_dS)N)r+r*Zoffsetsr,r)	r;r(rGr<r=rH�_byteorderconvZnewbyteorderr')r)r.�descrr!r!r"r&�s
zformat_parser._createdescr)FN)r)�__name__�
__module__�__qualname__�__doc__r/r$r%r&r!r!r!r"r
Ss
:

$c@sHeZdZdZdZdZdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)rzEA data-type scalar that allows field access as attribute lookup.
    �numpycCs|��S)N)�__str__)r)r!r!r"�__repr__�szrecord.__repr__cCst|���S)N)rC�item)r)r!r!r"rP�szrecord.__str__cCs�|dkrtj�||�Sytj�||�Stk
r8YnXtj�|d�j}|�|d�}|r�|j|dd��}y
|j}Wntk
r�|SX|jr�|�|j	|jjf�S|Std|��dS)N)�setfield�getfieldr(r(r0z%'record' object has no attribute '%s')
�nt�void�__getattribute__�AttributeErrorr6�getrTr(�view�	__class__)r)�attr�	fielddict�res�objZdtr!r!r"rW�s&
zrecord.__getattribute__cCsx|dkrtd|��tj�|d�j}|�|d�}|rL|j|f|dd���St||d�rhtj�|||�Std|��dS)N)rSrTr(zCannot set '%s' attributer(r0z%'record' object has no attribute '%s')	rXrUrVrWr6rYrS�getattr�__setattr__)r)r\�valr]r^r!r!r"ra�szrecord.__setattr__cCs>tj�||�}t|tj�r6|jjr6|�|j|jjf�S|SdS)N)rUrV�__getitem__r9r(r6rZr[)r)�indxr_r!r!r"rc
szrecord.__getitem__cCsV|jj}tdd�|D��}g}d|}x$|D]}|�||t||�f�q,Wd�|�S)zPretty-print all fields.css|]}t|�VqdS)N)r)r4�namer!r!r"�	<genexpr>sz record.pprint.<locals>.<genexpr>z%% %ds: %%s�
)r(r+�maxrr`r:)r)r+�maxlenZrows�fmtrer!r!r"�pprints
z
record.pprintN)
rKrLrMrNrQrPrWrarcrkr!r!r!r"r�s
c
s\eZdZdZdZdZddd�Zd	d
�Zdd�Zd
d�Z�fdd�Zdd�Z	ddd�Z
�ZS)ra2Construct an ndarray that allows field access using attributes.

    Arrays may have a data-types containing fields, analogous
    to columns in a spread sheet.  An example is ``[(x, int), (y, float)]``,
    where each entry in the array is a pair of ``(int, float)``.  Normally,
    these attributes are accessed using dictionary lookups such as ``arr['x']``
    and ``arr['y']``.  Record arrays allow the fields to be accessed as members
    of the array, using ``arr.x`` and ``arr.y``.

    Parameters
    ----------
    shape : tuple
        Shape of output array.
    dtype : data-type, optional
        The desired data-type.  By default, the data-type is determined
        from `formats`, `names`, `titles`, `aligned` and `byteorder`.
    formats : list of data-types, optional
        A list containing the data-types for the different columns, e.g.
        ``['i4', 'f8', 'i4']``.  `formats` does *not* support the new
        convention of using types directly, i.e. ``(int, float, int)``.
        Note that `formats` must be a list, not a tuple.
        Given that `formats` is somewhat limited, we recommend specifying
        `dtype` instead.
    names : tuple of str, optional
        The name of each column, e.g. ``('x', 'y', 'z')``.
    buf : buffer, optional
        By default, a new array is created of the given shape and data-type.
        If `buf` is specified and is an object exposing the buffer interface,
        the array will use the memory from the existing buffer.  In this case,
        the `offset` and `strides` keywords are available.

    Other Parameters
    ----------------
    titles : tuple of str, optional
        Aliases for column names.  For example, if `names` were
        ``('x', 'y', 'z')`` and `titles` is
        ``('x_coordinate', 'y_coordinate', 'z_coordinate')``, then
        ``arr['x']`` is equivalent to both ``arr.x`` and ``arr.x_coordinate``.
    byteorder : {'<', '>', '='}, optional
        Byte-order for all fields.
    aligned : bool, optional
        Align the fields in memory as the C-compiler would.
    strides : tuple of ints, optional
        Buffer (`buf`) is interpreted according to these strides (strides
        define how many bytes each array element, row, column, etc.
        occupy in memory).
    offset : int, optional
        Start reading buffer (`buf`) from this offset onwards.
    order : {'C', 'F'}, optional
        Row-major (C-style) or column-major (Fortran-style) order.

    Returns
    -------
    rec : recarray
        Empty array of the given shape and type.

    See Also
    --------
    rec.fromrecords : Construct a record array from data.
    record : fundamental data-type for `recarray`.
    format_parser : determine a data-type from formats, names, titles.

    Notes
    -----
    This constructor can be compared to ``empty``: it creates a new record
    array but does not fill it with data.  To create a record array from data,
    use one of the following methods:

    1. Create a standard ndarray and convert it to a record array,
       using ``arr.view(np.recarray)``
    2. Use the `buf` keyword.
    3. Use `np.rec.fromrecords`.

    Examples
    --------
    Create an array with two fields, ``x`` and ``y``:

    >>> x = np.array([(1.0, 2), (3.0, 4)], dtype=[('x', float), ('y', int)])
    >>> x
    array([(1.0, 2), (3.0, 4)],
          dtype=[('x', '<f8'), ('y', '<i4')])

    >>> x['x']
    array([ 1.,  3.])

    View the array as a record array:

    >>> x = x.view(np.recarray)

    >>> x.x
    array([ 1.,  3.])

    >>> x.y
    array([2, 4])

    Create a new, empty record array:

    >>> np.recarray((2,),
    ... dtype=[('x', int), ('y', float), ('z', int)]) #doctest: +SKIP
    rec.array([(-1073741821, 1.2249118382103472e-301, 24547520),
           (3471280, 1.2134086255804012e-316, 0)],
          dtype=[('x', '<i4'), ('y', '<f8'), ('z', '<i4')])

    rONrF�Cc	Csf|dk	rt�|�}nt||||
|	�j}|dkrFtj||t|f|d�}
ntj||t|f||||d�}
|
S)N)�order)�buffer�offset�stridesrm)r;r(r
r'�ndarray�__new__r)Zsubtype�shaper(�bufrorpr*r+r,r.r-rmrJr)r!r!r"rr�s
zrecarray.__new__cCs |jjtk	r|jjr|j|_dS)N)r(rArr6)r)r_r!r!r"�__array_finalize__�szrecarray.__array_finalize__c	Cs�yt�||�Stk
r YnXt�|d�j}y||dd�}Wn$ttfk
rhtd|��YnX|j|�}|jjr�t	|jj
tj�r�|j
|jj
|jfd�S|S|�
t�SdS)Nr(r0zrecarray has no attribute %s)r()�objectrWrXrqr6�	TypeError�KeyErrorrTr(�
issubclassrArUrVrZ)r)r\r]r^r_r!r!r"rW�s
zrecarray.__getattribute__c		Cs|dkr*t|jtj�r*|jr*t�t|f�}||jk}yt	�
|||�}WnBt�|d�jp^i}||kr�t
��dd�\}}||��Yn@Xt�|d�jp�i}||kr�|S|r�yt	�||�Wn
|Sy||dd�}Wn&ttfk
�rtd|��YnX|j|f|��S)Nr(r0z record array has no attribute %s)ryrArUrVr6r;r(r�__dict__rvrarqrW�sys�exc_info�__delattr__rwrxrXrS)	r)r\rbZnewattrZretr]�exctype�valuer^r!r!r"ra�s.
zrecarray.__setattr__csptt|��|�}t|t�rh|jjrZ|�t|��}t	|jjt
j�rV|j|jj|jfd�S|S|jtd�Sn|SdS)N)r()rA)�superrrcr9rqr(r6rZrAryrUrV)r)rdr_)r[r!r"rc�s
zrecarray.__getitem__cCs�|j}|jjtks"t|jjtj�sF|jtkr<t�tj|f�}d}d}nd}d}|jdksb|jdkrttj	|d|d�}nd	t
|j�f}d
dt|�}||||fS)Nz
rec.array(zrec.array(%s, %sdtype=%s)zarray(z*array(%s, %sdtype=%s).view(numpy.recarray)r)rz, )Z	separator�prefixz[], shape=%srg� )r(rArryrUrVr;�sizersZarray2stringrFr)r)Z
repr_dtyper�rjZlstZlfr!r!r"rQs
zrecarray.__repr__cCszt|t�r t�|d�j}||}t�|d�j}||dd�}|dkrf|j|�}|jjr\|S|�t�S|j	|f|��SdS)Nr(r0)
r9�intrqrWr+r6rTr(rZrS)r)r\rbr+r]r^r_r!r!r"�field"s


zrecarray.field)
NNrNNNNNFrl)N)rKrLrMrNrrrurWrarcrQr��
__classcell__r!r!)r[r"r*sh
" FcCs|dd�|D�}|dks|dkr(|dj}t|t�r8|f}|dkr�|dkr�g}x,|D]$}t|t�shtd��|�|jj�qRWd�|�}|dk	r�t	�|�}	|	j
}
nt|||||�}|j}
|j
}	t|	�t|�kr�td��|	dj}t|�}
|
dkr�|d|
�}xJt|�D]>\}}|	|j}
|jd|j|
�}||k�rtd|���qWt||	�}x&tt|��D]}||||
|<�q^W|S)	aA create a record array from a (flat) list of arrays

    >>> x1=np.array([1,2,3,4])
    >>> x2=np.array(['a','dd','xyz','12'])
    >>> x3=np.array([1.1,2,3,4])
    >>> r = np.core.records.fromarrays([x1,x2,x3],names='a,b,c')
    >>> print(r[1])
    (2, 'dd', 2.0)
    >>> x1[1]=34
    >>> r.a
    array([1, 2, 3, 4])
    cSsg|]}t�|��qSr!)r;Zasarray)r4�xr!r!r"r7Cszfromarrays.<locals>.<listcomp>Nrz*item in the array list must be an ndarray.r2z>mismatch between the number of fields and the number of arraysz array-shape mismatch in array %d)rsr9r�rqr8rr(rCr:r;r+r
rGr'r�	enumerate�ndimrr)Z	arrayListr(rsr*r+r,r-r.r_rJrGZparsedZd0Znn�kZ	testshape�_arrayrr!r!r"�
fromarrays4sB









r�c	s<|dkrP|dkrPtj|td���fdd�t�jd�D�}t|||||||d�S|dk	rht�t|f�}	nt|||||�j	}	ytj||	d�}
Wn�t
k
�r|dks�|dkr�t|�}t|t
tf�r�|f}t|�dkr�td	��t||	�}x"t|j�D]}t||�||<q�W|SX|dk	�r.|
j|k�r.||
_|
�t�}
|
S)
ad create a recarray from a list of records in text form

        The data in the same field can be heterogeneous, they will be promoted
        to the highest data type.  This method is intended for creating
        smaller record arrays.  If used to create large array without formats
        defined

        r=fromrecords([(2,3.,'abc')]*100000)

        it can be slow.

        If formats is None, then this will auto-detect formats. Use list of
        tuples rather than list of lists for faster processing.

    >>> r=np.core.records.fromrecords([(456,'dbe',1.2),(2,'de',1.3)],
    ... names='col1,col2,col3')
    >>> print(r[0])
    (456, 'dbe', 1.2)
    >>> r.col1
    array([456,   2])
    >>> r.col2
    array(['dbe', 'de'],
          dtype='|S3')
    >>> import pickle
    >>> print(pickle.loads(pickle.dumps(r)))
    [(456, 'dbe', 1.2) (2, 'de', 1.3)]
    N)r(cs"g|]}t��d|f����qS).)r;�array�tolist)r4r)r_r!r"r7�szfromrecords.<locals>.<listcomp>���)r*rsr+r,r-r.rrzCan only deal with 1-d array.)r;r�rvrrsr�r(rr
r'rwrr9r�r
r8rr�rBrZ)ZrecListr(rsr*r+r,r-r.ZarrlistrJZretvalr�r�r^r!)r_r"�fromrecordsus2


r�c	Cs�|dkr|dkrtd��|dk	r,t�|�}	nt|||||�j}	|	j}
|dks\|dks\|dkrlt|�||
}t||	||d�}|S)zM create a (read-only) record array from binary data contained in
    a stringNzMust have dtype= or formats=rr�)rtro)r8r;r(r
r'�itemsizerr)Z
datastringr(rsror*r+r,r-r.rJr�r�r!r!r"�
fromstring�sr�cCsPy|��}Wn&tk
r2tj�|j�|��SXt�|�}|j|��}|S)N)	�filenorX�os�path�getsizere�tell�fstat�st_size)�fd�fn�str�r!r!r"�get_remaining_size�s
r�c	Cs0|dks|dkrd}nt|ttf�r*|f}d}	t|t�rFd}	t|d�}|dkrZ|�|d�t|�}
|dk	rvt�|�}nt	|||||�j
}|j}t�|��
�}
|
|}|dkr�t|�}|
|||�d�<t|�}t�|��
�}
|
|}||
kr�td��t||�}|�|j�}||k�rtd��|	�r,|��|S)	amCreate an array from binary file data

    If file is a string then that file is opened, else it is assumed
    to be a file object. The file object must support random access
    (i.e. it must have tell and seek methods).

    >>> from tempfile import TemporaryFile
    >>> a = np.empty(10,dtype='f8,i4,a5')
    >>> a[5] = (0.5,10,'abcde')
    >>>
    >>> fd=TemporaryFile()
    >>> a = a.newbyteorder('<')
    >>> a.tofile(fd)
    >>>
    >>> fd.seek(0)
    >>> r=np.core.records.fromfile(fd, formats='f8,i4,a5', shape=10,
    ... byteorder='<')
    >>> print(r[5])
    (0.5, 10, 'abcde')
    >>> r.shape
    (10,)
    Nr)r�r�rbr�z:Not enough bytes left in file for specified shape and typez%Didn't read as many bytes as expected)r9r�r
rC�open�seekr�r;r(r
r'r�r�Zprodr�indexrBr8r�readinto�data�IOError�close)r�r(rsror*r+r,r-r.rer�rJr�Z	shapeprodZ	shapesize�nbytesr�Z
nbytesreadr!r!r"�fromfile�sB



r�TcCs t|td�tf�st|�r2|dkr2|dkr2td��i}|dk	rJt�|�}n,|dk	rft|||||	�j}n|||||	d�}|dkr�|dkr�td��t	|||||d�St|t
�r�t||f||d�|��St|tt
f��rt|dt
tf��r�t|f||d�|��St|f||d�|��S�nt|t	��rZ|dk	�rD|j|k�rD|�|�}n|}|
�rV|��}|St|��rtt||||d	�St|t��r�|dk	�r�|j|k�r�|�|�}n|}|
�r�|��}|�t	�St|d
d�}
|
dk�s�t|
t��s�td��t�|�}|dk	�r|j|k�r|�|�}|�t	�SdS)z=Construct a record array from a wide-variety of objects.
    NzIMust define formats (or dtype) if object is None, string, or an open file)r*r+r,r-r.z"Must define a shape if obj is None)rtrorp)rsror)r(rs)r(rsroZ__array_interface__zUnknown input type)r9rArCrr8r;r(r
r'rr	r�rrBr�r�rZ�copyr�rqr`�dictr�)r_r(rsrorpr*r+r,r-r.r��kwds�newZ	interfacer!r!r"r�s^




r�)NNNNNFN)NNNNNFN)NNrNNNFN)NNrNNNFN)
NNrNNNNFNT) rNZ
__future__rrrr{r�r1rr;rrUZnumpy.compatrr	r
�__all__rqrIZtypeDictZnumfmtr#r
rVrrr�r�r�r�r�r�r!r!r!r"�<module>$sR
	S
@
>
	
D