prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  scan
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `ivy/functional/frontends/jax/lax/control_flow_operators.py`
  Content:
  ```
  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 FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
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"}], "after_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\n\n@to_ivy_arrays_and_back\ndef 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", "path": "ivy/functional/frontends/jax/lax/control_flow_operators.py"}]}