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)Ú
singletonsT)Ú	highlevelÚbehaviorÚattrsc                c  s   | fV  t | ||||ƒS )ag  
    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.

    Returns a singleton list (length 1) wrapping each non-missing value and
    an empty list (length 0) in place of each missing value.

    For example,

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

    See #ak.firsts to invert this function.
    )Ú_impl)ÚarrayÚaxisr   r   r   © r   úc/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/awkward/operations/ak_singletons.pyr
      s    #r
   c           	        s†   t ˆ ƒ‰ t||d�� }|j| ddd�}W d   ƒ n1 s:0    Y  tˆ ƒsZtdˆ ›�ƒ‚‡ fdd„}tjj||dd	�}|j||d
�S )N)r   r   FÚerror)Zallow_recordZprimitive_policyz'axis' must be an integer, not c                   sÆ   t | ˆ |ƒ}|d ur¦|d |kr¦| js,| jr0d S | jr�|jj| jd tjd�}d|d< |jj	| j
dd�|dd … d� tj tj |¡|  ¡ ¡S tj | d¡ d¡S n| jrÂtdˆ › d|› d	�ƒ‚d S )
Né   )Zdtyper   T)Z
valid_when)Z	maybe_outzaxis=z" exceeds the depth of this array (ú))r   Zis_unionZ	is_recordZ	is_optionZindex_nplikeÚemptyÚlengthÚnpZint64ZcumsumZmask_as_boolÚakÚcontentsZListOffsetArrayÚindexZIndex64ÚprojectZRegularArrayZto_ListOffsetArray64Zis_leafr	   )ÚlayoutÚdepthÚbackendÚkwargsZposaxisÚoffsets©r   r   r   ÚactionB   s     ÿÿz_impl.<locals>.actionT)Znumpy_to_regular)r   )	r   r   Úunwrapr   Ú	TypeErrorr   Z_doZrecursively_applyÚwrap)	r   r   r   r   r   Úctxr   r#   Úoutr   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   (