tf.keras.ops.while_loop
While loop implementation.
tf.keras.ops.while_loop(
cond, body, loop_vars, maximum_iterations=None
)
Args |
cond
|
A callable that represents the termination condition of the loop.
Must accept a loop_vars like structure as an argument. If
loop_vars is a tuple or list, each element of loop_vars will be
passed positionally to the callable.
|
body
|
A callable that represents the loop body. Must accept a
loop_vars like structure as an argument, and return update value
with the same structure. If loop_vars is a tuple or list, each
element of loop_vars will be passed positionally to the callable.
|
loop_vars
|
An arbitrary nested structure of tensor state to persist
across loop iterations.
|
maximum_iterations
|
Optional maximum number of iterations of the while
loop to run. If provided, the cond output is AND-ed with an
additional condition ensuring the number of iterations executed is
no greater than maximum_iterations .
|
Returns |
A list/tuple of tensors, has the same shape and dtype as inputs .
|
Examples:
i = 0
cond = lambda i: i < 10
body = lambda i: i + 1
keras.ops.while_loop(cond, body, i)
10
x, y = 0, 1
cond = lambda x, y: x < 10
body = lambda x, y: (x + 1, y + 1)
keras.ops.while_loop(cond, body, (x, y))
10, 11
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2024-06-07 UTC.
[null,null,["Last updated 2024-06-07 UTC."],[],[]]