tf.while_loop()
tuples .
def rosenbrock(data_tensor):
columns = tf.unstack(data_tensor)
index_summation = (tf.constant(1), tf.constant(0.0))
def condition(index, summation):
return tf.less(index, tf.subtract(tf.shape(columns)[0], 1))
def body(index, summation):
x_i = tf.gather(columns, index)
x_ip1 = tf.gather(columns, tf.add(index, 1))
first_term = tf.square(tf.subtract(x_ip1, tf.square(x_i)))
second_term = tf.square(tf.subtract(x_i, 1.0))
summand = tf.add(tf.multiply(100.0, first_term), second_term)
return tf.add(index, 1), tf.add(summation, summand)
return tf.while_loop(condition, body, index_summation)[1]
, , while. , body()
.
, , .