diff --git a/mat.cc b/mat.cc index 98e6757..013f89c 100644 --- a/mat.cc +++ b/mat.cc @@ -1167,7 +1167,80 @@ for (int i=0; i< nn; i++) v[i][i] = r[i]; #endif } +template<> +void NRMat::orthonormalize(const bool rowcol, const NRSMat *metric) //modified Gram-Schmidt +{ +if(metric) //general metric +{ +if(rowcol) //vectors are rows + { + if((*metric).nrows() != mm) laerror("incompatible metric in orthonormalize"); + for(int j=0; j tmp = *metric * (*this).row(i); + double fact = cblas_ddot(mm,(*this)[j],1,tmp,1); + cblas_daxpy(mm,-fact,(*this)[i],1,(*this)[j],1); + } + NRVec tmp = *metric * (*this).row(j); + double norm = cblas_ddot(mm,(*this)[j],1,tmp,1); + if(norm<=0.) laerror("zero vector in orthonormalize or nonpositive metric"); + cblas_dscal(mm,1./sqrt(norm),(*this)[j],1); + } + } +else //vectors are columns + { + if((*metric).nrows() != nn) laerror("incompatible metric in orthonormalize"); + for(int j=0; j tmp = *metric * (*this).column(i); + double fact = cblas_ddot(nn,&(*this)[0][j],mm,tmp,1); + cblas_daxpy(nn,-fact,&(*this)[0][i],mm,&(*this)[0][j],mm); + } + NRVec tmp = *metric * (*this).column(j); + double norm = cblas_ddot(nn,&(*this)[0][j],mm,tmp,1); + if(norm<=0.) laerror("zero vector in orthonormalize or nonpositive metric"); + cblas_dscal(nn,1./sqrt(norm),&(*this)[0][j],mm); + } + } +} +else //unit metric + +{ +if(rowcol) //vectors are rows + { + for(int j=0; j; template class NRMat >; +template class NRMat; +template class NRMat; template class NRMat; template class NRMat; template class NRMat; template class NRMat; +template class NRMat; template class NRMat; template class NRMat; +template class NRMat;