SparseOptimizerIncremental::~SparseOptimizerIncremental() { _updateMat.clear(true); delete _cholmodSparse; if (_cholmodFactor) { cholmod_free_factor(&_cholmodFactor, &_cholmodCommon); _cholmodFactor = 0; } cholmod_free_triplet(&_permutedUpdate, &_cholmodCommon); cholmod_finish(&_cholmodCommon); }
double GaussianProcessInterpolationRestraintSparse::unprotected_evaluate( DerivativeAccumulator *accum) const { //check if the functions have changed const_cast<GaussianProcessInterpolationRestraintSparse*>(this)-> update_mean_and_covariance(); double ene = mvn_->evaluate(); if (accum) { cholmod_dense *dmv = mvn_->evaluate_derivative_FM(); if (dmv->xtype != CHOLMOD_REAL) IMP_THROW("matrix type is not real, update code here first", ModelException); double *dmvx=(double*) dmv->x; //derivatives for mean particles for (size_t i=0; i<M_; i++) { DerivativeAccumulator a(*accum, dmvx[i]); gpi_->mean_function_->add_to_derivatives(gpi_->x_[i], a); } cholmod_free_dense(&dmv, c_); //derivatives for covariance particles cholmod_sparse *tmp(mvn_->evaluate_derivative_Sigma()); cholmod_triplet *dmvS = cholmod_sparse_to_triplet(tmp, c_); cholmod_free_sparse(&tmp, c_); if ((dmvS->itype != CHOLMOD_INT) && (dmvS->xtype != CHOLMOD_REAL)) IMP_THROW("matrix type is not real or coefficients are not int!", ModelException); int *dmvi=(int*) dmvS->i; int *dmvj=(int*) dmvS->j; dmvx=(double*) dmvS->x; for (size_t p=0; p<dmvS->nzmax; ++p) { int i=dmvi[p]; int j=dmvj[p]; double val=dmvx[p]; DerivativeAccumulator a(*accum, val); gpi_->covariance_function_->add_to_derivatives( gpi_->x_[i],gpi_->x_[j], a); } cholmod_free_triplet(&dmvS,c_); } return ene; }
// doing cholesky decomposition void Algebra::CK_decomp(Matrix &A, cholmod_factor *&L, cholmod_common *cm, size_t &peak_mem, size_t & CK_mem){ // doing factorization first cholmod_triplet * T; size_t n_row = A.get_row(); size_t n_col = A.get_row(); size_t nnz = A.size(); int *Ti; int *Tj; double *Tx; int stype = -1;// lower triangular storage T = cholmod_allocate_triplet(n_row, n_col, nnz, stype, CHOLMOD_REAL, cm); Ti = static_cast<int *>(T->i); Tj = static_cast<int *>(T->j); Tx = static_cast<double *>(T->x); // copy data into T for(size_t k=0;k<nnz;k++){ Ti[k] = A.Ti[k]; Tj[k] = A.Tj[k]; Tx[k] = A.Tx[k]; } T->nnz = nnz; A.Ti.clear(); A.Tj.clear(); A.Tx.clear(); cholmod_sparse * A_cholmod; A_cholmod = cholmod_triplet_to_sparse(T, nnz, cm); // free the triplet pointer cholmod_free_triplet(&T, cm); //cm->supernodal = -1; L = cholmod_analyze(A_cholmod, cm); //L->ordering = CHOLMOD_NATURAL; cholmod_factorize(A_cholmod, L, cm); //cholmod_print_factor(L, "L", cm); //if(peak_mem < cm->memory_usage) //peak_mem = cm->memory_usage; //CK_mem += cm->lnz; cholmod_free_sparse(&A_cholmod, cm); }