added dumping of matrices and gradients