prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  AverageValueMeter returns incorrect results when `tensor` is passed
  Based on [this thread](https://discuss.pytorch.org/t/confusing-result-about-meter-averagevaluemeter/21819) it seems as if the internal members of the class hold references to the `tensors`, thus yielding wrong results.
  When the `tensor` value is passed by `.item()` the result is correct.
  A simple fix would be to add this condition to `add`:
  ```python
  def add(self, value, n=1):
      if isinstance(value, torch.Tensor):
          value = value.item()
      self.val = value
  ```
  
  I can submit a PR, if that makes sense to you.
  
  </issue>
  <code>
  [start of torchnet/meter/averagevaluemeter.py]
  1 import math
  2 from . import meter
  3 import numpy as np
  4 
  5 
  6 class AverageValueMeter(meter.Meter):
  7     def __init__(self):
  8         super(AverageValueMeter, self).__init__()
  9         self.reset()
  10         self.val = 0
  11 
  12     def add(self, value, n=1):
  13         self.val = value
  14         self.sum += value
  15         self.var += value * value
  16         self.n += n
  17 
  18         if self.n == 0:
  19             self.mean, self.std = np.nan, np.nan
  20         elif self.n == 1:
  21             self.mean, self.std = self.sum, np.inf
  22             self.mean_old = self.mean
  23             self.m_s = 0.0
  24         else:
  25             self.mean = self.mean_old + (value - n * self.mean_old) / float(self.n)
  26             self.m_s += (value - self.mean_old) * (value - self.mean)
  27             self.mean_old = self.mean
  28             self.std = math.sqrt(self.m_s / (self.n - 1.0))
  29 
  30     def value(self):
  31         return self.mean, self.std
  32 
  33     def reset(self):
  34         self.n = 0
  35         self.sum = 0.0
  36         self.var = 0.0
  37         self.val = 0.0
  38         self.mean = np.nan
  39         self.mean_old = 0.0
  40         self.m_s = 0.0
  41         self.std = np.nan
  42
  [end of torchnet/meter/averagevaluemeter.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/torchnet/meter/averagevaluemeter.py b/torchnet/meter/averagevaluemeter.py
  --- a/torchnet/meter/averagevaluemeter.py
  +++ b/torchnet/meter/averagevaluemeter.py
  @@ -18,14 +18,15 @@
           if self.n == 0:
               self.mean, self.std = np.nan, np.nan
           elif self.n == 1:
  -            self.mean, self.std = self.sum, np.inf
  +            self.mean = 0.0 + self.sum  # This is to force a copy in torch/numpy
  +            self.std = np.inf
               self.mean_old = self.mean
               self.m_s = 0.0
           else:
               self.mean = self.mean_old + (value - n * self.mean_old) / float(self.n)
               self.m_s += (value - self.mean_old) * (value - self.mean)
               self.mean_old = self.mean
  -            self.std = math.sqrt(self.m_s / (self.n - 1.0))
  +            self.std = np.sqrt(self.m_s / (self.n - 1.0))
   
       def value(self):
           return self.mean, self.std
  
verification_info: {"golden_diff": "diff --git a/torchnet/meter/averagevaluemeter.py b/torchnet/meter/averagevaluemeter.py\n--- a/torchnet/meter/averagevaluemeter.py\n+++ b/torchnet/meter/averagevaluemeter.py\n@@ -18,14 +18,15 @@\n         if self.n == 0:\n             self.mean, self.std = np.nan, np.nan\n         elif self.n == 1:\n-            self.mean, self.std = self.sum, np.inf\n+            self.mean = 0.0 + self.sum  # This is to force a copy in torch/numpy\n+            self.std = np.inf\n             self.mean_old = self.mean\n             self.m_s = 0.0\n         else:\n             self.mean = self.mean_old + (value - n * self.mean_old) / float(self.n)\n             self.m_s += (value - self.mean_old) * (value - self.mean)\n             self.mean_old = self.mean\n-            self.std = math.sqrt(self.m_s / (self.n - 1.0))\n+            self.std = np.sqrt(self.m_s / (self.n - 1.0))\n \n     def value(self):\n         return self.mean, self.std\n", "issue": "AverageValueMeter returns incorrect results when `tensor` is passed\nBased on [this thread](https://discuss.pytorch.org/t/confusing-result-about-meter-averagevaluemeter/21819) it seems as if the internal members of the class hold references to the `tensors`, thus yielding wrong results.\r\nWhen the `tensor` value is passed by `.item()` the result is correct.\r\nA simple fix would be to add this condition to `add`:\r\n```python\r\ndef add(self, value, n=1):\r\n    if isinstance(value, torch.Tensor):\r\n        value = value.item()\r\n    self.val = value\r\n```\r\n\r\nI can submit a PR, if that makes sense to you.\n", "before_files": [{"content": "import math\nfrom . import meter\nimport numpy as np\n\n\nclass AverageValueMeter(meter.Meter):\n    def __init__(self):\n        super(AverageValueMeter, self).__init__()\n        self.reset()\n        self.val = 0\n\n    def add(self, value, n=1):\n        self.val = value\n        self.sum += value\n        self.var += value * value\n        self.n += n\n\n        if self.n == 0:\n            self.mean, self.std = np.nan, np.nan\n        elif self.n == 1:\n            self.mean, self.std = self.sum, np.inf\n            self.mean_old = self.mean\n            self.m_s = 0.0\n        else:\n            self.mean = self.mean_old + (value - n * self.mean_old) / float(self.n)\n            self.m_s += (value - self.mean_old) * (value - self.mean)\n            self.mean_old = self.mean\n            self.std = math.sqrt(self.m_s / (self.n - 1.0))\n\n    def value(self):\n        return self.mean, self.std\n\n    def reset(self):\n        self.n = 0\n        self.sum = 0.0\n        self.var = 0.0\n        self.val = 0.0\n        self.mean = np.nan\n        self.mean_old = 0.0\n        self.m_s = 0.0\n        self.std = np.nan\n", "path": "torchnet/meter/averagevaluemeter.py"}]}