prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Inconsistency of type checking between SoftmaxCrossEntropy and Accuracy
  We often evaluate training procedure with both `softmax_cross_entropy` and `accuracy`, as default `chainer.links.Classifier` does. But there are cases `softmax_cross_entorpy(x, t)` is accepted but `accuracy(x, t)` raises error because of its type checking (and vise versa). Replicated softmax is one of a such examples (e.g. `x.shape = (B, C, N)` and `t.shape = (B, N)`). We need to reshape them manually in such a case.
  
  It is convenient for users that shape checking of the two be more consistent.
  
  
  </issue>
  <code>
  [start of chainer/functions/evaluation/accuracy.py]
  1 import numpy
  2 
  3 from chainer import cuda
  4 from chainer import function
  5 from chainer.utils import type_check
  6 
  7 
  8 class Accuracy(function.Function):
  9 
  10     def __init__(self, ignore_label=None):
  11         self.ignore_label = ignore_label
  12 
  13     def check_type_forward(self, in_types):
  14         type_check.expect(in_types.size() == 2)
  15         x_type, t_type = in_types
  16 
  17         type_check.expect(
  18             x_type.dtype.kind == 'f',
  19             x_type.ndim >= 2,
  20             t_type.dtype == numpy.int32,
  21             t_type.ndim == 1,
  22             t_type.shape[0] == x_type.shape[0],
  23         )
  24         for i in range(2, x_type.ndim.eval()):
  25             type_check.expect(x_type.shape[i] == 1)
  26 
  27     def forward(self, inputs):
  28         xp = cuda.get_array_module(*inputs)
  29         y, t = inputs
  30         y = y.reshape(len(y), -1)  # flatten
  31 
  32         if self.ignore_label is not None:
  33             mask = (t == self.ignore_label)
  34             ignore_cnt = mask.sum()
  35 
  36             # will always be true when the true label is ignore_label
  37             # TODO(henry0312)
  38             #   If cupy.where returns indexes, we could make the code better.
  39             #   Also, we would need Advanced Indexing.
  40             pred = xp.where(mask, self.ignore_label, y.argmax(axis=1))
  41             count = (pred == t).sum() - ignore_cnt
  42             total = len(t) - ignore_cnt
  43 
  44             if total == 0:
  45                 return xp.asarray(0.0, dtype=y.dtype),
  46             else:
  47                 return xp.asarray(float(count) / total, dtype=y.dtype),
  48         else:
  49             pred = y.argmax(axis=1)
  50             return xp.asarray((pred == t).mean(dtype=y.dtype)),
  51 
  52 
  53 def accuracy(y, t, ignore_label=None):
  54     """Computes muticlass classification accuracy of the minibatch.
  55 
  56     Args:
  57         y (Variable): Variable holding a matrix whose (i, j)-th element
  58             indicates the score of the class j at the i-th example.
  59         t (Variable): Variable holding an int32 vector of ground truth labels.
  60         ignore_label (int or None): Skip calculating accuracy
  61             if the ture label is ``ignore_label``.
  62 
  63     Returns:
  64         Variable: A variable holding a scalar array of the accuracy.
  65 
  66     .. note:: This function is non-differentiable.
  67 
  68     """
  69     return Accuracy(ignore_label=ignore_label)(y, t)
  70
  [end of chainer/functions/evaluation/accuracy.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/chainer/functions/evaluation/accuracy.py b/chainer/functions/evaluation/accuracy.py
  --- a/chainer/functions/evaluation/accuracy.py
  +++ b/chainer/functions/evaluation/accuracy.py
  @@ -1,4 +1,5 @@
   import numpy
  +import six
   
   from chainer import cuda
   from chainer import function
  @@ -16,18 +17,21 @@
   
           type_check.expect(
               x_type.dtype.kind == 'f',
  -            x_type.ndim >= 2,
  -            t_type.dtype == numpy.int32,
  -            t_type.ndim == 1,
  -            t_type.shape[0] == x_type.shape[0],
  +            t_type.dtype == numpy.int32
           )
  -        for i in range(2, x_type.ndim.eval()):
  +
  +        t_ndim = t_type.ndim.eval()
  +        type_check.expect(
  +            x_type.ndim >= t_type.ndim,
  +            x_type.shape[0] == t_type.shape[0],
  +            x_type.shape[2: t_ndim + 1] == t_type.shape[1:]
  +        )
  +        for i in six.moves.range(t_ndim + 1, x_type.ndim.eval()):
               type_check.expect(x_type.shape[i] == 1)
   
       def forward(self, inputs):
           xp = cuda.get_array_module(*inputs)
           y, t = inputs
  -        y = y.reshape(len(y), -1)  # flatten
   
           if self.ignore_label is not None:
               mask = (t == self.ignore_label)
  @@ -37,16 +41,17 @@
               # TODO(henry0312)
               #   If cupy.where returns indexes, we could make the code better.
               #   Also, we would need Advanced Indexing.
  -            pred = xp.where(mask, self.ignore_label, y.argmax(axis=1))
  +            pred = xp.where(mask, self.ignore_label,
  +                            y.argmax(axis=1).reshape(t.shape))
               count = (pred == t).sum() - ignore_cnt
  -            total = len(t) - ignore_cnt
  +            total = t.size - ignore_cnt
   
               if total == 0:
                   return xp.asarray(0.0, dtype=y.dtype),
               else:
                   return xp.asarray(float(count) / total, dtype=y.dtype),
           else:
  -            pred = y.argmax(axis=1)
  +            pred = y.argmax(axis=1).reshape(t.shape)
               return xp.asarray((pred == t).mean(dtype=y.dtype)),
  
verification_info: {"golden_diff": "diff --git a/chainer/functions/evaluation/accuracy.py b/chainer/functions/evaluation/accuracy.py\n--- a/chainer/functions/evaluation/accuracy.py\n+++ b/chainer/functions/evaluation/accuracy.py\n@@ -1,4 +1,5 @@\n import numpy\n+import six\n \n from chainer import cuda\n from chainer import function\n@@ -16,18 +17,21 @@\n \n         type_check.expect(\n             x_type.dtype.kind == 'f',\n-            x_type.ndim >= 2,\n-            t_type.dtype == numpy.int32,\n-            t_type.ndim == 1,\n-            t_type.shape[0] == x_type.shape[0],\n+            t_type.dtype == numpy.int32\n         )\n-        for i in range(2, x_type.ndim.eval()):\n+\n+        t_ndim = t_type.ndim.eval()\n+        type_check.expect(\n+            x_type.ndim >= t_type.ndim,\n+            x_type.shape[0] == t_type.shape[0],\n+            x_type.shape[2: t_ndim + 1] == t_type.shape[1:]\n+        )\n+        for i in six.moves.range(t_ndim + 1, x_type.ndim.eval()):\n             type_check.expect(x_type.shape[i] == 1)\n \n     def forward(self, inputs):\n         xp = cuda.get_array_module(*inputs)\n         y, t = inputs\n-        y = y.reshape(len(y), -1)  # flatten\n \n         if self.ignore_label is not None:\n             mask = (t == self.ignore_label)\n@@ -37,16 +41,17 @@\n             # TODO(henry0312)\n             #   If cupy.where returns indexes, we could make the code better.\n             #   Also, we would need Advanced Indexing.\n-            pred = xp.where(mask, self.ignore_label, y.argmax(axis=1))\n+            pred = xp.where(mask, self.ignore_label,\n+                            y.argmax(axis=1).reshape(t.shape))\n             count = (pred == t).sum() - ignore_cnt\n-            total = len(t) - ignore_cnt\n+            total = t.size - ignore_cnt\n \n             if total == 0:\n                 return xp.asarray(0.0, dtype=y.dtype),\n             else:\n                 return xp.asarray(float(count) / total, dtype=y.dtype),\n         else:\n-            pred = y.argmax(axis=1)\n+            pred = y.argmax(axis=1).reshape(t.shape)\n             return xp.asarray((pred == t).mean(dtype=y.dtype)),\n", "issue": "Inconsistency of type checking between SoftmaxCrossEntropy and Accuracy\nWe often evaluate training procedure with both `softmax_cross_entropy` and `accuracy`, as default `chainer.links.Classifier` does. But there are cases `softmax_cross_entorpy(x, t)` is accepted but `accuracy(x, t)` raises error because of its type checking (and vise versa). Replicated softmax is one of a such examples (e.g. `x.shape = (B, C, N)` and `t.shape = (B, N)`). We need to reshape them manually in such a case.\n\nIt is convenient for users that shape checking of the two be more consistent.\n\n", "before_files": [{"content": "import numpy\n\nfrom chainer import cuda\nfrom chainer import function\nfrom chainer.utils import type_check\n\n\nclass Accuracy(function.Function):\n\n    def __init__(self, ignore_label=None):\n        self.ignore_label = ignore_label\n\n    def check_type_forward(self, in_types):\n        type_check.expect(in_types.size() == 2)\n        x_type, t_type = in_types\n\n        type_check.expect(\n            x_type.dtype.kind == 'f',\n            x_type.ndim >= 2,\n            t_type.dtype == numpy.int32,\n            t_type.ndim == 1,\n            t_type.shape[0] == x_type.shape[0],\n        )\n        for i in range(2, x_type.ndim.eval()):\n            type_check.expect(x_type.shape[i] == 1)\n\n    def forward(self, inputs):\n        xp = cuda.get_array_module(*inputs)\n        y, t = inputs\n        y = y.reshape(len(y), -1)  # flatten\n\n        if self.ignore_label is not None:\n            mask = (t == self.ignore_label)\n            ignore_cnt = mask.sum()\n\n            # will always be true when the true label is ignore_label\n            # TODO(henry0312)\n            #   If cupy.where returns indexes, we could make the code better.\n            #   Also, we would need Advanced Indexing.\n            pred = xp.where(mask, self.ignore_label, y.argmax(axis=1))\n            count = (pred == t).sum() - ignore_cnt\n            total = len(t) - ignore_cnt\n\n            if total == 0:\n                return xp.asarray(0.0, dtype=y.dtype),\n            else:\n                return xp.asarray(float(count) / total, dtype=y.dtype),\n        else:\n            pred = y.argmax(axis=1)\n            return xp.asarray((pred == t).mean(dtype=y.dtype)),\n\n\ndef accuracy(y, t, ignore_label=None):\n    \"\"\"Computes muticlass classification accuracy of the minibatch.\n\n    Args:\n        y (Variable): Variable holding a matrix whose (i, j)-th element\n            indicates the score of the class j at the i-th example.\n        t (Variable): Variable holding an int32 vector of ground truth labels.\n        ignore_label (int or None): Skip calculating accuracy\n            if the ture label is ``ignore_label``.\n\n    Returns:\n        Variable: A variable holding a scalar array of the accuracy.\n\n    .. note:: This function is non-differentiable.\n\n    \"\"\"\n    return Accuracy(ignore_label=ignore_label)(y, t)\n", "path": "chainer/functions/evaluation/accuracy.py"}]}