a
    yn„fq  ã                   @  sŽ   d dl mZ d dlZd dlmZ d dlmZmZ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d„ƒZdd„ ZdS )é    )ÚannotationsN)Úhigh_level_function)ÚHighLevelContextÚmaybe_highlevel_to_lowlevelÚmaybe_posaxis)Úufuncs)ÚNumpyMetadata)Úregularize_axis)ÚsoftmaxFT)ÚkeepdimsÚmask_identityÚ	highlevelÚbehaviorÚattrsc                c  s   | fV  t | ||||||ƒS )a-  
    Args:
        x: The data on which to compute the softmax (anything #ak.to_layout recognizes).
        axis (None or int): If None, combine all values from the array into
            a single scalar result; if an int, group by that axis. Only `axis`
            arguments equivalent to `-1` (softmax reduction along the innermost
            dimension) is supported.
        keepdims (bool): If False, this function decreases the number of
            dimensions by 1; if True, the output values are wrapped in a new
            length-1 dimension so that the result of this operation may be
            broadcasted with the original array.
        mask_identity (bool): If True, the application of this function on
            empty lists results in None (an option type); otherwise, the
            calculation is followed through with the reducers' identities,
            usually resulting in floating-point `nan`.
        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.

    Computes the softmax in each group of elements from `x` (many
    types supported, including all Awkward Arrays and Records). The grouping
    is performed the same way as for reducers, though this operation is not a
    reducer and has no identity.

    This function has no NumPy equivalent.

    Passing all arguments to the reducers, the softmax is calculated as

        np.exp(x) / ak.sum(np.exp(x))

    See #ak.sum for a complete description of handling nested lists and
    missing values (None) in reducers, and #ak.mean for an example with another
    non-reducer.
    )Ú_impl)ÚxÚaxisr   r   r   r   r   © r   ú`/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/awkward/operations/ak_softmax.pyr
      s    1r
   c              
   C  sî   |}t |ƒ}t||d�� }|j| ddd�}	W d   ƒ n1 s>0    Y  | |	¡} t|	|dƒt|	ddƒkrztd|› d�ƒ‚tjd	d	d
��R t 	| ¡}
t
jjj|
|||d|j|jd�}|jt|
| ƒ|dd�W  d   ƒ S 1 sà0    Y  d S )N)r   r   FÚerror)Zallow_recordZprimitive_policyé   éÿÿÿÿz1ak.softmax is only defined for axis=-1, but axis=zO; see https://github.com/scikit-hep/awkward/issues/2760#issuecomment-2034749982Úignore)ÚinvalidÚdivideT)r   r   r   )r   Zallow_other)r	   r   ÚunwrapÚwrapr   ÚNotImplementedErrorÚnpZerrstater   ÚexpÚakÚ
operationsZak_sumr   r   r   r   )r   r   r   r   r   r   r   Zoriginal_axisÚctxZx_layoutZexpxÚdenomr   r   r   r   L   s2    .

ÿ
ù	
ýr   )N)Ú
__future__r   Zawkwardr    Zawkward._dispatchr   Zawkward._layoutr   r   r   Zawkward._nplikesr   Zawkward._nplikes.numpy_liker   Zawkward._regularizer	   Ú__all__Úinstancer   r
   r   r   r   r   r   Ú<module>   s$    þø6