def array_ufunc(ufunc, method, inputs, kwargs):
    if ((method != '__call__') or (len(inputs) == 0) or ('out' in kwargs)):
        return NotImplemented
    behavior = ak._util.behaviorof(*inputs)
    nextinputs = []
    for x in inputs:
        cast_fcn = ak._util.custom_cast(x, behavior)
        if (cast_fcn is not None):
            x = cast_fcn(x)
        nextinputs.append(ak.operations.convert.to_layout(x, allow_record=True, allow_other=True))
    inputs = nextinputs

    def adjust(custom, inputs, kwargs):
        args = [(ak._util.wrap(x, behavior) if isinstance(x, (ak.layout.Content, ak.layout.Record)) else x) for x in inputs]
        out = custom(*args, **kwargs)
        if (not isinstance(out, tuple)):
            out = (out,)
        return tuple(((x.layout if isinstance(x, (ak.highlevel.Array, ak.highlevel.Record)) else x) for x in out))

    def adjust_apply_ufunc(apply_ufunc, ufunc, method, inputs, kwargs):
        nextinputs = [(ak._util.wrap(x, behavior) if isinstance(x, (ak.layout.Content, ak.layout.Record)) else x) for x in inputs]
        out = apply_ufunc(ufunc, method, nextinputs, kwargs)
        if (out is NotImplemented):
            return None
        else:
            if (not isinstance(out, tuple)):
                out = (out,)
            out = tuple(((x.layout if isinstance(x, (ak.highlevel.Array, ak.highlevel.Record)) else x) for x in out))
            return (lambda : out)

    def is_fully_regular(layout):
        if (isinstance(layout, ak.layout.RegularArray) and (layout.parameter('__record__') is None) and (layout.parameter('__array__') is None)):
            if isinstance(layout.content, ak.layout.NumpyArray):
                return True
            elif isinstance(layout.content, ak.layout.RegularArray):
                return is_fully_regular(layout.content)
            else:
                return False
        else:
            return False

    def deregulate(layout):
        if (not is_fully_regular(layout)):
            return layout
        else:
            shape = [len(layout)]
            node = layout
            while isinstance(node, ak.layout.RegularArray):
                shape.append(node.size)
                node = node.content
            nparray = ak.nplike.of(node).asarray(node)
            nparray = nparray.reshape((tuple(shape) + nparray.shape[1:]))
            return ak.layout.NumpyArray(nparray, node.identities, node.parameters)

    def getfunction(inputs):
        signature = [ufunc]
        for x in inputs:
            if isinstance(x, ak.layout.Content):
                record = x.parameter('__record__')
                array = x.parameter('__array__')
                if (record is not None):
                    signature.append(record)
                elif (array is not None):
                    signature.append(array)
                elif isinstance(x, ak.layout.NumpyArray):
                    signature.append(ak.nplike.of(x).asarray(x).dtype.type)
                else:
                    signature.append(None)
            else:
                signature.append(type(x))
        custom = ak._util.overload(behavior, signature)
        if (custom is not None):
            return (lambda : adjust(custom, inputs, kwargs))
        if (ufunc is numpy.matmul):
            custom_matmul = getfunction_matmul(inputs)
            if (custom_matmul is not None):
                return custom_matmul
        inputs = [deregulate(x) for x in inputs]
        if all(((isinstance(x, ak.layout.NumpyArray) or (not isinstance(x, (ak.layout.Content, ak.partition.PartitionedArray)))) for x in inputs)):
            nplike = ak.nplike.of(*inputs)
            result = getattr(ufunc, method)(*[nplike.asarray(x) for x in inputs], **kwargs)
            return (lambda : (ak.operations.convert.from_numpy(result, highlevel=False),))
        for x in inputs:
            if isinstance(x, ak.layout.Content):
                chained_behavior = ak._util.Behavior(ak.behavior, behavior)
                apply_ufunc = chained_behavior[(numpy.ufunc, x.parameter('__array__'))]
                if (apply_ufunc is not None):
                    out = adjust_apply_ufunc(apply_ufunc, ufunc, method, inputs, kwargs)
                    if (out is not None):
                        return out
                apply_ufunc = chained_behavior[(numpy.ufunc, x.parameter('__record__'))]
                if (apply_ufunc is not None):
                    out = adjust_apply_ufunc(apply_ufunc, ufunc, method, inputs, kwargs)
                    if (out is not None):
                        return out
        if all((((x.parameter('__array__') is not None) or (x.parameter('__record__') is not None)) for x in inputs if isinstance(x, ak.layout.Content))):
            custom_types = []
            for x in inputs:
                if isinstance(x, ak.layout.Content):
                    if (x.parameter('__array__') is not None):
                        custom_types.append(x.parameter('__array__'))
                    elif (x.parameter('__record__') is not None):
                        custom_types.append(x.parameter('__record__'))
                    else:
                        custom_types.append(type(x).__name__)
                else:
                    custom_types.append(type(x).__name__)
            raise ValueError(('no overloads for custom types: {0}({1})'.format(ufunc.__name__, ', '.join(custom_types)) + ak._util.exception_suffix(__file__)))
        return None
    out = ak._util.broadcast_and_apply(inputs, getfunction, behavior, allow_records=False, pass_depth=False)
    assert (isinstance(out, tuple) and (len(out) == 1))
    return ak._util.wrap(out[0], behavior)
