def multilabel_accuracy(
    outputs: torch.Tensor, targets: torch.Tensor, threshold: Union[float, torch.Tensor]
) -> torch.Tensor:
    """
    Computes multilabel accuracy for the specified activation and threshold.

    Args:
        outputs: NxK tensor that for each of the N examples
            indicates the probability of the example belonging to each of
            the K classes, according to the model.
        targets: binary NxK tensort that encodes which of the K
            classes are associated with the N-th input
            (eg: a row [0, 1, 0, 1] indicates that the example is
            associated with classes 2 and 4)
        threshold: threshold for for model output

    Returns:
        computed multilabel accuracy

    Examples:

    .. code-block:: python

        import torch
        from catalyst import metrics
        metrics.multilabel_accuracy(
            outputs=torch.tensor([
                [1, 0],
                [0, 1],
            ]),
            targets=torch.tensor([
                [1, 0],
                [0, 1],
            ]),
            threshold=0.5,
        )
        # tensor([1.])

    .. code-block:: python

        import torch
        from catalyst import metrics
        metrics.multilabel_accuracy(
            outputs=torch.tensor([
                [1.0, 0.0],
                [0.6, 1.0],
            ]),
            targets=torch.tensor([
                [1, 0],
                [0, 1],
            ]),
            threshold=0.5,
        )
        # tensor(0.7500)

    .. code-block:: python

        import torch
        from catalyst import metrics
        metrics.multilabel_accuracy(
            outputs=torch.tensor([
                [1.0, 0.0],
                [0.4, 1.0],
            ]),
            targets=torch.tensor([
                [1, 0],
                [0, 1],
            ]),
            threshold=0.5,
        )
        # tensor(1.0)
    """
    outputs, targets, _, _ = process_multilabel_components(
        outputs=outputs, targets=targets
    )

    outputs = (outputs > threshold).long()
    output = (targets.long() == outputs.long()).sum().float() / np.prod(targets.shape)
    return output

    Computes multilabel accuracy for the specified activation and threshold.

    Args:
        outputs: NxK tensor that for each of the N examples
            indicates the probability of the example belonging to each of
            the K classes, according to the model.
        targets: binary NxK tensort that encodes which of the K
            classes are associated with the N-th input
            (eg: a row [0, 1, 0, 1] indicates that the example is
            associated with classes 2 and 4)
        threshold: threshold for for model output

    Returns:
        computed multilabel accuracy

    Examples:

    .. code-block:: python

        import torch
        from catalyst import metrics
        metrics.multilabel_accuracy(
            outputs=torch.tensor([
                [1, 0],
                [0, 1],
            ]),
            targets=torch.tensor([
                [1, 0],
                [0, 1],
            ]),
            threshold=0.5,
        )
        # tensor([1.])

    .. code-block:: python

        import torch
        from catalyst import metrics
        metrics.multilabel_accuracy(
            outputs=torch.tensor([
                [1.0, 0.0],
                [0.6, 1.0],
            ]),
            targets=torch.tensor([
                [1, 0],
                [0, 1],
            ]),
            threshold=0.5,
        )
        # tensor(0.7500)

    .. code-block:: python

        import torch
        from catalyst import metrics
        metrics.multilabel_accuracy(
            outputs=torch.tensor([
                [1.0, 0.0],
                [0.4, 1.0],
            ]),
            targets=torch.tensor([
                [1, 0],
                [0, 1],
            ]),
            threshold=0.5,
        )
        # tensor(1.0)
    
catalyst/metrics/functional/_accuracy.py