prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Mean Absolute Percentage Error (MAPE)
  ## 🚀 Feature
  
  I'd like to implement the mean absolute percentage error [(MAPE)](https://en.wikipedia.org/wiki/Mean_absolute_percentage_error) in `ignite/metrics`.
  
  It is a commonly used metric for regression problems and it would be really convenient to be able to use it directly with ignite evaluators.
  
  For that, I would write a custom Metric class in a new file `mean_absolute_percentage_error.py` inheriting from the base `Metric` class in `ignite/metrics/metric.py`.
  
  
  </issue>
  <code>
  [start of ignite/contrib/metrics/regression/mean_absolute_relative_error.py]
  1 from typing import Tuple
  2 
  3 import torch
  4 
  5 from ignite.contrib.metrics.regression._base import _BaseRegression
  6 from ignite.exceptions import NotComputableError
  7 from ignite.metrics.metric import reinit__is_reduced, sync_all_reduce
  8 
  9 
  10 class MeanAbsoluteRelativeError(_BaseRegression):
  11     r"""Calculate Mean Absolute Relative Error.
  12 
  13     .. math::
  14         \text{MARE} = \frac{1}{n}\sum_{j=1}^n\frac{\left|A_j-P_j\right|}{\left|A_j\right|}
  15 
  16     where :math:`A_j` is the ground truth and :math:`P_j` is the predicted value.
  17 
  18     More details can be found in the reference `Botchkarev 2018`__.
  19 
  20     - ``update`` must receive output of the form ``(y_pred, y)`` or ``{'y_pred': y_pred, 'y': y}``.
  21     - `y` and `y_pred` must be of same shape `(N, )` or `(N, 1)`.
  22 
  23     __ https://arxiv.org/ftp/arxiv/papers/1809/1809.03006.pdf
  24 
  25     Parameters are inherited from ``Metric.__init__``.
  26 
  27     Args:
  28         output_transform: a callable that is used to transform the
  29             :class:`~ignite.engine.engine.Engine`'s ``process_function``'s output into the
  30             form expected by the metric. This can be useful if, for example, you have a multi-output model and
  31             you want to compute the metric with respect to one of the outputs.
  32             By default, metrics require the output as ``(y_pred, y)`` or ``{'y_pred': y_pred, 'y': y}``.
  33         device: specifies which device updates are accumulated on. Setting the
  34             metric's device to be the same as your ``update`` arguments ensures the ``update`` method is
  35             non-blocking. By default, CPU.
  36 
  37     Examples:
  38         To use with ``Engine`` and ``process_function``, simply attach the metric instance to the engine.
  39         The output of the engine's ``process_function`` needs to be in format of
  40         ``(y_pred, y)`` or ``{'y_pred': y_pred, 'y': y, ...}``.
  41 
  42         .. include:: defaults.rst
  43             :start-after: :orphan:
  44 
  45         .. testcode::
  46 
  47             metric = MeanAbsoluteRelativeError()
  48             metric.attach(default_evaluator, 'mare')
  49             y_true = torch.tensor([1., 2., 3., 4., 5.])
  50             y_pred = y_true * 0.75
  51             state = default_evaluator.run([[y_pred, y_true]])
  52             print(state.metrics['mare'])
  53 
  54         .. testoutput::
  55 
  56             0.25...
  57 
  58     .. versionchanged:: 0.4.5
  59         - Works with DDP.
  60     """
  61     _state_dict_all_req_keys = ("_sum_of_absolute_relative_errors", "_num_samples")
  62 
  63     @reinit__is_reduced
  64     def reset(self) -> None:
  65         self._sum_of_absolute_relative_errors = torch.tensor(0.0, device=self._device)
  66         self._num_samples = 0
  67 
  68     def _update(self, output: Tuple[torch.Tensor, torch.Tensor]) -> None:
  69         y_pred, y = output[0].detach(), output[1].detach()
  70         if (y == 0).any():
  71             raise NotComputableError("The ground truth has 0.")
  72         absolute_error = torch.abs(y_pred - y.view_as(y_pred)) / torch.abs(y.view_as(y_pred))
  73         self._sum_of_absolute_relative_errors += torch.sum(absolute_error).to(self._device)
  74         self._num_samples += y.size()[0]
  75 
  76     @sync_all_reduce("_sum_of_absolute_relative_errors", "_num_samples")
  77     def compute(self) -> float:
  78         if self._num_samples == 0:
  79             raise NotComputableError(
  80                 "MeanAbsoluteRelativeError must have at least one sample before it can be computed."
  81             )
  82         return self._sum_of_absolute_relative_errors.item() / self._num_samples
  83
  [end of ignite/contrib/metrics/regression/mean_absolute_relative_error.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/ignite/contrib/metrics/regression/mean_absolute_relative_error.py b/ignite/contrib/metrics/regression/mean_absolute_relative_error.py
  --- a/ignite/contrib/metrics/regression/mean_absolute_relative_error.py
  +++ b/ignite/contrib/metrics/regression/mean_absolute_relative_error.py
  @@ -8,7 +8,7 @@
   
   
   class MeanAbsoluteRelativeError(_BaseRegression):
  -    r"""Calculate Mean Absolute Relative Error.
  +    r"""Calculate Mean Absolute Relative Error (MARE), also known as Mean Absolute Percentage Error (MAPE).
   
       .. math::
           \text{MARE} = \frac{1}{n}\sum_{j=1}^n\frac{\left|A_j-P_j\right|}{\left|A_j\right|}
  
verification_info: {"golden_diff": "diff --git a/ignite/contrib/metrics/regression/mean_absolute_relative_error.py b/ignite/contrib/metrics/regression/mean_absolute_relative_error.py\n--- a/ignite/contrib/metrics/regression/mean_absolute_relative_error.py\n+++ b/ignite/contrib/metrics/regression/mean_absolute_relative_error.py\n@@ -8,7 +8,7 @@\n \n \n class MeanAbsoluteRelativeError(_BaseRegression):\n-    r\"\"\"Calculate Mean Absolute Relative Error.\n+    r\"\"\"Calculate Mean Absolute Relative Error (MARE), also known as Mean Absolute Percentage Error (MAPE).\n \n     .. math::\n         \\text{MARE} = \\frac{1}{n}\\sum_{j=1}^n\\frac{\\left|A_j-P_j\\right|}{\\left|A_j\\right|}\n", "issue": "Mean Absolute Percentage Error (MAPE)\n## \ud83d\ude80 Feature\r\n\r\nI'd like to implement the mean absolute percentage error [(MAPE)](https://en.wikipedia.org/wiki/Mean_absolute_percentage_error) in `ignite/metrics`.\r\n\r\nIt is a commonly used metric for regression problems and it would be really convenient to be able to use it directly with ignite evaluators.\r\n\r\nFor that, I would write a custom Metric class in a new file `mean_absolute_percentage_error.py` inheriting from the base `Metric` class in `ignite/metrics/metric.py`.\r\n\n", "before_files": [{"content": "from typing import Tuple\n\nimport torch\n\nfrom ignite.contrib.metrics.regression._base import _BaseRegression\nfrom ignite.exceptions import NotComputableError\nfrom ignite.metrics.metric import reinit__is_reduced, sync_all_reduce\n\n\nclass MeanAbsoluteRelativeError(_BaseRegression):\n    r\"\"\"Calculate Mean Absolute Relative Error.\n\n    .. math::\n        \\text{MARE} = \\frac{1}{n}\\sum_{j=1}^n\\frac{\\left|A_j-P_j\\right|}{\\left|A_j\\right|}\n\n    where :math:`A_j` is the ground truth and :math:`P_j` is the predicted value.\n\n    More details can be found in the reference `Botchkarev 2018`__.\n\n    - ``update`` must receive output of the form ``(y_pred, y)`` or ``{'y_pred': y_pred, 'y': y}``.\n    - `y` and `y_pred` must be of same shape `(N, )` or `(N, 1)`.\n\n    __ https://arxiv.org/ftp/arxiv/papers/1809/1809.03006.pdf\n\n    Parameters are inherited from ``Metric.__init__``.\n\n    Args:\n        output_transform: a callable that is used to transform the\n            :class:`~ignite.engine.engine.Engine`'s ``process_function``'s output into the\n            form expected by the metric. This can be useful if, for example, you have a multi-output model and\n            you want to compute the metric with respect to one of the outputs.\n            By default, metrics require the output as ``(y_pred, y)`` or ``{'y_pred': y_pred, 'y': y}``.\n        device: specifies which device updates are accumulated on. Setting the\n            metric's device to be the same as your ``update`` arguments ensures the ``update`` method is\n            non-blocking. By default, CPU.\n\n    Examples:\n        To use with ``Engine`` and ``process_function``, simply attach the metric instance to the engine.\n        The output of the engine's ``process_function`` needs to be in format of\n        ``(y_pred, y)`` or ``{'y_pred': y_pred, 'y': y, ...}``.\n\n        .. include:: defaults.rst\n            :start-after: :orphan:\n\n        .. testcode::\n\n            metric = MeanAbsoluteRelativeError()\n            metric.attach(default_evaluator, 'mare')\n            y_true = torch.tensor([1., 2., 3., 4., 5.])\n            y_pred = y_true * 0.75\n            state = default_evaluator.run([[y_pred, y_true]])\n            print(state.metrics['mare'])\n\n        .. testoutput::\n\n            0.25...\n\n    .. versionchanged:: 0.4.5\n        - Works with DDP.\n    \"\"\"\n    _state_dict_all_req_keys = (\"_sum_of_absolute_relative_errors\", \"_num_samples\")\n\n    @reinit__is_reduced\n    def reset(self) -> None:\n        self._sum_of_absolute_relative_errors = torch.tensor(0.0, device=self._device)\n        self._num_samples = 0\n\n    def _update(self, output: Tuple[torch.Tensor, torch.Tensor]) -> None:\n        y_pred, y = output[0].detach(), output[1].detach()\n        if (y == 0).any():\n            raise NotComputableError(\"The ground truth has 0.\")\n        absolute_error = torch.abs(y_pred - y.view_as(y_pred)) / torch.abs(y.view_as(y_pred))\n        self._sum_of_absolute_relative_errors += torch.sum(absolute_error).to(self._device)\n        self._num_samples += y.size()[0]\n\n    @sync_all_reduce(\"_sum_of_absolute_relative_errors\", \"_num_samples\")\n    def compute(self) -> float:\n        if self._num_samples == 0:\n            raise NotComputableError(\n                \"MeanAbsoluteRelativeError must have at least one sample before it can be computed.\"\n            )\n        return self._sum_of_absolute_relative_errors.item() / self._num_samples\n", "path": "ignite/contrib/metrics/regression/mean_absolute_relative_error.py"}]}