a
    yn„f1  ã                   @  s@  d dl mZ d dlZd dlmZm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 d d	lmZ d d
lmZ d dlmZ d dlmZ e ¡ Zd_dddddddddddddœdd„Zd`dddddd d!d"œd#d$„Z ddd%œd&d'„Z!daddddd)dd*œd+d,„Z"dbd-dd.œd/d0„Z#dcdd1œd2d3„Z$dddddddd4œd5d6„Z%dedd7dd8œd9d:„Z&dd;ddd<œd=d>„Z'dddd?œd@dA„Z(dBdC„ Z)dfdddddDœdEdF„Z*dGddHœdIdJ„Z+dgddLdMddddNœdOdP„Z,dhdd;d;dRœdSdT„Z-didd7ddddUœdVdW„Z.djdd7ddddUœdXdY„Z/dkdddZœd[d\„Z0dldddZœd]d^„Z1dS )mé    )ÚannotationsN)ÚMappingÚMutableMapping)ÚIntegral)ÚBackend)ÚNumpyMetadata)ÚAnyÚAxisMaybeNoneÚLiteral)Ú
ActionTypeÚContent)Úremove_structure)Ú	AxisError)Úform)ÚRecordTFzContent | Recordr   zdict | Nonezdict[str, Any] | NoneÚboolz
str | NonezContent | Record | None)ÚlayoutÚactionÚbehaviorÚdepth_contextÚlateral_contextÚallow_recordsÚkeep_parametersÚnumpy_to_regularÚreturn_simplifiedÚreturn_arrayÚfunction_nameÚreturnc                 C  sr   t | tƒr2|  |dt |¡|||||||	|
dœ¡S t | tƒrnt| j|||||||||	|
ƒ}|	rjt|| jƒS d S d S )Né   )r   r   r   Úregular_to_jaggedr   r   r   )Ú
isinstancer   Z_recursively_applyÚcopyr   Úrecursively_applyZ_arrayÚat)r   r   r   r   r   r   r   r   r   r   r   r   Úout© r%   úN/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/awkward/_do.pyr"      s@    
ùû
õr"   ú{form_key}-{attribute}únode{id}ú<r   zMutableMapping[str, Any] | Noner   zBackend | NonezLiteral['<', '>']z(tuple[form.Form, int, Mapping[str, Any]])ÚcontentÚ	containerÚform_keyÚid_startÚbackendÚ	byteorderr   c           	        s¨   |d u ri }|d u r| j }|jjs*tdƒ‚tˆ tƒrB‡ fdd„}n(tˆ ƒrX‡ fdd„}ntdtˆ ƒ› �ƒ‚|d u rztdƒ‚| j||d�}|  	|||||¡ |t
| ƒ|fS )Nz:cannot call 'to_buffers' on an array without concrete datac                   s   ˆ j |j|d�S )N)r,   Ú	attribute)Úformatr,   ©r   r   r0   ©Ú
buffer_keyr%   r&   Úgetkey\   s    zto_buffers.<locals>.getkeyc                   s   ˆ |j || |d�S )N)r,   r0   r   r   )r,   r2   r3   r%   r&   r5   a   s    üz/buffer_key must be a string or a callable, not zSa 'form_key' must be supplied, to match Form elements to buffers in the 'container')r,   r-   )Ú_backendÚnplikeZ
known_dataÚ	TypeErrorr    ÚstrÚcallableÚtypeZform_with_keyZ_to_buffersÚlen)	r*   r+   r4   r,   r-   r.   r/   r5   r   r%   r3   r&   Ú
to_buffersJ   s(    	
	ÿÿr=   ©r   Úaxisc                 C  s   |   |d¡S ©Nr   )Z_local_indexr>   r%   r%   r&   Úlocal_indexz   s    rA   r   zlist[str] | None)r   ÚnÚreplacementr?   ÚfieldsÚ
parametersc                 C  sH   |dk rt dƒ‚d }|d ur4|}t|ƒ|kr4t dƒ‚|  |||||d¡S )Nr   z'in combinations, 'n' must be at least 1z/if provided, the length of 'fields' must be 'n')Ú
ValueErrorr<   Z_combinations)r   rB   rC   r?   rD   rE   Zrecordlookupr%   r%   r&   Úcombinations~   s    rG   zIntegral | None)r?   r   c                 C  sP   |d u r|n| }t jjjd| jjd�}t jjj| j| jjd�}|  |||d¡S )Nr   ©r7   )ÚakÚindexÚIndex64Úzerosr6   Úindex_nplikeÚlengthZ
_is_unique)r   r?   ÚnegaxisÚstartsÚparentsr%   r%   r&   Ú	is_unique‘   s    rR   )r   c                 C  sð   |dks|d u rÜ|d u r|n| }|d urž| j \}}|rh|dkrHtdƒ‚||kržtd|› d|› d�ƒ‚n6|dkrx|| }d|k rˆ||ksžtd|› d|› d	�ƒ‚tjjjd
| jjd�}tjjj| j| jjd�}|  	|||d
¡S td|› d�ƒ‚d S )Néÿÿÿÿr   ú˜cannot use non-negative axis on a nested list structure of variable depth (negative axis counts from the leaves of the tree; non-negative from the root)úcannot use axis=ú] on a nested list structure that splits into different depths, the minimum of which is depth=ú from the leavesúaxis=z" exceeds the depth of this array (ú)r   rH   z-unique expects axis 'None' or '-1', got axis=z that is not supported yet)
Úbranch_depthr   rI   rJ   rK   rL   r6   rM   rN   Ú_unique)r   r?   rO   ÚbranchÚdepthrP   rQ   r%   r%   r&   Úunique˜   s:    
ÿÿÿÿ
ÿ
ÿr^   )r   rN   r?   Úclipr   c                 C  s   |   ||d|¡S r@   )Z	_pad_none)r   rN   r?   r_   r%   r%   r&   Úpad_none½   s    r`   Úint)r   r?   r   c                 C  s   |   |d¡\}}|S r@   )Z_offsets_and_flattened)r   r?   ÚoffsetsZ	flattenedr%   r%   r&   ÚflattenÃ   s    rc   r9   )r   ÚnameÚincluding_unknownr   c                 C  s   |   ||¡S ©N)Z_numbers_to_type)r   rd   re   r%   r%   r&   Únumbers_to_typeÈ   s    rg   )r   Úvaluer   c                 C  s
   |   |¡S rf   )Z
