a
    yn„f '  ã                   @  sð   d dl mZ d dlZd dlmZ e ¡ ZG dd„ dƒZdd„ Z	G dd	„ d	ƒZ
G d
d„ de
ƒZG dd„ de
ƒZG dd„ de
ƒZG dd„ de
ƒZG dd„ de
ƒZG dd„ de
ƒZG dd„ de
ƒZG dd„ de
ƒZG dd„ de
ƒZG dd„ de
ƒZdS )é    )ÚannotationsN)ÚNumpyMetadatac                   @  s   e Zd Zddd„ZdS )ÚLookupNc                   sV   g }t ||ƒ ‡fdd„‰ |jjˆ_|ˆ_|ˆ_ˆjj‡ fdd„|D ƒtjd�ˆ_d S )Nc                   s4   t | tƒr| S t ˆ jtjjjƒr(| jjS | j	jS d S ©N)
Ú
isinstanceÚintÚnplikeÚakZ_nplikesZcupyZCupyÚdataZptrÚctypes)Úx)Úself© úR/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/awkward/_lookup.pyÚarrayptr   s
    
z!Lookup.__init__.<locals>.arrayptrc                   s   g | ]}ˆ |ƒ‘qS r   r   )Ú.0r   )r   r   r   Ú
<listcomp>   ó    z#Lookup.__init__.<locals>.<listcomp>)Údtype)	ÚtolookupÚbackendr   Ú	generatorÚ	positionsZasarrayÚnpZintpZ	arrayptrs)r   Úlayoutr   r   r   )r   r   r   Ú__init__   s    

ÿzLookup.__init__)N)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r      s   r   c                 C  sŒ  t | tjjƒr&t|  t tj¡¡|ƒS t | tjj	ƒr`t
| jƒdkrNt | |¡S t|  ¡ |ƒS �n(t | tjjƒrzt | |¡S t | tjjtjjfƒrœt | |¡S t | tjjƒr¶t | |¡S t | tjjƒrÐt | |¡S t | tjjƒrêt | |¡S t | tjjƒ�rt | |¡S t | tjjƒ�r"t | |¡S t | tjjƒ�r>t | |¡S t | tjj ƒ�rZt | |¡S t | tjj!ƒ�rvt" | |¡S t#dt$| ƒ› �ƒ‚d S )Né   zunrecognized Content: )%r   r	   ÚcontentsZ
EmptyArrayr   Zto_NumpyArrayr   r   Zfloat64Ú
NumpyArrayÚlenÚshapeÚNumpyLookupZto_RegularArrayÚRegularArrayÚRegularLookupÚ	ListArrayZListOffsetArrayÚ
ListLookupÚIndexedArrayÚIndexedLookupÚIndexedOptionArrayÚIndexedOptionLookupÚByteMaskedArrayÚByteMaskedLookupÚBitMaskedArrayÚBitMaskedLookupÚUnmaskedArrayÚUnmaskedLookupÚRecordArrayÚRecordLookupÚrecordZRecordÚ
UnionArrayÚUnionLookupÚAssertionErrorÚtype)r   r   r   r   r   r       s6    r   c                   @  s   e Zd ZdS )ÚContentLookupN)r   r   r   r   r   r   r   r:   L   s   r:   c                   @  s$   e Zd ZdZedd„ ƒZdd„ ZdS )r$   r   c                 C  s   t |ƒ}| | ¡ j¡ |S r   )r"   ÚappendZto_contiguousr
   ©Úclsr   r   Úposr   r   r   r   S   s    zNumpyLookup.tolookupc                 C  s*   |dksJ ‚t jj|j|| j  | jd�S )Nr   ©Ú
parameters)r	   r    r!   r   ÚARRAYr@   )r   Úlookupr>   Úfieldsr   r   r   ÚtolayoutY   s    ÿzNumpyLookup.tolayoutN)r   r   r   rA   Úclassmethodr   rD   r   r   r   r   r$   P   s   
r$   c                   @  s(   e Zd ZdZdZedd„ ƒZdd„ ZdS )r&   r   r   c                 C  s:   t |ƒ}| t |ƒ¡ | d ¡ t|j|ƒ||| j < |S r   ©r"   r;   r   ÚcontentÚCONTENTr<   r   r   r   r   d   s
    
zRegularLookup.tolookupc                 C  s@   | j  ||j|| j  |¡}tjj|| j|j|| j  | j	d�S ©Nr?   )
ÚcontenttyperD   r   rH   r	   r    r%   ÚsizeÚZEROS_LENGTHr@   ©r   rB   r>   rC   rG   r   r   r   rD   l   s    ÿüzRegularLookup.tolayoutN)r   r   r   rL   rH   rE   r   rD   r   r   r   r   r&   `   s
   
