title: Successive matrix multiplication in R using TensorFlow
body: <p>A simple question.</p>
  
  <p>Suppose I have an <code>m x m</code> <code>matrix</code> (<code>mat</code>)  which I'd like to raise to the power of <code>n</code>, meaning <code>mat %*% mat %*% mat %*%</code> ... (and suppose I'd like to keep all the intermediate products)</p>
  
  <p>To to this using <code>tensorflow</code> (since I want to make it efficient using <code>GPU</code>s), would the <code>code</code> be:</p>
  
  <pre><code>library(tensorflow)
  set.seed(1)
  m &lt;- 9 #in my real data m is pretty big though
  mat &lt;- matrix(rnorm(m*m),m,m)
  tf.mat &lt;- tf$constant(mat)
  tf.prod.mat &lt;- tf$constant(mat)
  n &lt;- 4
  prod.list &lt;- vector(mode="list",n)
  for(i in 1:n){
    mat.mat.prod &lt;- tf$matmul(tf.prod.mat,tf.mat)
    sess &lt;- tf$Session()
    prod.list[[i]] &lt;- sess$run(mat.mat.prod)
    tf.prod.mat &lt;- tf$constant(prod.list[[i]])
  }
  sess$close()
  </code></pre>
  
  <p>Or am I not using <code>tensorflow</code> appropriately?</p>