def array_ufunc(ufunc, method, inputs, kwargs):
    if ((method != '__call__') or (len(inputs) == 0) or ('out' in kwargs)):
        return NotImplemented
    behavior = ak._util.behaviorof(*inputs)
    nextinputs = []
    for x in inputs:
        cast_fcn = ak._util.custom_cast(x, behavior)
        if (cast_fcn is not None):
            x = cast_fcn(x)
        nextinputs.append(ak.operations.convert.to_layout(x, allow_record=True, allow_other=True))
    inputs = nextinputs

    def adjust(custom, inputs, kwargs):
        args = [(ak._util.wrap(x, behavior) if isinstance(x, (ak.layout.Content, ak.layout.Record)) else x) for x in inputs]
        out = custom(*args, **kwargs)
        if (not isinstance(out, tuple)):
            out = (out,)
        return tuple(((x.layout if isinstance(x, (ak.highlevel.Array, ak.highlevel.Record)) else x) for x in out))

    def adjust_apply_ufunc(apply_ufunc, ufunc, method, inputs, kwargs):
        nextinputs = [(ak._util.wrap(x, behavior) if isinstance(x, (ak.layout.Content, ak.layout.Record)) else x) for x in inputs]
        out = apply_ufunc(ufunc, method, nextinputs, kwargs)
        if (out is NotImplemented):
            return None
        else:
            if (not isinstance(out, tuple)):
                out = (out,)
            out = tuple(((x.layout if isinstance(x, (ak.highlevel.Array, ak.highlevel.Record)) else x) for x in out))
            return (lambda : out)

    def is_fully_regular(layout):
        if (isinstance(layout, ak.layout.RegularArray) and (layout.parameter('__record__') is None) and (layout.parameter('__array__') is None)):
            if isinstance(layout.content, ak.layout.NumpyArray):
                return True
            elif isinstance(layout.content, ak.layout.RegularArray):
                return is_fully_regular(layout.content)
            else:
                return False
        else:
            return False

    def deregulate(layout):
        if (not is_fully_regular(layout)):
            return layout
        else:
            shape = [len(layout)]
            node = layout
            while isinstance(node, ak.layout.RegularArray):
                shape.append(node.size)
                node = node.content
            nparray = ak.nplike.of(node).asarray(node)
            nparray = nparray.reshape((tuple(shape) + nparray.shape[1:]))
            return ak.layout.NumpyArray(nparray, node.identities, node.parameters)

    def getfunction(inputs):
        signature = [ufunc]
        for x in inputs:
            if isinstance(x, ak.layout.Content):
                record = x.parameter('__record__')
                array = x.parameter('__array__')
                if (record is not None):
                    signature.append(record)
                elif (array is not None):
                    signature.append(array)
                elif isinstance(x, ak.layout.NumpyArray):
                    signature.append(ak.nplike.of(x).asarray(x).dtype.type)
                else:
                    signature.append(None)
            else:
                signature.append(type(x))
        custom = ak._util.overload(behavior, signature)
        if (custom is not None):
            return (lambda : adjust(custom, inputs, kwargs))
        if (ufunc is numpy.matmul):
            custom_matmul = getfunction_matmul(inputs)
            if (custom_matmul is not None):
                return custom_matmul
        inputs = [deregulate(x) for x in inputs]
        if all(((isinstance(x, ak.layout.NumpyArray) or (not isinstance(x, (ak.layout.Content, ak.partition.PartitionedArray)))) for x in inputs)):
            nplike = ak.nplike.of(*inputs)
            result = getattr(ufunc, method)(*[nplike.asarray(x) for x in inputs], **kwargs)
            return (lambda : (ak.operations.convert.from_numpy(result, highlevel=False),))
        for x in inputs:
            if isinstance(x, ak.layout.Content):
                chained_behavior = ak._util.Behavior(ak.behavior, behavior)
                apply_ufunc = chained_behavior[(numpy.ufunc, x.parameter('__array__'))]
                if (apply_ufunc is not None):
                    out = adjust_apply_ufunc(apply_ufunc, ufunc, method, inputs, kwargs)
                    if (out is not None):
                        return out
                apply_ufunc = chained_behavior[(numpy.ufunc, x.parameter('__record__'))]
                if (apply_ufunc is not None):
                    out = adjust_apply_ufunc(apply_ufunc, ufunc, method, inputs, kwargs)
                    if (out is not None):
                        return out
        if all((((x.parameter('__array__') is not None) or (x.parameter('__record__') is not None)) for x in inputs if isinstance(x, ak.layout.Content))):
            custom_types = []
            for x in inputs:
                if isinstance(x, ak.layout.Content):
                    if (x.parameter('__array__') is not None):
                        custom_types.append(x.parameter('__array__'))
                    elif (x.parameter('__record__') is not None):
                        custom_types.append(x.parameter('__record__'))
                    else:
                        custom_types.append(type(x).__name__)
                else:
                    custom_types.append(type(x).__name__)
            raise ValueError(('no overloads for custom types: {0}({1})'.format(ufunc.__name__, ', '.join(custom_types)) + ak._util.exception_suffix(__file__)))
        return None
    out = ak._util.broadcast_and_apply(inputs, getfunction, behavior, allow_records=False, pass_depth=False)
    assert (isinstance(out, tuple) and (len(out) == 1))
    return ak._util.wrap(out[0], behavior)