r&   c                   @  s,   e Zd ZdZdZdZedd„ ƒZdd„ ZdS )	r(   r   r   é   c                 C  sH   t |ƒ}| |jj¡ | |jj¡ | d ¡ t|j|ƒ||| j < |S r   )r"   r;   Ústartsr
   Ústopsr   rG   rH   r<   r   r   r   r   }   s    
zListLookup.tolookupc                 C  sj   |   | j¡|j|| j  ƒ}|   | j¡|j|| j  ƒ}| j ||j|| j  |¡}tj	j
|||| jd�S rI   )ÚIndexOfÚ	indextyper   ÚSTARTSÚSTOPSrJ   rD   rH   r	   r    r'   r@   )r   rB   r>   rC   rO   rP   rG   r   r   r   rD   †   s    ÿzListLookup.tolayoutN)	r   r   r   rS   rT   rH   rE   r   rD   r   r   r   r   r(   x   s   
r(   c                   @  s(   e Zd ZdZdZedd„ ƒZdd„ ZdS )r*   r   r   c                 C  s:   t |ƒ}| |jj¡ | d ¡ t|j|ƒ||| j < |S r   ©r"   r;   Úindexr
   r   rG   rH   r<   r   r   r   r   “   s
    
zIndexedLookup.tolookupc                 C  sL   |   | j¡|j|| j  ƒ}| j ||j|| j  |¡}tjj	||| j
d�S rI   )rQ   rR   r   ÚINDEXrJ   rD   rH   r	   r    r)   r@   ©r   rB   r>   rC   rV   rG   r   r   r   rD   ›   s
    ÿzIndexedLookup.tolayoutN©r   r   r   rW   rH   rE   r   rD   r   r   r   r   r*   �   s
   
r*   c                   @  s(   e Zd ZdZdZedd„ ƒZdd„ ZdS )r,   r   r   c                 C  s:   t |ƒ}| |jj¡ | d ¡ t|j|ƒ||| j < |S r   rU   r<   r   r   r   r   §   s
    
zIndexedOptionLookup.tolookupc                 C  sL   |   | j¡|j|| j  ƒ}| j ||j|| j  |¡}tjj	||| j
d�S rI   )rQ   rR   r   rW   rJ   rD   rH   r	   r    r+   r@   rX   r   r   r   rD   ¯   s    ÿÿzIndexedOptionLookup.tolayoutNrY   r   r   r   r   r,   £   s
   
r,   c                   @  s(   e Zd ZdZdZedd„ ƒZdd„ ZdS )r.   r   r   c                 C  s:   t |ƒ}| |jj¡ | d ¡ t|j|ƒ||| j < |S r   ©r"   r;   Úmaskr
   r   rG   rH   r<   r   r   r   r   ½   s
    
zByteMaskedLookup.tolookupc                 C  sP   |   | j¡|j|| j  ƒ}| j ||j|| j  |¡}tjj	||| j
| jd�S rI   )rQ   Úmasktyper   ÚMASKrJ   rD   rH   r	   r    r-   Ú
valid_whenr@   ©r   rB   r>   rC   r[   rG   r   r   r   rD   Å   s    ÿÿzByteMaskedLookup.tolayoutN)r   r   r   r]   rH   rE   r   rD   r   r   r   r   r.   ¹   s
   
