a
    yn„fÄ  ã                   @  s`   d dl mZ d dlmZ d dlmZ d dlmZ dZe 	¡ Z
eƒ ddddœd	d
„ƒZdd„ ZdS )é    )Úannotations)Úhigh_level_function)ÚHighLevelContext)ÚNumpyMetadata)Ú	to_packedTN)Ú	highlevelÚbehaviorÚattrsc                c  s   | fV  t | |||ƒS )aœ
  
    Args:
        array: Array-like data (anything #ak.to_layout recognizes).
        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 an array with the same type and values as the input, but with packed inner structures:

    - #ak.contents.NumpyArray becomes C-contiguous (if it isn't already)
    - #ak.contents.RegularArray trims unreachable content
    - #ak.contents.ListArray becomes #ak.contents.ListOffsetArray, making all list data contiguous
    - #ak.contents.ListOffsetArray starts at `offsets[0] == 0`, trimming unreachable content
    - #ak.contents.RecordArray trims unreachable contents
    - #ak.contents.IndexedArray gets projected
    - #ak.contents.IndexedOptionArray remains an #ak.contents.IndexedOptionArray (with simplified `index`)
      if it contains records, becomes #ak.contents.ByteMaskedArray otherwise
    - #ak.contents.ByteMaskedArray becomes an #ak.contents.IndexedOptionArray if it contains records,
      stays a #ak.contents.ByteMaskedArray otherwise
    - #ak.contents.BitMaskedArray becomes an #ak.contents.IndexedOptionArray if it contains records,
      stays a #ak.contents.BitMaskedArray otherwise
    - #ak.contents.UnionArray gets projected contents
    - #ak.record.Record becomes a record over a single-item #ak.contents.RecordArray

    Example:

        >>> a = ak.Array([[1, 2, 3], [], [4, 5], [6], [7, 8, 9, 10]])
        >>> b = a[::-1]
        >>> b.layout
        <ListArray len='5'>
            <starts><Index dtype='int64' len='5'>
                [6 5 3 3 0]
            </Index></starts>
            <stops><Index dtype='int64' len='5'>
                [10  6  5  3  3]
            </Index></stops>
            <content><NumpyArray dtype='int64' len='10'>
                [ 1  2  3  4  5  6  7  8  9 10]
            </NumpyArray></content>
        </ListArray>

        >>> c = ak.to_packed(b)
        >>> c.layout
        <ListOffsetArray len='5'>
            <offsets><Index dtype='int64' len='6'>[ 0  4  5  7  7 10]</Index></offsets>
            <content><NumpyArray dtype='int64' len='10'>
                [ 7  8  9 10  6  4  5  1  2  3]
            </NumpyArray></content>
        </ListOffsetArray>

    Performing these operations will minimize the output size of data sent to
    #ak.to_buffers (though conversions through Arrow, #ak.to_arrow and
    #ak.to_parquet, do not need this because packing is part of that conversion).

    See also #ak.to_buffers.
    )Ú_impl)Úarrayr   r   r	   © r   úb/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/awkward/operations/ak_to_packed.pyr      s    >r   c                 C  sR   t ||d�� }|j| ddd�}W d   ƒ n1 s20    Y  | ¡ }|j||d�S )N)r   r	   TÚerror)Zallow_recordZprimitive_policy)r   )r   Úunwrapr   Úwrap)r   r   r   r	   ÚctxZlayoutÚoutr   r   r   r
   R   s    .r
   )Ú
__future__r   Zawkward._dispatchr   Zawkward._layoutr   Zawkward._nplikes.numpy_liker   Ú__all__ÚinstanceÚnpr   r
   r   r   r   r   Ú<module>   s   C