title: Initializing a symmetric Theano dmatrix from its upper triangle
body: <p>I'm trying to fit a Theano model that is parametrized in part by a symmetric matrix <code>A</code>. In order to enforce the symmetry of <code>A</code>, I want to be able to construct <code>A</code> by passing in just the values in the upper triangle.</p>
  
  <p>The equivalent numpy code might look something like this:</p>
  
  <pre><code>import numpy as np
  
  def make_symmetric(p, n):
      A = np.empty((n, n), P.dtype)
      A[np.triu_indices(n)] = p
      A.T[np.triu_indices(n)] = p
  
  # output matrix will be (n, n)
  n = 4
  
  # parameter vector
  P = np.arange(n * (n + 1) / 2)
  
  print make_symmetric(P, n)
  # [[ 0.  1.  2.  3.]
  #  [ 1.  4.  5.  6.]
  #  [ 2.  5.  7.  8.]
  #  [ 3.  6.  8.  9.]]    
  </code></pre>
  
  <p>However, since symbolic tensor variables don't support item assignment, I'm struggling to find a way to do this in Theano.</p>
  
  <p>The closest thing I could find is <code>theano.tensor.diag</code>, which allows me to construct a symbolic matrix from its diagonal:</p>
  
  <pre><code>import theano
  from theano import tensor as te
  
  P = te.dvector('P')
  D = te.diag(P)
  get_D = theano.function([P], D)
  
  print get_D(np.arange(1, 5))
  # [[ 1.  0.  0.  0.]
  #  [ 0.  2.  0.  0.]
  #  [ 0.  0.  3.  0.]
  #  [ 0.  0.  0.  4.]]
  </code></pre>
  
  <p>Whilst there is also a <code>theano.tensor.triu</code> function, this cannot be used to construct a matrix from the upper triangle, but rather returns a copy of an array with the lower triangular elements zeroed.</p>
  
  <p>Is there any way to construct a Theano symbolic matrix from its upper triangle?</p>