_fill_none)r   rh   r%   r%   r&   Ú	fill_noneÌ   s    ri   c                 C  s   |   |d¡S )Nr   )Z_numr>   r%   r%   r&   ÚnumÐ   s    rj   )ÚoneÚtwoÚ	mergeboolr   c                 C  s   | j ||d�S )N)rm   )Z_mergeable_next)rk   rl   rm   r%   r%   r&   Ú	mergeableÔ   s    rn   zlist[Content])Úcontentsr   c                 C  s&   t | ƒdksJ ‚| d  | dd … ¡S )Nr   r   )r<   Z
_mergemany)ro   r%   r%   r&   Ú	mergemanyØ   s    rp   rS   zak._reducers.Reducerr	   )r   Úreducerr?   ÚmaskÚkeepdimsr   c                 C  s†  | j  |¡}|d u r¬t| dd|ddd�}t|ƒdkr>tdƒ‚nt|ƒdkrVtj ¡ } n|\} tjj	 
d| j j¡}tjj	 
| j| j j¡}d }	|  |d||	|d|||¡	}
|
d S | }| j\}}|rð|dkrÐtdƒ‚||krîtd|› d	|› d
�ƒ‚nB|dk�r||7 }d|  k �r|k�s2n td|› d|› d�ƒ‚tjj	 
d| j j¡}tjj	 
| j| j j¡}d }	|  ||||	|d|||¡	}
|
d S d S )NFT)Zflatten_recordsZ
drop_nonesrs   r   Zlist_to_regularr   z>cannot use axis=None on an array containing irreducible unionsr   rT   rU   rV   rW   rX   ú: exceeds the depth of the nested list structure (which is rY   )r.   Zprepare_reducerr   r<   rF   rI   ro   Z
EmptyArrayrJ   rK   rL   rM   rN   Z_reduce_nextrZ   )r   rq   r?   rr   rs   r   ÚpartsrP   rQ   ZshiftsÚnextrO   r\   r]   r%   r%   r&   ÚreduceÝ   sˆ    ú	ÿ÷
ÿÿÿ
ÿÿ÷rw   r   )r   Úpathr   c                 C  s
   |   |¡S rf   )Z_validity_error)r   rx   r%   r%   r&   Úvalidity_error7  s    ry   )r   r?   Ú	ascendingÚstabler   c           	   	   C  sÄ   | }| j \}}|rD|dkr$tdƒ‚||kr€td|› d|› d�ƒ‚n<|dkrT|| }d|  k rh|ks€n td|› d|› d�ƒ‚tjjjd	| jjd
�}tjjj| j| jjd
�}|  	||d |d	||¡S ©Nr   rT   rU   rV   rW   rX   rt   rY   r   rH   )
rZ   rF   rI   rJ   rK   rL   r.   rM   rN   Z_argsort_next©	r   r?   rz   r{   rO   r\   r]   rP   rQ   r%   r%   r&   Úargsort;  s@    
ÿÿÿÿÿùr~   c           	      C  sÂ   | }| j \}}|rD|dkr$tdƒ‚||kr€td|› d|› d�ƒ‚n<|dkrT|| }d|  k rh|ks€n td|› d|› d�ƒ‚tjjjd	| jjd
�}tjjj| j| jjd
�}|  	|||d	||¡S r|   )
rZ   rF   rI   rJ   rK   rL   r.   rM   rN   Z
_sort_nextr}   r%   r%   r&   Úsorte  s0    
ÿÿÿÿÿr   ©r   Ú	recursivec                 C  s   |   |¡ d S rf   )Z_touch_datar€   r%   r%   r&   Ú
touch_data„  s    r‚   c                 C  s   |   |¡ d S rf   )Z_touch_shaper€   r%   r%   r&   Útouch_shapeˆ  s    rƒ   )
NNNTTTTTNF)Nr'   r(   r   Nr)   )Fr   NN)N)N)F)r   )T)rS   TFN)r   )rS   TF)rS   TF)T)T)2Ú
__future__r   r!   Úcollections.abcr   r   Únumbersr   ZawkwardrI   Zawkward._backends.backendr   Zawkward._nplikes.numpy_liker   Zawkward._typingr   r	   r
   Zawkward.contents.contentr   r   Z!awkward.contents.remove_structurer   Zawkward.errorsr   Zawkward.formsr   Zawkward.recordr   ÚinstanceÚnpr"   r=   rA   rG   rR   r^   r`   rc   rg   ri   rj   rn   rp   rw   ry   r~   r   r‚   rƒ   r%   r%   r%   r&   Ú<module>   sz             ô&6      ù0    ú& ÿ    úZ   ü+ ÿ