r.   c                   @  s,   e Zd ZdZdZdZedd„ ƒZdd„ ZdS )	r0   r   r   rN   c                 C  sH   t |ƒ}| t |ƒ¡ | |jj¡ | d ¡ t|j|ƒ||| j < |S r   rZ   r<   r   r   r   r   Ô   s    
zBitMaskedLookup.tolookupc                 C  sb   |   | j¡|j|| j  ƒ}| j ||j|| j  |¡}tjj	||| j
|j|| j  | j| jd�S rI   )rQ   r\   r   r]   rJ   rD   rH   r	   r    r/   r^   ÚLENGTHZ	lsb_orderr@   r_   r   r   r   rD   Ý   s    ÿúzBitMaskedLookup.tolayoutN)	r   r   r   r`   r]   rH   rE   r   rD   r   r   r   r   r0   Ï   s   
r0   c                   @  s$   e Zd ZdZedd„ ƒZdd„ ZdS )r2   r   c                 C  s,   t |ƒ}| d ¡ t|j|ƒ||| j < |S r   rF   r<   r   r   r   r   ï   s    
zUnmaskedLookup.tolookupc                 C  s.   | j  ||j|| j  |¡}tjj|| jd�S rI   )rJ   rD   r   rH   r	   r    r1   r@   rM   r   r   r   rD   ö   s    ÿzUnmaskedLookup.tolayoutN)r   r   r   rH   rE   r   rD   r   r   r   r   r2   ì   s   
r2   c                   @  s(   e Zd ZdZdZedd„ ƒZdd„ ZdS )r4   r   r   c                 C  s\   t |ƒ}| t |ƒ¡ | d gt |jƒ ¡ t|jƒD ] \}}t||ƒ||| j | < q6|S r   )r"   r;   Úextendr    Ú	enumerater   ÚCONTENTS©r=   r   r   r>   ÚirG   r   r   r   r     s    zRecordLookup.tolookupc           	      C  sº   t |ƒdkrR|  |d ¡}|d us&J ‚| j|  ||j|| j |  |dd … ¡S g }t| jƒD ]0\}}| ||j|| j |  |¡}| |¡ q`tj	j
|| j|j|| j  | jd�S d S )Nr   r   r?   )r"   Z
fieldindexÚcontenttypesrD   r   rc   rb   r;   r	   r    r3   rC   r`   r@   )	r   rB   r>   rC   rV   r    re   rJ   r   r   r   r   rD   
  s$    
ÿÿüzRecordLookup.tolayoutN)r   r   r   r`   rc   rE   r   rD   r   r   r   r   r4   ý   s
   
r4   c                   @  s,   e Zd ZdZdZdZedd„ ƒZdd„ ZdS )	r7   r   r   rN   c                 C  sj   t |ƒ}| |jj¡ | |jj¡ | d gt |jƒ ¡ t|jƒD ] \}}t||ƒ||| j	 | < qD|S r   )
r"   r;   Útagsr
   rV   ra   r    rb   r   rc   rd   r   r   r   r   &  s    zUnionLookup.tolookupc           
      C  sŽ   |   | j¡|j|| j  ƒ}|   | j¡|j|| j  ƒ}g }t| jƒD ]0\}}| ||j|| j	 |  |¡}	| 
|	¡ qFtjj|||| jd�S rI   )rQ   Ztagstyper   ÚTAGSrR   rW   rb   rf   rD   rc   r;   r	   r    r6   r@   )
r   rB   r>   rC   rg   rV   r    re   rJ   r   r   r   r   rD   0  s    ÿzUnionLookup.tolayoutN)	r   r   r   rh   rW   rc   rE   r   rD   r   r   r   r   r7   !  s   
	r7   )Ú
__future__r   Zawkwardr	   Zawkward._nplikes.numpy_liker   Úinstancer   r   r   r:   r$   r&   r(   r*   r,   r.   r0   r2   r4   r7   r   r   r   r   Ú<module>   s    ,$