prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  scan
  
  
  </issue>
  <code>
  [start of ivy/functional/frontends/jax/lax/control_flow_operators.py]
  1 # global
  2 import ivy
  3 from ivy.functional.frontends.jax.func_wrapper import to_ivy_arrays_and_back
  4 
  5 
  6 @to_ivy_arrays_and_back
  7 def cond(pred, true_fun, false_fun, *operands, operand=None, linear=None):
  8     if operand is not None:
  9         if operands:
  10             raise ivy.utils.exceptions.IvyException(
  11                 "if `operand` is passed, positional `operands` should not be passed"
  12             )
  13         operands = (operand,)
  14 
  15     if pred:
  16         return true_fun(*operands)
  17     return false_fun(*operands)
  18 
  19 
  20 @to_ivy_arrays_and_back
  21 def map(f, xs):
  22     return ivy.stack([f(x) for x in xs])
  23 
  24 
  25 @to_ivy_arrays_and_back
  26 def switch(index, branches, *operands, operand=None):
  27     if operand is not None:
  28         if operands:
  29             raise ivy.utils.exceptions.IvyException(
  30                 "if `operand` is passed, positional `operands` should not be passed"
  31             )
  32         operands = (operand,)
  33 
  34     index = max(index, 0)
  35     index = min(len(branches) - 1, index)
  36     return branches[index](*operands)
  37 
  38 
  39 @to_ivy_arrays_and_back
  40 def fori_loop(lower, upper, body_fun, init_val):
  41     if not (callable(body_fun)):
  42         raise ivy.exceptions.IvyException(
  43             "jax.lax.fori_loop: Argument body_fun should be callable."
  44         )
  45     val = init_val
  46     for i in range(lower, upper):
  47         val = body_fun(i, val)
  48     return val
  49 
  50 
  51 @to_ivy_arrays_and_back
  52 def while_loop(cond_fun, body_fun, init_val):
  53     if not (callable(body_fun) and callable(cond_fun)):
  54         raise ivy.exceptions.IvyException(
  55             "jax.lax.while_loop: Arguments body_fun and cond_fun should be callable."
  56         )
  57     val = init_val
  58     while cond_fun(val):
  59         val = body_fun(val)
  60     return val
  61
  [end of ivy/functional/frontends/jax/lax/control_flow_operators.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/ivy/functional/frontends/jax/lax/control_flow_operators.py b/ivy/functional/frontends/jax/lax/control_flow_operators.py
  --- a/ivy/functional/frontends/jax/lax/control_flow_operators.py
  +++ b/ivy/functional/frontends/jax/lax/control_flow_operators.py
  @@ -58,3 +58,29 @@
       while cond_fun(val):
           val = body_fun(val)
       return val
  +
  +
  +@to_ivy_arrays_and_back
  +def scan(f, init, xs, length=None, reverse=False, unroll=1):
  +    if not (callable(f)):
  +        raise ivy.exceptions.IvyException(
  +            "jax.lax.scan: Argument f should be callable."
  +        )
  +    if xs is None and length is None:
  +        raise ivy.exceptions.IvyException(
  +            "jax.lax.scan: Either xs or length must be provided."
  +        )
  +
  +    if length is not None and (not isinstance(length, int) or length < 0):
  +        raise ivy.exceptions.IvyException(
  +            "jax.lax.scan: length must be a non-negative integer."
  +        )
  +    if xs is None:
  +        xs = [None] * length
  +
  +    carry = init
  +    ys = []
  +    for x in xs:
  +        carry, y = f(carry, x)
  +        ys.append(y)
  +    return carry, ivy.stack(ys)
  
verification_info: {"golden_diff": "diff --git a/ivy/functional/frontends/jax/lax/control_flow_operators.py b/ivy/functional/frontends/jax/lax/control_flow_operators.py\n--- a/ivy/functional/frontends/jax/lax/control_flow_operators.py\n+++ b/ivy/functional/frontends/jax/lax/control_flow_operators.py\n@@ -58,3 +58,29 @@\n     while cond_fun(val):\n         val = body_fun(val)\n     return val\n+\n+\n+@to_ivy_arrays_and_back\n+def scan(f, init, xs, length=None, reverse=False, unroll=1):\n+    if not (callable(f)):\n+        raise ivy.exceptions.IvyException(\n+            \"jax.lax.scan: Argument f should be callable.\"\n+        )\n+    if xs is None and length is None:\n+        raise ivy.exceptions.IvyException(\n+            \"jax.lax.scan: Either xs or length must be provided.\"\n+        )\n+\n+    if length is not None and (not isinstance(length, int) or length < 0):\n+        raise ivy.exceptions.IvyException(\n+            \"jax.lax.scan: length must be a non-negative integer.\"\n+        )\n+    if xs is None:\n+        xs = [None] * length\n+\n+    carry = init\n+    ys = []\n+    for x in xs:\n+        carry, y = f(carry, x)\n+        ys.append(y)\n+    return carry, ivy.stack(ys)\n", "issue": "scan\n\n", "before_files": [{"content": "# global\nimport ivy\nfrom ivy.functional.frontends.jax.func_wrapper import to_ivy_arrays_and_back\n\n\n@to_ivy_arrays_and_back\ndef cond(pred, true_fun, false_fun, *operands, operand=None, linear=None):\n    if operand is not None:\n        if operands:\n            raise ivy.utils.exceptions.IvyException(\n                \"if `operand` is passed, positional `operands` should not be passed\"\n            )\n        operands = (operand,)\n\n    if pred:\n        return true_fun(*operands)\n    return false_fun(*operands)\n\n\n@to_ivy_arrays_and_back\ndef map(f, xs):\n    return ivy.stack([f(x) for x in xs])\n\n\n@to_ivy_arrays_and_back\ndef switch(index, branches, *operands, operand=None):\n    if operand is not None:\n        if operands:\n            raise ivy.utils.exceptions.IvyException(\n                \"if `operand` is passed, positional `operands` should not be passed\"\n            )\n        operands = (operand,)\n\n    index = max(index, 0)\n    index = min(len(branches) - 1, index)\n    return branches[index](*operands)\n\n\n@to_ivy_arrays_and_back\ndef fori_loop(lower, upper, body_fun, init_val):\n    if not (callable(body_fun)):\n        raise ivy.exceptions.IvyException(\n            \"jax.lax.fori_loop: Argument body_fun should be callable.\"\n        )\n    val = init_val\n    for i in range(lower, upper):\n        val = body_fun(i, val)\n    return val\n\n\n@to_ivy_arrays_and_back\ndef while_loop(cond_fun, body_fun, init_val):\n    if not (callable(body_fun) and callable(cond_fun)):\n        raise ivy.exceptions.IvyException(\n            \"jax.lax.while_loop: Arguments body_fun and cond_fun should be callable.\"\n        )\n    val = init_val\n    while cond_fun(val):\n        val = body_fun(val)\n    return val\n", "path": "ivy/functional/frontends/jax/lax/control_flow_operators.py"}]}