SEXP MakeFill(SEXP coord,SEXP obs,SEXP h,SEXP p){ covafill<double>* cfp = new covafill<double>(asMatrix(coord), asVector(obs), asVector(h), asInteger(p)); if(cfp == NULL){ return R_NilValue; } SEXP val = R_MakeExternalPtr(cfp, install("covafillPointer"), R_NilValue); return val; }
SEXP MakeTree(SEXP coord,SEXP obs,SEXP h,SEXP p, SEXP d){ covafill<double>* cfp = new covafill<double>(asMatrix(coord), asVector(obs), asVector(h), asInteger(p)); covatree<double>* ctp = new covatree<double>(asDouble(d),cfp); if(ctp == NULL){ return R_NilValue; } SEXP val = R_MakeExternalPtr(ctp, install("covatreePointer"), R_NilValue); return val; }
SEXP predictTree(SEXP sp, SEXP x){ if(R_ExternalPtrTag(sp) != install("covatreePointer")) Rf_error("The pointer must be to a covatree object"); covatree<double>* ptr=(covatree<double>*)R_ExternalPtrAddr(sp); int dim = ptr->getDim(); if(isMatrix(x)){ MatrixXd res(nrows(x),1 + dim); MatrixXd x0 = asMatrix(x); for(int i = 0; i < nrows(x); ++i) res.row(i) = ptr->operator()((vector)x0.row(i)); return asSEXP(res); }else if(isNumeric(x)){ return asSEXP(ptr->operator()(asVector(x))); }else{ Rf_error("Element must be a matrix or numeric vector"); } return R_NilValue; }
SEXP predictFillSE(SEXP sp, SEXP x){ if(R_ExternalPtrTag(sp) != install("covafillPointer")) Rf_error("The pointer must be to a covafill object"); covafill<double>* ptr=(covafill<double>*)R_ExternalPtrAddr(sp); if(isMatrix(x)){ MatrixXd x0 = asMatrix(x); int lsdim = 1 + ptr->getDim(); if(ptr->p >= 2) lsdim += 0.5 * ptr->getDim() * (ptr->getDim() + 1); if(ptr->p >= 3) lsdim += (ptr->p - 2) * ptr->getDim(); MatrixXd res(nrows(x),lsdim); MatrixXd resSE(nrows(x),lsdim); Array<Array<double,Dynamic,1>, Dynamic,1> tmp(2); for(int i = 0; i < nrows(x); ++i){ tmp = ptr->operator()((vector)x0.row(i),0, true); res.row(i) = tmp(0); resSE.row(i) = tmp(1); } SEXP vecOut = PROTECT(allocVector(VECSXP, 2)); SEXP sr1 = PROTECT(asSEXP(res)); SEXP sr2 = PROTECT(asSEXP(resSE)); SET_VECTOR_ELT(vecOut,0,sr1); SET_VECTOR_ELT(vecOut,1,sr2); UNPROTECT(3); return vecOut; }else{ error("Element must be a matrix or numeric vector"); } return R_NilValue; }
SEXP predictFill(SEXP sp, SEXP x){ if(R_ExternalPtrTag(sp) != install("covafillPointer")) Rf_error("The pointer must be to a covafill object"); covafill<double>* ptr=(covafill<double>*)R_ExternalPtrAddr(sp); if(isMatrix(x)){ int lsdim = 1 + ptr->getDim(); if(ptr->p >= 2) lsdim += 0.5 * ptr->getDim() * (ptr->getDim() + 1); if(ptr->p >= 3) lsdim += (ptr->p - 2) * ptr->getDim(); MatrixXd res(nrows(x),lsdim); MatrixXd x0 = asMatrix(x); for(int i = 0; i < nrows(x); ++i) res.row(i) = ptr->operator()((vector)x0.row(i), true); return asSEXP(res); }else if(isNumeric(x)){ return asSEXP(ptr->operator()(asVector(x), true)); }else{ error("Element must be a matrix or numeric vector"); } return R_NilValue; }
virtual CVector3D<TReal> Apply(CVector3D<TReal> vp) { CVector3D<TReal> tmp; tmp = (vp * asMatrix()); return tmp; };
void DiscreteBoundaryOperator<ValueType>::dump() const { std::cout << asMatrix() << std::endl; }