// [[Rcpp::export]] MatrixXd shuffleMatrix(const MatrixXd X, const IntegerVector prm) { // TODO: test that prm is zero-based const int n(X.rows()); const int m(X.cols()); MatrixXd Xout(n,m); for(int i = 0; i < n; ++i) { for(int j = 0; j < m; ++j) { Xout(i,j) = X(prm[i],j); } } return Xout; }
static PetscErrorCode bfgs_apply(PC pc, Vec xin, Vec xout) { TaoLMVMMat *M ; TaoVecPetsc Xin(xin); TaoVecPetsc Xout(xout); TaoTruth info2; int info; PetscFunctionBegin; PetscTruth VerbosePrint = PETSC_FALSE; PetscOptionsGetTruth(PETSC_NULL,"-verboseapp",&VerbosePrint,PETSC_NULL); info = PCShellGetContext(pc,(void**)&M); CHKERRQ(info); PetscScalar solnNorm,solnDot; info = VecNorm(xin,NORM_2,&solnNorm); CHKERRQ(info) info=PetscPrintf(PETSC_COMM_WORLD,"bfgs_apply: ||Xin||_2 = %22.15e\n",solnNorm); if(VerbosePrint) VecView(xin,0); info = M->Solve(&Xin, &Xout, &info2); CHKERRQ(info); info = VecNorm(xout,NORM_2,&solnNorm); CHKERRQ(info) info = VecDot(xin,xout,&solnDot); CHKERRQ(info) info=PetscPrintf(PETSC_COMM_WORLD,"bfgs_apply: ||Xout||_2 = %22.15e, Xin^T Xout= %22.15e\n",solnNorm,solnDot); if(VerbosePrint) VecView(xout,0); PetscFunctionReturn(0); }