I looked, and numpy.triu and numpy.tril are implemented in Theano in theano.tensor.tri[lu]. Is there a reason not to make the graph a Theano graph of the existing ops? This would allow merging of partial computation with other part of the graph.