Use DenseMatrix.copy instead of loops