title: Tensorflow sparse to dense operations failing when placeholder provided shape
body: <p>I'm having an issue multiplying a sparse tensor (a sparse placeholder) by a dense tensor in Tensorflow. I am also encountering problems converting a sparse tensor to a dense tensor directly. I've searched but so far haven't found an example of this problem.</p>
  
  <h2>TL;DR</h2>
  
  <p>The computation works if the sparse placeholder has its <code>shape</code> argument set to <code>None</code>, but if I provide a shape like <code>(3,3)</code> it fails.</p>
  
  <p>Here is the code that works:</p>
  
  <pre><code>import tensorflow as tf
  import numpy as np
  
  matrix_place = tf.placeholder(tf.float32, name="foo", shape=(3,2))
  sparse_place = tf.sparse_placeholder(tf.float32, name="bar", shape=None) # Note shape is None
  
  mul_result = tf.sparse_tensor_dense_matmul(sparse_place, matrix_place)
  
  matrix_input = np.ones((3,2))
  sparse_input = tf.SparseTensorValue([[0,0], [1,1], [2,2]], [1, 2, 3], (3, 3))
  
  with tf.Session() as sess:
      result = sess.run(mul_result, feed_dict={sparse_place: sparse_input, matrix_place: matrix_input})
      print(result)
  </code></pre>
  
  <p>Output (as expected):</p>
  
  <pre><code>[[1. 1.]
   [2. 2.]
   [3. 3.]]
  </code></pre>
  
  <p>Now, if I change this line:</p>
  
  <pre><code>sparse_place = tf.sparse_placeholder(tf.float32, name="bar", shape=None)
  </code></pre>
  
  <p>to this:</p>
  
  <pre><code>sparse_place = tf.sparse_placeholder(tf.float32, name="bar", shape=(3,3))
  </code></pre>
  
  <p>(which matches the shape of the <code>tf.SparseTenorValue(...)</code> that I'm feeding in), I get the following error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "testing_sparse3.py", line 13, in &lt;module&gt;
      result = sess.run(mul_result, feed_dict={sparse_place: sparse_input, matrix_place: matrix_input})
    File "C:\Anaconda3\envs\tensorflow-cpu\lib\site-packages\tensorflow\python\client\session.py", line 905, in run
      run_metadata_ptr)
    File "C:\Anaconda3\envs\tensorflow-cpu\lib\site-packages\tensorflow\python\client\session.py", line 1115, in _run
      raise ValueError('Tensor %s may not be fed.' % subfeed_t)
  ValueError: Tensor Tensor("bar/shape:0", shape=(2,), dtype=int64) may not be fed.
  </code></pre>
  
  <h2>Things I've Tried</h2>
  
  <p>If I switch from matrix multiplication (which involves 2 tensors):</p>
  
  <pre><code>sparse_place = tf.sparse_placeholder(tf.float32, name="bar", shape=(3,3))
  
  mul_result = tf.sparse_tensor_dense_matmul(sparse_place, matrix_place)
  </code></pre>
  
  <p>to simply summing the elements of the sparse tensor (which only involves the sparse tensor):</p>
  
  <pre><code>sparse_place = tf.sparse_placeholder(tf.float32, name="bar", shape=(3,3))
  
  mul_result = tf.sparse_tensor_reduce_sum(sparse_place)
  </code></pre>
  
  <p>it does not produce an error and gives the correct result. But if I try to convert the sparse tensor to a dense tensor (an op which also only involves the sparse tensor):</p>
  
  <pre><code>sparse_place = tf.sparse_placeholder(tf.float32, name="bar", shape=(3,3))
  
  mul_result = tf.sparse_tensor_to_dense(sparse_place)
  </code></pre>
  
  <p>the error returns.</p>
  
  <p>I did see a <a href="https://github.com/tensorflow/tensorflow/issues/6749" rel="nofollow noreferrer">related</a> issue but it appears to have been <a href="https://github.com/tensorflow/tensorflow/pull/11153" rel="nofollow noreferrer">merged</a> already. I tried converting the indices/values/shape passed to <code>tf.SparseTensorValue</code> into numpy arrays with dtypes <code>int64</code>/<code>float32</code>/<code>int64</code> respectively, but the problem persisted. I also tried converting the <code>(3,3)</code> shape passed to the sparse placeholder into a numpy <code>int64</code> array but that also failed.</p>
  
  <p>Any ideas? Am I missing something very obvious? I am using Python 3.5 and Tensorflow v1.6.0 (CPU) on Windows.</p>
  
  <p>Thanks!</p>