a
    yn„fÿ  ã                   @  sŠ   d dl mZ d dlZd dlmZ d dlmZmZ d dl	m
Z
 d dlmZmZ d dlmZ dZe
 ¡ Zeƒ dd
dddœdd„ƒZdd„ ZdS )é    )ÚannotationsN)Úhigh_level_function)ÚHighLevelContextÚmaybe_posaxis)ÚNumpyMetadata)Ú
is_integerÚregularize_axis)Ú	AxisError)Úfirstsé   T)Ú	highlevelÚbehaviorÚattrsc                c  s   | fV  t | ||||ƒS )a=  
    Args:
        array: Array-like data (anything #ak.to_layout recognizes).
        axis (int): The dimension at which this operation is applied. The
            outermost dimension is `0`, followed by `1`, etc., and negative
            values count backward from the innermost: `-1` is the innermost
            dimension, `-2` is the next level up, etc.
        highlevel (bool): If True, return an #ak.Array; otherwise, return
            a low-level #ak.contents.Content subclass.
        behavior (None or dict): Custom #ak.behavior for the output array, if
            high-level.
        attrs (None or dict): Custom attributes for the output array, if
            high-level.

    Selects the first element of each non-empty list and inserts None for each
    empty list.

    For example,

        >>> array = ak.Array([[1.1], [2.2], [], [3.3], [], [], [4.4], [5.5]])
        >>> ak.firsts(array).show()
        [1.1,
         2.2,
         None,
         3.3,
         None,
         None,
         4.4,
         5.5]

    See #ak.singletons to invert this function.
    )Ú_impl)ÚarrayÚaxisr   r   r   © r   ú_/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/awkward/operations/ak_firsts.pyr
      s    #r
   c                   sè   t ||d��}|j| dd�}W d   ƒ n1 s00    Y  tˆ ƒ‰ tˆ ƒsXtdˆ ›�ƒ‚t|ˆ dƒdkrºt | ¡}t t 	d dg¡|¡}|j
dkr¦||dg  d }	qØ||dg  d }	n‡ fdd„}
tjj||
d	d
�}	|j|	|d	d�S )N)r   r   F)Zallow_recordz'axis' must be an integer, not r   r   c           	        sˆ   t | ˆ |ƒ}||krh| jrh|jj| jjtjdd� }}| jj}||k}d||< t	j
j t	j |¡| j¡S | jr„tdˆ › d|› d�ƒ‚d S )NT)ZdtypeÚcopyéÿÿÿÿzaxis=z" exceeds the depth of this array (ú))r   Zis_listZindex_nplikeZasarrayÚstartsÚdataÚnpZint64ÚstopsÚakÚcontentsZIndexedOptionArrayZ
simplifiedÚindexZIndex64Ú_contentZis_leafr	   )	ÚlayoutÚdepthÚbackendÚkwargsZposaxisr   r   r   Zempties©r   r   r   ÚactionP   s    ÿ
ÿÿz_impl.<locals>.actionT)Znumpy_to_regular)r   Zallow_other)r   Úunwrapr   r   Ú	TypeErrorr   r   r!   Z
to_backendZ	from_iterÚlengthZ_doZrecursively_applyÚwrap)r   r   r   r   r   Úctxr   r!   ZslicerÚoutr$   r   r#   r   r   :   s    ,

r   )r   )Ú
__future__r   Zawkwardr   Zawkward._dispatchr   Zawkward._layoutr   r   Zawkward._nplikes.numpy_liker   Zawkward._regularizer   r   Zawkward.errorsr	   Ú__all__Úinstancer   r
   r   r   r   r   r   Ú<module>   s   (