a
    yn„f|  ã                   @  sŒ   d dl mZ d dlZd dlZd dlmZ d dlmZ d dl	m
Z
mZ d dlmZ dZe ¡ Ze ¡ Zedd	�d
dddœdd„ƒZdd„ ZdS )é    )ÚannotationsN)ÚTypeTracerBackend)Úhigh_level_function)ÚHighLevelContextÚensure_same_backend)ÚNumpyMetadata)Úrepeatzak.str)ÚmoduleT)Ú	highlevelÚbehaviorÚattrsc                c  s   | |fV  t | ||||ƒS )a‡  
    Args:
        array: Array-like data (anything #ak.to_layout recognizes).
        num_repeats: (int, or an array of them to broadcast): number of times
            to repeat each element
        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.

    Replaces any string-valued or bytestring-valued data with the same value
    repeated `num_repeats` times, which can be a scalar integer or a
    (broadcasted) array of integers.

    Note: this function does not raise an error if the `array` does not
    contain any string or bytestring data.

    Requires the pyarrow library and calls
    [pyarrow.compute.binary_repeat](https://arrow.apache.org/docs/python/generated/pyarrow.compute.binary_repeat.html)
    or
    [pyarrow.compute.binary_repeat](https://arrow.apache.org/docs/python/generated/pyarrow.compute.binary_repeat.html)
    on strings and bytestrings, respectively.
    )Ú_impl)ÚarrayÚnum_repeatsr
   r   r   © r   úf/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/awkward/operations/str/akstr_repeat.pyr      s    
r   c                   sâ   ddl m} ddlm‰  |dƒ‰t||d��4}t|j| dd�|jˆddd	�ƒ\}}W d   ƒ n1 sf0    Y  t|tj	j
ƒr¢‡ ‡fd
d„}	tj ||f|	¡\}
n2tˆtjƒs¶tdƒ‚‡ ‡‡fdd„}	tj ||	¡}
|j|
|d�S )Nr   )Úimport_pyarrow_compute)Ú_apply_through_arrowzak.str.repeat)r   r   F)Úallow_recordzpass-through)r   Zprimitive_policyc                   sZ   | d j rV| d  d¡dv rV| d jr:t | d jtj¡sBtdƒ‚ˆ ˆjg| ¢R Ž fS d S )Nr   Ú	__array__©ÚstringÚ
bytestringé   ú;num_repeats must be an integer or broadcastable to integers)	Úis_listÚ	parameterZis_numpyÚnpZ
issubdtypeZdtypeÚintegerÚ	TypeErrorÚbinary_repeat)ÚinputsÚkwargs)r   Úpcr   r   ÚactionD   s    ÿÿÿz_impl.<locals>.actionr   c                   s&   | j r"|  d¡dv r"ˆ ˆj| ˆƒS d S )Nr   r   )r   r   r    )Úlayoutr"   ©r   r   r#   r   r   r$   \   s    )r
   )Zawkward._connect.pyarrowr   Zawkward.operations.strr   r   r   ÚunwrapÚ
isinstanceÚakÚcontentsZContentZ_broadcastingZbroadcast_and_applyÚnumbersÚIntegralr   Z_doZrecursively_applyÚwrap)r   r   r
   r   r   r   Úctxr%   Znum_repeats_layoutr$   Úoutr   r&   r   r   5   s,    ÿþ&ÿÿr   )Ú
__future__r   r+   Zawkwardr)   Zawkward._backends.typetracerr   Zawkward._dispatchr   Zawkward._layoutr   r   Zawkward._nplikes.numpy_liker   Ú__all__ÚinstanceZ
typetracerr   r   r   r   r   r   r   Ú<module>   s   !