a
    yn„f$  ã                   @  sÀ   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
 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œdd„ƒZdd„ Zejj d¡deeefdd„ƒZdS )é    )ÚannotationsN)ÚUNSUPPORTED)Úhigh_level_function)ÚHighLevelContextÚensure_same_backend)ÚNumpyMetadata)Úis_unknown_scalar)Úis_integer_like)Ú_ZEROS©Ú	full_likeFT)ÚdtypeÚincluding_unknownÚ	highlevelÚbehaviorÚattrsc                c  s   | |fV  t | ||||||ƒS )aj
  
    Args:
        array: Array-like data (anything #ak.to_layout recognizes).
        fill_value: Value to fill the new array with.
        dtype (None or NumPy dtype): Overrides the data type of the result.
        including_unknown (bool): If True, the `unknown` type is considered
            a value type and is converted to a zero-length array of the
            specified dtype; if False, `unknown` will remain `unknown`.
        highlevel (bool, default is True): 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.

    This is the equivalent of NumPy's `np.full_like` for Awkward Arrays.

    Although it's possible to produce an array of `fill_value` with the
    structure of an `array` using #ak.broadcast_arrays:

        >>> array = ak.Array([[1, 2, 3], [], [4, 5]])
        >>> ak.broadcast_arrays(array, 1)
        [<Array [[1, 2, 3], [], [4, 5]] type='3 * var * int64'>,
         <Array [[1, 1, 1], [], [1, 1]] type='3 * var * int64'>]
        >>> ak.broadcast_arrays(array, 1.0)
        [<Array [[1, 2, 3], [], [4, 5]] type='3 * var * int64'>,
         <Array [[1, 1, 1], [], [1, 1]] type='3 * var * float64'>]

    Such a technique takes its type from the scalar (`1` or `1.0`), rather than
    the array. This function gets all types from the array, which might not be
    the same in all parts of the structure.

    Here is an extreme example:

        >>> array = ak.Array([
        ... [{"x": 0.0, "y": []},
        ...  {"x": 1.1, "y": [1]},
        ...  {"x": 2.2, "y": [1, 2]}],
        ... [],
        ... [{"x": 3.3, "y": [1, 2, None, 3]},
        ...  False,
        ...  False,
        ...  True,
        ...  {"x": 4.4, "y": [1, 2, None, 3, 4]}]])
        >>> ak.full_like(array, 12.3).show()
        [[{x: 12.3, y: []}, {x: 12.3, y: [12]}, {x: 12.3, y: [12, 12]}],
         [],
         [{x: 12.3, y: [12, 12, None, 12]}, True, ..., True, {x: 12.3, y: [12, ...]}]]

    The `"x"` values get filled in with `12.3` because they retain their type
    (`float64`) and the `"y"` list items get filled in with `12` because they
    retain their type (`int64`). Booleans get filled with True because `12.3`
    is not zero. Missing values remain in the same positions as in the original
    `array`. (To fill them in, use #ak.fill_none.)

    See also #ak.zeros_like and #ak.ones_like.

    (There is no equivalent of NumPy's `np.empty_like` because Awkward Arrays
    are immutable.)
    )Ú_impl)ÚarrayÚ
fill_valuer   r   r   r   r   © r   úb/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/awkward/operations/ak_full_like.pyr      s    H
ÿr   c              	     sÆ   t ˆ |d��6}t|j| dd�|jˆdddd�ƒ\}}	W d   ƒ n1 sH0    Y  ˆd ur˜t ˆ¡‰|jjjˆgˆd�d ‰ˆt tj¡kr˜ˆ 	tj
¡‰‡ ‡‡‡fd	d
„}
tj ||
¡}|j||d�S )N)r   r   Úerror)Úprimitive_policyzpass-throughT)r   Zstring_policyZallow_unknown©r   r   c              	     sŒ  |j }|j}| jr°| | j¡}ˆtu s>tˆƒrZtˆƒsZˆdkrZtj	j
|j|ˆd�| jd�S tˆƒrŽtˆƒsŽˆdkrŽtj	j
|j|ˆd�| jd�S tj	j
|j|ˆˆd�| jd�S �nØ| jrÖˆd urÎˆrÎ| jˆd�S d S �n²|  d¡dv �r„|  d¡}|dk� rþdnd	}ˆtu �rz|jd
tjd�}tj	jtjj|j| jtjd�|d�tjj|j| jtjd�|d�tj	j
|d|id�d|id�}	nÔ|j| dg¡tjd�d }
ˆt tj¡k�r¾|
�r¾ˆ�r¸dnd}n"tˆtƒ�rÐˆ}nt ˆƒ !dd¡}|j|tjd�}tj	jtjj|j| jtjd�|d�tj |j"| jt#|ƒtjd�¡tj	j
|d|id�d|id�}	ˆd u�r€tj$j%|	ˆdˆ d�}	tj$j&|	ˆdˆ d�}	|	S d S d S )Nr   r   )Ú
parametersé   Z	__array__>   ÚstringÚ
bytestringr   ÚbyteÚcharó    )ÚnplikeÚ0ó   ó    zutf-8ÚsurrogateescapeF)r   r   )'r!   Úindex_nplikeZis_numpyÚasarrayÚdatar
   r	   r   ÚakÚcontentsZ
NumpyArrayZ
zeros_liker   Z	ones_liker   Z
is_unknownZto_NumpyArrayZ	parameterZ
frombufferÚnpÚuint8Z	ListArrayÚindexZIndex64ZzerosÚlengthZint64ZastypeÚbool_r   Ú
isinstanceÚbytesÚstrÚencodeÚfullÚlenÚ
operationsZstrings_astypeZvalues_astype)ÚlayoutÚbackendÚkwargsr!   r&   ÚoriginalZstringlike_typeZcharlike_typeZasbytesÚresultZnumpy2_behavior©r   r   r   r   r   r   Úactionz   s¨    ÿþýþÿþýþþ


þþþóÿþÿÿõ
ÿÿz_impl.<locals>.action)r   )r   r   Úunwrapr+   r   r8   r!   r'   r/   Úviewr,   r)   Z_doZrecursively_applyÚwrap)r   r   r   r   r   r   r   Úctxr7   Ú_r=   Úoutr   r<   r   r   c   s$    üþ&

gr   c                 C  s   t | ||d�S )N)r   r   r   )Úar   r   ÚorderZsubokÚshaper   r   r   Ú_nep_18_implå   s    rG   )Ú
__future__r   Zawkwardr)   Zawkward._connect.numpyr   Zawkward._dispatchr   Zawkward._layoutr   r   Zawkward._nplikes.numpy_liker   Zawkward._nplikes.typetracerr   Zawkward._regularizer	   Z awkward.operations.ak_zeros_liker
   Ú__all__Úinstancer+   r   r   Ú_connectÚnumpyZ
implementsrG   r   r   r   r   Ú<module>   s,   øO ÿ