a
    yn„f!  ã                   @  sZ   d Z ddlmZ ddlZdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
G dd„ dƒZdS )a  
Copyright (c) 2005-2023, NumPy Developers.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

    * Redistributions of source code must retain the above copyright
       notice, this list of conditions and the following disclaimer.

    * Redistributions in binary form must reproduce the above
       copyright notice, this list of conditions and the following
       disclaimer in the documentation and/or other materials provided
       with the distribution.

    * Neither the name of the NumPy Developers nor the names of any
       contributors may be used to endorse or promote products derived
       from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
é    )ÚannotationsNc                 C  s&   z| j du W S  ty    Y dS 0 dS )z)True when __array_ufunc__ is set to None.NF)Z__array_ufunc__ÚAttributeError)Úobj© r   úU/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/awkward/_operators.pyÚ_disables_array_ufunc'   s    r   c                   s   ‡ fdd„}d|› d�|_ |S )z>Implement a forward binary method with a ufunc, e.g., __add__.c                   s   t |ƒrtS ˆ | |ƒS ©N©r   ÚNotImplemented©ÚselfÚother©Úufuncr   r   Úfunc2   s    z_binary_method.<locals>.funcÚ__©Ú__name__©r   Únamer   r   r   r   Ú_binary_method/   s    r   c                   s   ‡ fdd„}d|› d�|_ |S )zAImplement a reflected binary method with a ufunc, e.g., __radd__.c                   s   t |ƒrtS ˆ || ƒS r   r	   r   r   r   r   r   >   s    z&_reflected_binary_method.<locals>.funcÚ__rr   r   r   r   r   r   Ú_reflected_binary_method;   s    r   c                   s   ‡ fdd„}d|› d�|_ |S )zAImplement an in-place binary method with a ufunc, e.g., __iadd__.c                   s   ˆ | || fd�S )N)Úoutr   r   r   r   r   r   J   s    z$_inplace_binary_method.<locals>.funcZ__ir   r   r   r   r   r   Ú_inplace_binary_methodG   s    r   c                 C  s   t | |ƒt| |ƒt| |ƒfS )zEImplement forward, reflected and inplace binary methods with a ufunc.)r   r   r   )r   r   r   r   r   Ú_numeric_methodsQ   s    ýr   c                   s   ‡ fdd„}d|› d�|_ |S )z.Implement a unary special method with a ufunc.c                   s   ˆ | ƒS r   r   )r   r   r   r   r   ]   s    z_unary_method.<locals>.funcr   r   r   r   r   r   Ú_unary_methodZ   s    r   c                   @  sŠ  e Zd ZdZeejdƒZeejdƒZ	eej
dƒZeejdƒZeejdƒZeejdƒZeejdƒ\ZZZeejd	ƒ\ZZZeejd
ƒ\ZZZeejdƒ\Z Z!Z"eej#dƒ\Z$Z%Z&eej'dƒ\Z(Z)Z*eej+dƒ\Z,Z-Z.eej/dƒZ0e1ej/dƒZ2eej3dƒ\Z4Z5Z6eej7dƒ\Z8Z9Z:eej;dƒ\Z<Z=Z>eej?dƒ\Z@ZAZBeejCdƒ\ZDZEZFeejGdƒ\ZHZIZJeKejLdƒZMeKejNdƒZOeKejPdƒZQeKejRdƒZSdS )ÚNDArrayOperatorsMixina  Mixin defining all operator special methods using __array_ufunc__.

    This class implements the special methods for almost all of Python's
    builtin operators defined in the `operator` module, including comparisons
    (``==``, ``>``, etc.) and arithmetic (``+``, ``*``, ``-``, etc.), by
    deferring to the ``__array_ufunc__`` method, which subclasses must
    implement.

    It is useful for writing classes that do not inherit from `numpy.ndarray`,
    but that should support arithmetic and numpy universal functions like
    arrays as described in `A Mechanism for Overriding Ufuncs
    <https://numpy.org/neps/nep-0013-ufunc-overrides.html>`_.

    As an trivial example, consider this implementation of an ``ArrayLike``
    class that simply wraps a NumPy array and ensures that the result of any
    arithmetic operation is also an ``ArrayLike`` object::

        class ArrayLike(np.lib.mixins.NDArrayOperatorsMixin):
            def __init__(self, value):
                self.value = np.asarray(value)

            # One might also consider adding the built-in list type to this
            # list, to support operations like np.add(array_like, list)
            _HANDLED_TYPES = (np.ndarray, numbers.Number)

            def __array_ufunc__(self, ufunc, method, *inputs, **kwargs):
                out = kwargs.get('out', ())
                for x in inputs + out:
                    # Only support operations with instances of _HANDLED_TYPES.
                    # Use ArrayLike instead of type(self) for isinstance to
                    # allow subclasses that don't override __array_ufunc__ to
                    # handle ArrayLike objects.
                    if not isinstance(x, self._HANDLED_TYPES + (ArrayLike,)):
                        return NotImplemented

                # Defer to the implementation of the ufunc on unwrapped values.
                inputs = tuple(x.value if isinstance(x, ArrayLike) else x
                               for x in inputs)
                if out:
                    kwargs['out'] = tuple(
                        x.value if isinstance(x, ArrayLike) else x
                        for x in out)
                result = getattr(ufunc, method)(*inputs, **kwargs)

                if type(result) is tuple:
                    # multiple return values
                    return tuple(type(self)(x) for x in result)
                elif method == 'at':
                    # no return value
                    return None
                else:
                    # one return value
                    return type(self)(result)

            def __repr__(self):
                return '%s(%r)' % (type(self).__name__, self.value)

    In interactions between ``ArrayLike`` objects and numbers or numpy arrays,
    the result is always another ``ArrayLike``:

        >>> x = ArrayLike([1, 2, 3])
        >>> x - 1
        ArrayLike(array([0, 1, 2]))
        >>> 1 - x
        ArrayLike(array([ 0, -1, -2]))
        >>> np.arange(3) - x
        ArrayLike(array([-1, -1, -1]))
        >>> x - np.arange(3)
        ArrayLike(array([1, 1, 1]))

    Note that unlike ``numpy.ndarray``, ``ArrayLike`` does not allow operations
    with arbitrary, unrecognized types. This ensures that interactions with
    ArrayLike preserve a well-defined casting hierarchy.

    .. versionadded:: 1.13
    ÚltÚleÚeqÚneÚgtÚgeÚaddÚsubÚmulÚmatmulÚtruedivÚfloordivÚmodÚdivmodÚpowÚlshiftÚrshiftÚandÚxorÚorÚnegÚposÚabsÚinvertN)Tr   Ú
