def mean_average_precision(
    outputs: torch.Tensor, targets: torch.Tensor, topk: List[int]
) -> List[torch.Tensor]:
    """
    Calculate the mean average precision (MAP) for RecSys.
    The metrics calculate the mean of the AP across all batches

    MAP amplifies the interest in finding many
    relevant items for each query

    Args:
        outputs (torch.Tensor): Tensor with predicted score
            size: [batch_size, slate_length]
            model outputs, logits
        targets (torch.Tensor):
            Binary tensor with ground truth.
            1 means the item is relevant and 0 not relevant
            size: [batch_szie, slate_length]
            ground truth, labels
        topk (List[int]): List of parameter for evaluation topK items

    Returns:
        map_at_k (Tuple[float]):
        The map score for every k.
        size: len(top_k)

    Example:

    .. code-block:: python

        import torch
        from catalyst import metrics
        metrics.mean_average_precision(
            outputs=torch.tensor([
                [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],
                [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],
            ]),
            targets=torch.tensor([
                [1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0],
                [0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0],
            ]),
            topk=[1, 3, 5, 10],
        )
        # [tensor(0.5000), tensor(0.6667), tensor(0.6417), tensor(0.5325)]
    """
    results = []
    for k in topk:
        k = min(outputs.size(1), k)
        results.append(torch.mean(average_precision(outputs, targets, k)))

    return results

    Calculate the mean average precision (MAP) for RecSys.
    The metrics calculate the mean of the AP across all batches

    MAP amplifies the interest in finding many
    relevant items for each query

    Args:
        outputs (torch.Tensor): Tensor with predicted score
            size: [batch_size, slate_length]
            model outputs, logits
        targets (torch.Tensor):
            Binary tensor with ground truth.
            1 means the item is relevant and 0 not relevant
            size: [batch_szie, slate_length]
            ground truth, labels
        topk (List[int]): List of parameter for evaluation topK items

    Returns:
        map_at_k (Tuple[float]):
        The map score for every k.
        size: len(top_k)

    Example:

    .. code-block:: python

        import torch
        from catalyst import metrics
        metrics.mean_average_precision(
            outputs=torch.tensor([
                [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],
                [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],
            ]),
            targets=torch.tensor([
                [1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0],
                [0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0],
            ]),
            topk=[1, 3, 5, 10],
        )
        # [tensor(0.5000), tensor(0.6667), tensor(0.6417), tensor(0.5325)]
    
catalyst/metrics/functional/_average_precision.py