bool DenseGenMatrix::ComputeEigenVectors(const DenseSymMatrix& M, DenseVector& Evalues) { Index dim = M.Dim(); DBG_ASSERT(Evalues.Dim()==dim); DBG_ASSERT(NRows()==dim); DBG_ASSERT(NCols()==dim); // First we copy the content of the matrix into Q const Number* Mvalues = M.Values(); for (Index j=0; j<dim; j++) { for (Index i=j; i<dim; i++) { values_[i+j*dim] = Mvalues[i+j*dim]; } } bool compute_eigenvectors = true; Number* Evals = Evalues.Values(); Index info; IpLapackDsyev(compute_eigenvectors, dim, values_, dim, Evals, info); initialized_ = (info==0); ObjectChanged(); return (info==0); }
void DenseSymMatrix::AddMatrix(Number alpha, const DenseSymMatrix& A, Number beta) { DBG_ASSERT(beta==0. || initialized_); DBG_ASSERT(Dim()==A.Dim()); if (alpha==0.) return; const Number* Avalues = A.Values(); const Index dim = Dim(); if (beta==0.) { for (Index j=0; j<dim; j++) { for (Index i=j; i<dim; i++) { values_[i+j*dim] = alpha*Avalues[i+j*dim]; } } } else if (beta==1.) { for (Index j=0; j<dim; j++) { for (Index i=j; i<dim; i++) { values_[i+j*dim] += alpha*Avalues[i+j*dim]; } } } else { for (Index j=0; j<dim; j++) { for (Index i=j; i<dim; i++) { values_[i+j*dim] = alpha*Avalues[i+j*dim] + beta*values_[i+j*dim]; } } } ObjectChanged(); initialized_ = true; }
bool DenseGenMatrix::ComputeCholeskyFactor(const DenseSymMatrix& M) { Index dim = M.Dim(); DBG_ASSERT(dim==NCols()); DBG_ASSERT(dim==NRows()); ObjectChanged(); // First we copy the content of the symmetric matrix into J const Number* Mvalues = M.Values(); for (Index j=0; j<dim; j++) { for (Index i=j; i<dim; i++) { values_[i+j*dim] = Mvalues[i+j*dim]; } } // Now call the lapack subroutine to perform the factorization Index info; IpLapackDpotrf(dim, values_, dim, info); DBG_ASSERT(info>=0); if (info!=0) { initialized_ = false; return false; } // We set all strictly upper values to zero // ToDo: This might not be necessary?!? for (Index j=1; j<dim; j++) { for (Index i=0; i<j; i++) { values_[i+j*dim] = 0.; } } factorization_ = CHOL; initialized_ = true; return true; }