title: Why do I get a Theano TypeError when trying to update a shared variable?
body: <p>I'm trying to run a very simple gradient descent on the function y=x^2.
  I've tried implementing it using the following code:</p>
  
  <pre><code>import theano
  from theano import tensor as T
  x = theano.shared(2)
  y = x ** 2
  
  dy_dx = T.grad(y, x)
  learning_rate = 1
  updates = [(x, x - learning_rate * dy_dx)]
  fn = theano.function([], [y], updates = updates)
  </code></pre>
  
  <p>But when I try compile the function "fn", I get the following error: </p>
  
  <pre><code>TypeError: ('An update must have the same type as the original shared 
  variable (shared_var=&lt;TensorType(int64, scalar)&gt;, 
  shared_var.type=TensorType(int64, scalar), 
  update_val=Elemwise{sub,no_inplace}.0, 
  update_val.type=TensorType(float64, scalar)).', 'If the difference is 
  related to the broadcast pattern, you can call the 
  tensor.unbroadcast(var, axis_to_unbroadcast[, ...]) function to remove 
  broadcastable dimensions.')
  </code></pre>
  
  <p>I thought this may be a problem with the learning_rate variable, since it might not be the same type as the x shared variable, but if I modify the code as follows:</p>
  
  <pre><code>updates = [(x, x - dy_dx)]
  </code></pre>
  
  <p>I still get the same error.</p>
  
  <p>I'm stuck :( Any ideas?</p>