コード例 #1
0
ファイル: convert.hpp プロジェクト: Joe-Friedman/adcomp
SEXP asSEXP(const vector<Type> &a)
{
   int size = a.size();
   SEXP val;
   PROTECT(val = allocVector(VECSXP, size));
   for (int i = 0; i < size; i++) SET_VECTOR_ELT(val, i, asSEXP(a[i]));
   UNPROTECT(1);
   return val;
}
コード例 #2
0
ファイル: tree.hpp プロジェクト: calbertsen/covafillr
  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;
  }
コード例 #3
0
ファイル: fill.hpp プロジェクト: calbertsen/covafillr
  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;
  }
コード例 #4
0
ファイル: fill.hpp プロジェクト: calbertsen/covafillr
 SEXP setFillBandwith(SEXP sp, SEXP h){
   
   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(LENGTH(h) == 1){
     ptr->setH(asDouble(h));
   }else{
     ptr->setH(asVector(h));
   }
   int res = 1;
   return asSEXP(res);
 }
コード例 #5
0
ファイル: fill.hpp プロジェクト: calbertsen/covafillr
  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;
  }
コード例 #6
0
ファイル: fill.hpp プロジェクト: calbertsen/covafillr
  SEXP lnoResiduals(SEXP sp, SEXP excludeRadius){
    if(!(isNumeric(excludeRadius) && LENGTH(excludeRadius) == 1))
      Rf_error("Exclude radius must be a scalar");
    if(R_ExternalPtrTag(sp) != install("covafillPointer"))
      Rf_error("The pointer must be to a covafill object");
    covafill<double>* ptr=(covafill<double>*)R_ExternalPtrAddr(sp);

    double er = asDouble(excludeRadius);
    MatrixXd x0 = ptr->coordinates;
    vector y0 = ptr->observations;
    vector res(y0.size());

    for(int i = 0; i < x0.rows(); ++i)
      res.row(i) = ptr->operator()((vector)x0.row(i),er) - y0(i);

    return asSEXP(res);
  }
コード例 #7
0
ファイル: stepbearing.hpp プロジェクト: calbertsen/argosTrack
 SEXP bearing(SEXP x0, SEXP y0, SEXP x1, SEXP y1, SEXP nautical){
   return asSEXP(bearing(asDouble(x0),asDouble(y0),asDouble(x1),asDouble(y1),asBool(nautical)));
 }
コード例 #8
0
ファイル: stepbearing.hpp プロジェクト: calbertsen/argosTrack
 SEXP stepLength(SEXP x0, SEXP y0, SEXP x1, SEXP y1, SEXP nautical){
   return asSEXP(stepLength(asDouble(x0),asDouble(y0),asDouble(x1),asDouble(y1),asBool(nautical)));
 }
コード例 #9
0
ファイル: tree.hpp プロジェクト: calbertsen/covafillr
 SEXP getTreeDim(SEXP sp){
   if(R_ExternalPtrTag(sp) != install("covatreePointer"))
     Rf_error("The pointer must be to a covatree object");
   covatree<double>* ptr=(covatree<double>*)R_ExternalPtrAddr(sp);
   return(asSEXP(ptr->getDim()));
 }
コード例 #10
0
ファイル: fill.hpp プロジェクト: calbertsen/covafillr
 SEXP getFillBandwith(SEXP sp){
   if(R_ExternalPtrTag(sp) != install("covafillPointer"))
     Rf_error("The pointer must be to a covafill object");   
   covafill<double>* ptr=(covafill<double>*)R_ExternalPtrAddr(sp);
   return asSEXP(ptr->h);
 }