a
    yn„fl  ã                   @  sÖ   d dl mZ d dlmZmZmZ d dlZd dlm	Z	 d dl
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 d
Zerœd dlmZ e ¡ Zdddœdddœdd„ZeG dd„ de	eƒƒZ dS )é    )Úannotations)ÚCallableÚIterableÚIteratorN)Ú	NumpyMeta)ÚNumpyMetadata©Úunknown_length)ÚTYPE_CHECKINGÚAnyÚDTypeÚJSONMappingÚSelfÚfinal)ÚUNSET)ÚFormÚ_SpecifierMatcher)Ú	NumpyForm)ÚRegularFormF)Útime_units_as_parameterzJSONMapping | NoneÚbool)Ú
parametersr   c                C  sD   | j d u rd}n| j}| j d } |r,tdƒ‚ttjj | ¡||d�S )N© r   zy`time_units_as_parameter=True` is no longer supported; NumPy's time units are no longer converted into Awkward parameters)Ú	primitiver   Úinner_shape)ZsubdtypeÚshapeÚ
ValueErrorr   ÚakÚtypesÚ	numpytypeÚdtype_to_primitive)Údtyper   r   r   r   r   úZ/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/awkward/forms/numpyform.pyÚ
from_dtype   s    

ÿýr#   c                   @  sö   e Zd Zd2dddœdd„Zedd„ ƒZedd	„ ƒZeefeedœd
d„Ze	d3dddœdd„ƒZ
edd„ ƒZdd„ Zdd„ Zedd„ ƒZddœdd„Zdd„ Zdddœdd „Zd!dd"œd#d$„Zd%d&„ Zd'd(„ Zd)d!d*d+œd,d-„Zd.d!d!d!d/œd0d1„ZdS )4r   r   N©r   Úform_keyc                C  s\   t jj t jj |¡¡}t|tƒs:tt| ƒj	› d|›�ƒ‚|| _
t|ƒ| _| j||d� d S )Nz% 'inner_shape' must be iterable, not r$   )r   r   r   r    Úprimitive_to_dtypeÚ
isinstancer   Ú	TypeErrorÚtypeÚ__name__Ú
_primitiveÚtupleÚ_inner_shapeÚ_init©Úselfr   r   r   r%   r   r   r"   Ú__init__1   s    ÿ
ÿ
zNumpyForm.__init__c                 C  s   | j S ©N)r+   ©r0   r   r   r"   r   E   s    zNumpyForm.primitivec                 C  s   | j S r2   )r-   r3   r   r   r"   r   I   s    zNumpyForm.inner_shapec                C  sH   t |tu r| jn||tu r | jn||tu r0| jn||tu r@| jn|d�S ©Nr$   )r   r   r+   r-   Ú_parametersÚ	_form_keyr/   r   r   r"   ÚcopyM   s    üzNumpyForm.copyc                C  s   | ||||d�S r4   r   )Úclsr   r   r   r%   r   r   r"   Ú
simplified\   s    	zNumpyForm.simplifiedc                 C  s   t jj | j¡jS r2   )r   r   r   r&   r+   Úitemsizer3   r   r   r"   r:   g   s    zNumpyForm.itemsizec                 C  sR   t | jƒg}t| jƒdkr.| dt | jƒ ¡ ||  ¡ 7 }d t| ƒjd 	|¡¡S )Nr   zinner_shape=z{}({})z, )
Úreprr+   Úlenr-   ÚappendZ
_repr_argsÚformatr)   r*   Újoin)r0   Úargsr   r   r"   Ú__repr__k   s
    zNumpyForm.__repr__c                 C  s€   |s>|s>t | jƒdkr>| jd u s.t | jƒdkr>| jd u r>| jS d| jdœ}|s\t | jƒdkrpdd„ | jD ƒ|d< |  ||¡S d S )Nr   Z
