prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  cupy.random.permutation() overwrites its argument.
  `cupy.random.permutation()` overwrites its argument.
  This is incompatible with `numpy.random.permutation`.
  
  
  </issue>
  <code>
  [start of cupy/random/permutations.py]
  1 from cupy.random import generator
  2 import six
  3 
  4 
  5 def shuffle(a):
  6     """Shuffles an array.
  7 
  8     Args:
  9         a (cupy.ndarray): The array to be shuffled.
  10 
  11     .. seealso:: :func:`numpy.random.shuffle`
  12 
  13     """
  14     rs = generator.get_random_state()
  15     return rs.shuffle(a)
  16 
  17 
  18 def permutation(a):
  19     """Returns a permuted range or shuffles an array."""
  20     if isinstance(a, six.integer_types):
  21         rs = generator.get_random_state()
  22         return rs.permutation(a)
  23     else:
  24         return shuffle(a)
  25
  [end of cupy/random/permutations.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/cupy/random/permutations.py b/cupy/random/permutations.py
  --- a/cupy/random/permutations.py
  +++ b/cupy/random/permutations.py
  @@ -16,9 +16,20 @@
   
   
   def permutation(a):
  -    """Returns a permuted range or shuffles an array."""
  +    """Returns a permuted range or a permutation of an array.
  +
  +    Args:
  +        a (int or cupy.ndarray): The range or the array to be shuffled.
  +
  +    Returns:
  +        cupy.ndarray: If `a` is an integer, it is permutation range between 0
  +        and `a` - 1.
  +        Otherwise, it is a permutation of `a`.
  +
  +    .. seealso:: :func:`numpy.random.permutation`
  +    """
  +    rs = generator.get_random_state()
       if isinstance(a, six.integer_types):
  -        rs = generator.get_random_state()
           return rs.permutation(a)
       else:
  -        return shuffle(a)
  +        return a[rs.permutation(len(a))]
  
verification_info: {"golden_diff": "diff --git a/cupy/random/permutations.py b/cupy/random/permutations.py\n--- a/cupy/random/permutations.py\n+++ b/cupy/random/permutations.py\n@@ -16,9 +16,20 @@\n \n \n def permutation(a):\n-    \"\"\"Returns a permuted range or shuffles an array.\"\"\"\n+    \"\"\"Returns a permuted range or a permutation of an array.\n+\n+    Args:\n+        a (int or cupy.ndarray): The range or the array to be shuffled.\n+\n+    Returns:\n+        cupy.ndarray: If `a` is an integer, it is permutation range between 0\n+        and `a` - 1.\n+        Otherwise, it is a permutation of `a`.\n+\n+    .. seealso:: :func:`numpy.random.permutation`\n+    \"\"\"\n+    rs = generator.get_random_state()\n     if isinstance(a, six.integer_types):\n-        rs = generator.get_random_state()\n         return rs.permutation(a)\n     else:\n-        return shuffle(a)\n+        return a[rs.permutation(len(a))]\n", "issue": "cupy.random.permutation() overwrites its argument.\n`cupy.random.permutation()` overwrites its argument.\r\nThis is incompatible with `numpy.random.permutation`.\r\n\n", "before_files": [{"content": "from cupy.random import generator\nimport six\n\n\ndef shuffle(a):\n    \"\"\"Shuffles an array.\n\n    Args:\n        a (cupy.ndarray): The array to be shuffled.\n\n    .. seealso:: :func:`numpy.random.shuffle`\n\n    \"\"\"\n    rs = generator.get_random_state()\n    return rs.shuffle(a)\n\n\ndef permutation(a):\n    \"\"\"Returns a permuted range or shuffles an array.\"\"\"\n    if isinstance(a, six.integer_types):\n        rs = generator.get_random_state()\n        return rs.permutation(a)\n    else:\n        return shuffle(a)\n", "path": "cupy/random/permutations.py"}]}