How to run this conditional execution in Tensorflow?
<p>I'd like to assign a value to a tensor only once, and keep it untouched in all later executions. In other words,  I would like to implement something like the following:</p>

<pre><code>x = tf.cond(tf.equal(x_ready, 0), ComputeX(), tf.no_op)
</code></pre>

<p>This of course will not work, since tf.no_op does not return a tensor. So is there is any easy way of implementing an equivalent to the following C++ code in Tensorflow?</p>

<pre><code>x_ready = false;
if (!x_ready) {
  x = ComputeX();
  x_ready = true;
}  // and there is no "else" branch
</code></pre>

<p>Note that I don't wish to implement it in the following way:</p>

<pre><code>x = tf.cond(tf.equal(x_ready, 0), ComputeX(), tf.identity(x))
</code></pre>

<p>since "x" is not declared before this statement. If seems Tensorflow is inflexible for single-branch conditional executions - you always have to provide two funcitons fn1, fn2 for both "true" and "false" cases, even if fn2 is not necessary.</p>