diff --git a/src/tools/Tensor.h b/src/tools/Tensor.h index 13fd5a80cc..a4f53c8a9b 100644 --- a/src/tools/Tensor.h +++ b/src/tools/Tensor.h @@ -535,6 +535,10 @@ void diagMatSym(const TensorGeneric&mat,VectorGeneric&evals,TensorGeneri std::array iwork; std::array work; std::array isup; + // documentation says that "matrix is destroyed" !!! + auto mat_copy=mat; + // documentation says this is size n (even if m evals_tmp; int nn=n; // dimension of matrix double vl=0.0, vu=1.0; // ranges - not used int one=1,mm=m; // minimum and maximum index @@ -543,13 +547,14 @@ void diagMatSym(const TensorGeneric&mat,VectorGeneric&evals,TensorGeneri int info=0; // result int liwork=iwork.size(); int lwork=work.size(); - TensorGenericAux::local_dsyevr("V", (n==m?"A":"I"), "U", &nn, const_cast(&mat[0][0]), &nn, &vl, &vu, &one, &mm, - &abstol, &mout, &evals[0], &evec[0][0], &nn, + TensorGenericAux::local_dsyevr("V", (n==m?"A":"I"), "U", &nn, const_cast(&mat_copy[0][0]), &nn, &vl, &vu, &one, &mm, + &abstol, &mout, &evals_tmp[0], &evec[0][0], &nn, isup.data(), work.data(), &lwork, iwork.data(), &liwork, &info); if(info!=0) plumed_error()<<"Error diagonalizing matrix\n" <<"Matrix:\n"<