def METHOD_NAME(cls, ctx, op: "TensorTrapz"):
    inputs, device_id, xp = as_same_device(
        [ctx[c.key] for c in op.inputs], device=op.device, ret_extra=True
    )
    y = inputs[0]
    if len(inputs) > 1:
        x = inputs[-1]
    else:
        x = None
    with device(device_id):
        ctx[op.outputs[0].key] = xp.trapz(y, x=x, dx=op.dx, axis=op.axis)