__module__Ú__qualname__Ú__doc__r   ÚnpÚlessÚ__lt__Z
less_equalÚ__le__ÚequalÚ__eq__Ú	not_equalÚ__ne__ZgreaterÚ__gt__Zgreater_equalÚ__ge__r   r$   Ú__add__Ú__radd__Ú__iadd__ÚsubtractÚ__sub__Ú__rsub__Ú__isub__ÚmultiplyÚ__mul__Ú__rmul__Ú__imul__r'   Ú
__matmul__Ú__rmatmul__Ú__imatmul__Ztrue_divideÚ__truediv__Ú__rtruediv__Ú__itruediv__Zfloor_divideÚ__floordiv__Ú__rfloordiv__Ú__ifloordiv__Ú	remainderÚ__mod__Ú__rmod__Ú__imod__r+   Ú
__divmod__r   Ú__rdivmod__ÚpowerÚ__pow__Ú__rpow__Ú__ipow__Z
left_shiftÚ
__lshift__Ú__rlshift__Ú__ilshift__Zright_shiftÚ
__rshift__Ú__rrshift__Ú__irshift__Zbitwise_andÚ__and__Ú__rand__Ú__iand__Zbitwise_xorÚ__xor__Ú__rxor__Ú__ixor__Z
bitwise_orÚ__or__Ú__ror__Ú__ior__r   ÚnegativeÚ__neg__ZpositiveÚ__pos__ÚabsoluteÚ__abs__r5   Ú
__invert__r   r   r   r   r   d   s<   Qÿ
ÿ
r   )r8   Ú
__future__r   Únumpyr9   r   r   r   r   r   r   r   r   r   r   r   Ú<module>   s   !
	
