prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Issue with metric arithmetics
  I'm trying to define my metric as 
  ```python
  from ignite.metrics import Accuracy
  
  accuracy = Accuracy()
  error_metric = 1.0 - accuracy
  ```
  and I got the following error:
  ```
  ---------------------------------------------------------------------------
  TypeError                                 Traceback (most recent call last)
  <ipython-input-70-c4c69e70a6d5> in <module>()
        2 
        3 accuracy = Accuracy()
  ----> 4 error_metric = 1.0 - accuracy
  
  TypeError: unsupported operand type(s) for -: 'float' and 'Accuracy'
  ```
  But I can define 
  ```python
  from ignite.metrics import Accuracy
  
  accuracy = Accuracy()
  error_metric = (accuracy - 1.0) * -1.0
  ```
  
  cc @zasdfgbnm 
  Issue with metric arithmetics
  I'm trying to define my metric as 
  ```python
  from ignite.metrics import Accuracy
  
  accuracy = Accuracy()
  error_metric = 1.0 - accuracy
  ```
  and I got the following error:
  ```
  ---------------------------------------------------------------------------
  TypeError                                 Traceback (most recent call last)
  <ipython-input-70-c4c69e70a6d5> in <module>()
        2 
        3 accuracy = Accuracy()
  ----> 4 error_metric = 1.0 - accuracy
  
  TypeError: unsupported operand type(s) for -: 'float' and 'Accuracy'
  ```
  But I can define 
  ```python
  from ignite.metrics import Accuracy
  
  accuracy = Accuracy()
  error_metric = (accuracy - 1.0) * -1.0
  ```
  
  cc @zasdfgbnm 
  
  </issue>
  <code>
  [start of ignite/metrics/metric.py]
  1 from abc import ABCMeta, abstractmethod
  2 from ignite._six import with_metaclass
  3 from ignite.engine import Events
  4 import torch
  5 
  6 
  7 class Metric(with_metaclass(ABCMeta, object)):
  8     """
  9     Base class for all Metrics.
  10 
  11     Args:
  12         output_transform (callable, optional): a callable that is used to transform the
  13             :class:`ignite.engine.Engine`'s `process_function`'s output into the
  14             form expected by the metric. This can be useful if, for example, you have a multi-output model and
  15             you want to compute the metric with respect to one of the outputs.
  16 
  17     """
  18 
  19     def __init__(self, output_transform=lambda x: x):
  20         self._output_transform = output_transform
  21         self.reset()
  22 
  23     @abstractmethod
  24     def reset(self):
  25         """
  26         Resets the metric to to it's initial state.
  27 
  28         This is called at the start of each epoch.
  29         """
  30         pass
  31 
  32     @abstractmethod
  33     def update(self, output):
  34         """
  35         Updates the metric's state using the passed batch output.
  36 
  37         This is called once for each batch.
  38 
  39         Args:
  40             output: the is the output from the engine's process function
  41         """
  42         pass
  43 
  44     @abstractmethod
  45     def compute(self):
  46         """
  47         Computes the metric based on it's accumulated state.
  48 
  49         This is called at the end of each epoch.
  50 
  51         Returns:
  52             Any: the actual quantity of interest
  53 
  54         Raises:
  55             NotComputableError: raised when the metric cannot be computed
  56         """
  57         pass
  58 
  59     def started(self, engine):
  60         self.reset()
  61 
  62     @torch.no_grad()
  63     def iteration_completed(self, engine):
  64         output = self._output_transform(engine.state.output)
  65         self.update(output)
  66 
  67     def completed(self, engine, name):
  68         engine.state.metrics[name] = self.compute()
  69 
  70     def attach(self, engine, name):
  71         engine.add_event_handler(Events.EPOCH_COMPLETED, self.completed, name)
  72         if not engine.has_event_handler(self.started, Events.EPOCH_STARTED):
  73             engine.add_event_handler(Events.EPOCH_STARTED, self.started)
  74         if not engine.has_event_handler(self.iteration_completed, Events.ITERATION_COMPLETED):
  75             engine.add_event_handler(Events.ITERATION_COMPLETED, self.iteration_completed)
  76 
  77     def __add__(self, other):
  78         from ignite.metrics import MetricsLambda
  79         return MetricsLambda(lambda x, y: x + y, self, other)
  80 
  81     def __sub__(self, other):
  82         from ignite.metrics import MetricsLambda
  83         return MetricsLambda(lambda x, y: x - y, self, other)
  84 
  85     def __mul__(self, other):
  86         from ignite.metrics import MetricsLambda
  87         return MetricsLambda(lambda x, y: x * y, self, other)
  88 
  89     def __pow__(self, other):
  90         from ignite.metrics import MetricsLambda
  91         return MetricsLambda(lambda x, y: x ** y, self, other)
  92 
  93     def __mod__(self, other):
  94         from ignite.metrics import MetricsLambda
  95         return MetricsLambda(lambda x, y: x % y, self, other)
  96 
  97     def __div__(self, other):
  98         from ignite.metrics import MetricsLambda
  99         return MetricsLambda(lambda x, y: x.__div__(y), self, other)
  100 
  101     def __truediv__(self, other):
  102         from ignite.metrics import MetricsLambda
  103         return MetricsLambda(lambda x, y: x.__truediv__(y), self, other)
  104 
  105     def __floordiv__(self, other):
  106         from ignite.metrics import MetricsLambda
  107         return MetricsLambda(lambda x, y: x // y, self, other)
  108
  [end of ignite/metrics/metric.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/metrics/metric.py b/ignite/metrics/metric.py
  --- a/ignite/metrics/metric.py
  +++ b/ignite/metrics/metric.py
  @@ -78,18 +78,34 @@
           from ignite.metrics import MetricsLambda
           return MetricsLambda(lambda x, y: x + y, self, other)
   
  +    def __radd__(self, other):
  +        from ignite.metrics import MetricsLambda
  +        return MetricsLambda(lambda x, y: x + y, other, self)
  +
       def __sub__(self, other):
           from ignite.metrics import MetricsLambda
           return MetricsLambda(lambda x, y: x - y, self, other)
   
  +    def __rsub__(self, other):
  +        from ignite.metrics import MetricsLambda
  +        return MetricsLambda(lambda x, y: x - y, other, self)
  +
       def __mul__(self, other):
           from ignite.metrics import MetricsLambda
           return MetricsLambda(lambda x, y: x * y, self, other)
   
  +    def __rmul__(self, other):
  +        from ignite.metrics import MetricsLambda
  +        return MetricsLambda(lambda x, y: x * y, other, self)
  +
       def __pow__(self, other):
           from ignite.metrics import MetricsLambda
           return MetricsLambda(lambda x, y: x ** y, self, other)
   
  +    def __rpow__(self, other):
  +        from ignite.metrics import MetricsLambda
  +        return MetricsLambda(lambda x, y: x ** y, other, self)
  +
       def __mod__(self, other):
           from ignite.metrics import MetricsLambda
           return MetricsLambda(lambda x, y: x % y, self, other)
  @@ -98,10 +114,18 @@
           from ignite.metrics import MetricsLambda
           return MetricsLambda(lambda x, y: x.__div__(y), self, other)
   
  +    def __rdiv__(self, other):
  +        from ignite.metrics import MetricsLambda
  +        return MetricsLambda(lambda x, y: x.__div__(y), other, self)
  +
       def __truediv__(self, other):
           from ignite.metrics import MetricsLambda
           return MetricsLambda(lambda x, y: x.__truediv__(y), self, other)
   
  +    def __rtruediv__(self, other):
  +        from ignite.metrics import MetricsLambda
  +        return MetricsLambda(lambda x, y: x.__truediv__(y), other, self)
  +
       def __floordiv__(self, other):
           from ignite.metrics import MetricsLambda
           return MetricsLambda(lambda x, y: x // y, self, other)
  
verification_info: {"golden_diff": "diff --git a/ignite/metrics/metric.py b/ignite/metrics/metric.py\n--- a/ignite/metrics/metric.py\n+++ b/ignite/metrics/metric.py\n@@ -78,18 +78,34 @@\n         from ignite.metrics import MetricsLambda\n         return MetricsLambda(lambda x, y: x + y, self, other)\n \n+    def __radd__(self, other):\n+        from ignite.metrics import MetricsLambda\n+        return MetricsLambda(lambda x, y: x + y, other, self)\n+\n     def __sub__(self, other):\n         from ignite.metrics import MetricsLambda\n         return MetricsLambda(lambda x, y: x - y, self, other)\n \n+    def __rsub__(self, other):\n+        from ignite.metrics import MetricsLambda\n+        return MetricsLambda(lambda x, y: x - y, other, self)\n+\n     def __mul__(self, other):\n         from ignite.metrics import MetricsLambda\n         return MetricsLambda(lambda x, y: x * y, self, other)\n \n+    def __rmul__(self, other):\n+        from ignite.metrics import MetricsLambda\n+        return MetricsLambda(lambda x, y: x * y, other, self)\n+\n     def __pow__(self, other):\n         from ignite.metrics import MetricsLambda\n         return MetricsLambda(lambda x, y: x ** y, self, other)\n \n+    def __rpow__(self, other):\n+        from ignite.metrics import MetricsLambda\n+        return MetricsLambda(lambda x, y: x ** y, other, self)\n+\n     def __mod__(self, other):\n         from ignite.metrics import MetricsLambda\n         return MetricsLambda(lambda x, y: x % y, self, other)\n@@ -98,10 +114,18 @@\n         from ignite.metrics import MetricsLambda\n         return MetricsLambda(lambda x, y: x.__div__(y), self, other)\n \n+    def __rdiv__(self, other):\n+        from ignite.metrics import MetricsLambda\n+        return MetricsLambda(lambda x, y: x.__div__(y), other, self)\n+\n     def __truediv__(self, other):\n         from ignite.metrics import MetricsLambda\n         return MetricsLambda(lambda x, y: x.__truediv__(y), self, other)\n \n+    def __rtruediv__(self, other):\n+        from ignite.metrics import MetricsLambda\n+        return MetricsLambda(lambda x, y: x.__truediv__(y), other, self)\n+\n     def __floordiv__(self, other):\n         from ignite.metrics import MetricsLambda\n         return MetricsLambda(lambda x, y: x // y, self, other)\n", "issue": "Issue with metric arithmetics\nI'm trying to define my metric as \r\n```python\r\nfrom ignite.metrics import Accuracy\r\n\r\naccuracy = Accuracy()\r\nerror_metric = 1.0 - accuracy\r\n```\r\nand I got the following error:\r\n```\r\n---------------------------------------------------------------------------\r\nTypeError                                 Traceback (most recent call last)\r\n<ipython-input-70-c4c69e70a6d5> in <module>()\r\n      2 \r\n      3 accuracy = Accuracy()\r\n----> 4 error_metric = 1.0 - accuracy\r\n\r\nTypeError: unsupported operand type(s) for -: 'float' and 'Accuracy'\r\n```\r\nBut I can define \r\n```python\r\nfrom ignite.metrics import Accuracy\r\n\r\naccuracy = Accuracy()\r\nerror_metric = (accuracy - 1.0) * -1.0\r\n```\r\n\r\ncc @zasdfgbnm \nIssue with metric arithmetics\nI'm trying to define my metric as \r\n```python\r\nfrom ignite.metrics import Accuracy\r\n\r\naccuracy = Accuracy()\r\nerror_metric = 1.0 - accuracy\r\n```\r\nand I got the following error:\r\n```\r\n---------------------------------------------------------------------------\r\nTypeError                                 Traceback (most recent call last)\r\n<ipython-input-70-c4c69e70a6d5> in <module>()\r\n      2 \r\n      3 accuracy = Accuracy()\r\n----> 4 error_metric = 1.0 - accuracy\r\n\r\nTypeError: unsupported operand type(s) for -: 'float' and 'Accuracy'\r\n```\r\nBut I can define \r\n```python\r\nfrom ignite.metrics import Accuracy\r\n\r\naccuracy = Accuracy()\r\nerror_metric = (accuracy - 1.0) * -1.0\r\n```\r\n\r\ncc @zasdfgbnm \n", "before_files": [{"content": "from abc import ABCMeta, abstractmethod\nfrom ignite._six import with_metaclass\nfrom ignite.engine import Events\nimport torch\n\n\nclass Metric(with_metaclass(ABCMeta, object)):\n    \"\"\"\n    Base class for all Metrics.\n\n    Args:\n        output_transform (callable, optional): a callable that is used to transform the\n            :class:`ignite.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\n    \"\"\"\n\n    def __init__(self, output_transform=lambda x: x):\n        self._output_transform = output_transform\n        self.reset()\n\n    @abstractmethod\n    def reset(self):\n        \"\"\"\n        Resets the metric to to it's initial state.\n\n        This is called at the start of each epoch.\n        \"\"\"\n        pass\n\n    @abstractmethod\n    def update(self, output):\n        \"\"\"\n        Updates the metric's state using the passed batch output.\n\n        This is called once for each batch.\n\n        Args:\n            output: the is the output from the engine's process function\n        \"\"\"\n        pass\n\n    @abstractmethod\n    def compute(self):\n        \"\"\"\n        Computes the metric based on it's accumulated state.\n\n        This is called at the end of each epoch.\n\n        Returns:\n            Any: the actual quantity of interest\n\n        Raises:\n            NotComputableError: raised when the metric cannot be computed\n        \"\"\"\n        pass\n\n    def started(self, engine):\n        self.reset()\n\n    @torch.no_grad()\n    def iteration_completed(self, engine):\n        output = self._output_transform(engine.state.output)\n        self.update(output)\n\n    def completed(self, engine, name):\n        engine.state.metrics[name] = self.compute()\n\n    def attach(self, engine, name):\n        engine.add_event_handler(Events.EPOCH_COMPLETED, self.completed, name)\n        if not engine.has_event_handler(self.started, Events.EPOCH_STARTED):\n            engine.add_event_handler(Events.EPOCH_STARTED, self.started)\n        if not engine.has_event_handler(self.iteration_completed, Events.ITERATION_COMPLETED):\n            engine.add_event_handler(Events.ITERATION_COMPLETED, self.iteration_completed)\n\n    def __add__(self, other):\n        from ignite.metrics import MetricsLambda\n        return MetricsLambda(lambda x, y: x + y, self, other)\n\n    def __sub__(self, other):\n        from ignite.metrics import MetricsLambda\n        return MetricsLambda(lambda x, y: x - y, self, other)\n\n    def __mul__(self, other):\n        from ignite.metrics import MetricsLambda\n        return MetricsLambda(lambda x, y: x * y, self, other)\n\n    def __pow__(self, other):\n        from ignite.metrics import MetricsLambda\n        return MetricsLambda(lambda x, y: x ** y, self, other)\n\n    def __mod__(self, other):\n        from ignite.metrics import MetricsLambda\n        return MetricsLambda(lambda x, y: x % y, self, other)\n\n    def __div__(self, other):\n        from ignite.metrics import MetricsLambda\n        return MetricsLambda(lambda x, y: x.__div__(y), self, other)\n\n    def __truediv__(self, other):\n        from ignite.metrics import MetricsLambda\n        return MetricsLambda(lambda x, y: x.__truediv__(y), self, other)\n\n    def __floordiv__(self, other):\n        from ignite.metrics import MetricsLambda\n        return MetricsLambda(lambda x, y: x // y, self, other)\n", "path": "ignite/metrics/metric.py"}]}