@ops.RegisterGradient('MatrixDeterminant')
def _MatrixDeterminantGrad(op, grad):
    """Gradient for MatrixDeterminant. Use formula from 2.2.4 from
  An extended collection of matrix derivative results for forward and reverse
  mode algorithmic differentiation by Mike Giles
  -- http://eprints.maths.ox.ac.uk/1079/1/NA-08-01.pdf
"""
A = op.inputs[0]
C = op.outputs[0]
Ainv = tf.matrix_inverse(A)
return grad * C * tf.transpose(Ainv)
matrix determinant differentiation in tensorflow