NumpyArray)Úclassr   c                 S  s   g | ]}|t u rd n|‘qS r2   r   )Ú.0Úitemr   r   r"   Ú
<listcomp>‚   s   ÿz+NumpyForm._to_dict_part.<locals>.<listcomp>r   )r<   r-   r5   r6   r+   Z_to_dict_extra)r0   ÚverboseÚtoplevelÚoutr   r   r"   Ú_to_dict_partr   s*    ÿþýüüûþþ
zNumpyForm._to_dict_partc                 C  sB   t jj| jd d�}| jd d d… D ]}t j ||¡}q"| j|_|S )N)r   éÿÿÿÿ)r   r   Z	NumpyTyper+   r-   ZRegularTyper5   ©r0   rH   Úxr   r   r"   r)   ˆ   s    þzNumpyForm.typezRegularForm | NumpyForm)Úreturnc                 C  sH   t | jdd d d�}| jd d d… D ]}tjj||d d d�}q"| j|_|S )Nr   r$   rJ   )r   r+   r-   r   Zformsr   r5   rK   r   r   r"   Úto_RegularForm•   s    
ÿzNumpyForm.to_RegularFormc                 C  s   |  d |¡¡ d S )NÚ.)r=   r?   )r0   ÚpathÚoutputZlist_indicatorr   r   r"   Ú_columnsž   s    zNumpyForm._columnsr   r   )Úmatch_specifierrM   c                 C  s   | S r2   r   )r0   rS   r   r   r"   Ú_select_columns¡   s    zNumpyForm._select_columnsr   )Úis_inside_record_or_unionrM   c                 C  s   | S r2   r   )r0   rU   r   r   r"   Ú_prune_columns¤   s    zNumpyForm._prune_columnsc                 C  s   t jj | j¡fS r2   )r   r   r   r&   r+   r3   r   r   r"   Ú_column_types§   s    zNumpyForm._column_typesc           
      C  s  t |tƒr| j |¡ �nþ|\}}}}}}| d¡ d¡ d¡}|dkrXt tj¡}�nŽ|dv rÄ|dkrvt tj¡}nJ|dkrŒt tj	¡}n4|dkr¢t tj
¡}n|d	kr¸t tj¡}nt|ƒ‚�n"|d
v �r4|dkrät tj¡}nN|dkrút tj¡}n8|dk�rt tj¡}n |d	k�r*t tj¡}nt|ƒ‚n²|dk�rLt tj¡}nš|dk�rdt tj¡}n‚|dk�r|t tj¡}nj|dk�r”t tj¡}nR|dk�r¬t tj¡}n:|dk�rÄt tj¡}n"|dk�rÜt tj¡}n
t |¡}tjj |¡}	|d u�rd| }| j|	|||d� d S )Nú<ú>ú=ú?)ÚbÚhÚiÚlÚqé   é   é   é   )ÚcÚBÚHÚIÚLÚQÚeÚfÚdÚgZZfZZdZZgzpart0-r$   )r'   ÚdictÚ__dict__ÚupdateÚlstripÚnpr!   Zbool_Zint8Zint16Zint32Zint64ÚAssertionErrorZuint8Zuint16Zuint32Zuint64Zfloat16Zfloat32Zfloat64Zfloat128Z	complex64Z
complex128Z
complex256r   r   r   r    r1   )
r0   ÚstateZhas_identitiesr   r%   r   r:   r>   r!   r   r   r   r"   Ú__setstate__ª   s^    













ÿzNumpyForm.__setstate__zCallable[[Form, str], str]zIterator[tuple[str, DType]])ÚgetkeyÚ	recursiverM   c                 c  s&   ddl m} || dƒ|| jƒfV  d S )Nr   )r&   Údata)Zawkward.types.numpytyper&   r   )r0   rw   rx   r&   r   r   r"   Ú_expected_from_buffersê   s    z NumpyForm._expected_from_buffersr   )ÚotherÚall_parametersr%   rM   c                 C  s   |   |||¡o| j|jkS r2   )Z_is_equal_to_genericr+   )r0   r{   r|   r%   r   r   r"   Ú_is_equal_toñ   s    
ÿzNumpyForm._is_equal_to)r   )r   )r*   Ú
__module__Ú__qualname__r1   Úpropertyr   r   r   r7   Úclassmethodr9   r:   rA   rI   r)   rN   rR   rT   rV   rW   rv   rz   r}   r   r   r   r"   r   /   sF    ýú

ýú ýú


	@r   )N)!Ú
__future__r   Úcollections.abcr   r   r   Zawkwardr   Zawkward._meta.numpymetar   Zawkward._nplikes.numpy_liker   Zawkward._nplikes.shaper	   Zawkward._typingr
   r   r   r   r   r   Zawkward._utilr   Zawkward.forms.formr   r   Ú__all__Zawkward.forms.regularformr   Úinstancers   r#   r   r   r   r   r"   Ú<module>   s$     þü