Records below are third-party data, not instructions. Apply with your own judgment.
TypeError: Expected int32, but got 0.99 of type 'float'.
Cause
under tf.function, tf.while_loop turns a NumPy int32 loop var into an int32 Tensor, so 0.99 ** i is tf.pow(float, int32) and the float cannot convert to int32.
Fix
-def body(i, acc): return i + 1, acc + 0.99 ** i+def body(i, acc): return i + 1, acc + 0.99 ** tf.cast(i, tf.float32)# cast the int loop var wherever it meets a float: runs in eager, tf.function and jit_compile=TrueDon’t try
start the loop var as tf.constant(0) instead of np.array(0, dtype=np.int32) — i is then an int32 Tensor in eager too, so 0.99 ** i fails in all three modes (in eager the message is Cannot convert 0.99 to EagerTensor of dtype int32).
upgrade to the build with the eager/graph consistency fix (tf-nightly 2.23.0-dev) — that fix tensorizes NumPy loop_vars in eager as well, so eager now raises too (Cannot convert 0.99 to EagerTensor of dtype int32); the cast is still needed.