Exemplo n.º 1
0
template<> SEXP getHistory<arma::vec>(cppbugs::MCMCObject* node) {
    //SEXP ans;
    cppbugs::MCMCSpecialized<arma::vec>* sp = dynamic_cast<cppbugs::MCMCSpecialized<arma::vec>*>(node);
    if(sp == NULL) {
        throw std::logic_error("invalid node conversion.");
    }

    if(sp->history.size()==0) {
        return R_NilValue;
    }

    //Rprintf("getHistory<arma::vec> history.size(): %d\n",sp->history.size());
    const size_t NC = sp->history.begin()->n_elem;
    //Rprintf("getHistory<arma::vec> history dim: %d\n",NC);
    Rcpp::NumericMatrix ans(sp->history.size(),NC);
    R_len_t i = 0;
    for(typename std::list<arma::vec>::const_iterator it = sp->history.begin(); it != sp->history.end(); it++) {
        for(size_t j = 0; j < NC; j++) {
            ans(i,j) = it->at(j);
        }
        ++i;
    }
    //UNPROTECT(1);
    return Rcpp::wrap(ans);
}
Exemplo n.º 2
0
SEXP getHistory(cppbugs::MCMCObject* node) {
    //SEXP ans;
    cppbugs::MCMCSpecialized<T>* sp = dynamic_cast<cppbugs::MCMCSpecialized<T>*>(node);
    if(sp == NULL) {
        throw std::logic_error("invalid node conversion.");
    }
    //Rprintf("getHistory<T> history.size(): %d\n",sp->history.size());
    //PROTECT(ans = Rf_allocVector(VECSXP, sp->history.size()));
    //Rcpp::List ans(sp->history.size());
    //const size_t NC = sp->history.begin()->n_elem;
    const size_t NC = sp->history.begin()->n_cols;
    Rcpp::NumericMatrix ans(sp->history.size(),NC);
    R_len_t i = 0;
    for(typename std::list<T>::const_iterator it = sp->history.begin(); it != sp->history.end(); it++) {
        //SET_VECTOR_ELT(ans, i, Rcpp::wrap(*it)); ++i;
        //ans[i] = Rcpp::wrap(*it);
        //Rprintf("%d %d",i, it->n_cols);
        for(size_t j = 0; j < NC; j++) {
            ans(i,j) = it->at(j);
        }
        ++i;
    }
    //UNPROTECT(1);
    return Rcpp::wrap(ans);
}