Could you try casting matrix into theano? Seems there is a memory error when theano is trying to do that internally.
matrix