Hi, Romain, Your suggestion works pretty well. I appreciate your valuable help !
Chaomei On Thu, May 22, 2014 at 4:18 PM, Romain François <[email protected]>wrote: > Hello, > > From what I understand of ArrayRCP, having read the documentation for a > few minutes. ( > http://trilinos.sandia.gov/packages/docs/r9.0/packages/teuchos/doc/html/classTeuchos_1_1ArrayRCP.html > ) > This looks like a vector and therefore it is likely that the default > Exporter<T> will not be useful as it tries to use the constructor taking a > SEXP : > > template <typename T> > class Exporter{ > public: > Exporter( SEXP x ) : t(x){} > inline T get(){ return t ; } > > private: > T t ; > } ; > > you can use a RangeExporter instead which looks more compatible to what > ArrayRCP looks like: > > template <typename T> class RangeExporter { > public: > typedef typename T::value_type r_export_type ; > > RangeExporter( SEXP x ) : object(x){} > ~RangeExporter(){} > > T get(){ > T vec( ::Rf_length(object) ); > ::Rcpp::internal::export_range( object, vec.begin() ) ; > return vec ; > } > > private: > SEXP object ; > } ; > > > You can probably do this by having something like this early enough (after > RcppCommon.h but before Rcpp.h). > > namespace Rcpp { > namespace traits { > > template <typename T> class Exporter< Teuchos::ArrayRCP<T> > : public > RangeExporter< Teuchos::ArrayRCP<T> >{ > public: > Exporter( SEXP x) : RangeExporter< Teuchos::ArrayRCP<T> >(x){} > } > > } > } > > > Romain > > Le 23 mai 2014 à 00:42, Chaomei Lo <[email protected]> a écrit : > > Sorry to confuse you, Dirk, I had my previous message title wrong. Here > below was the message with the correct title and content. > > //////////////////////////////// > I have created R packages using Makevars and it works pretty good for me. > I am able to convert from a Rcpp::NumericVector to std::vector as in below. > > > > > *NumericVector col_cts = buildMatrix(Xr);vector<long unsigned int> > col_counts = Rcpp::as<vector<long unsigned int>>(col_cts); * > Now I am having a problem with an application involves the Trilinos > library. Here below I am trying to convert a Rcpp::NumericVector to > Teuchos::ArrayRCP<size_t> in the following line, it gave me errors as shown > below in red. Would you please help me with this ? > > *Teuchos::ArrayRCP<size_t> > col_counts=Rcpp::as<Teuchos::ArrayRCP<size_t>>(col_cts);* > > Thanks a lot. > > In file included from > /share/apps/R/3.0.2/lib64/R/library/Rcpp/include/Rcpp/as.h:25:0, > from > /share/apps/R/3.0.2/lib64/R/library/Rcpp/include/RcppCommon.h:169, > from > /share/apps/R/3.0.2/lib64/R/library/Rcpp/include/Rcpp.h:27, > from buildMatrix.cpp:4: > /share/apps/R/3.0.2/lib64/R/library/Rcpp/include/Rcpp/internal/Exporter.h: > In constructor 'Rcpp::traits::Exporter<T>::Exporter(SEXP) [with T = > Teuchos::Array > RCP<long unsigned int>, SEXP = SEXPREC*]': > /share/apps/R/3.0.2/lib64/R/library/Rcpp/include/Rcpp/as.h:79:51: > instantiated from 'T Rcpp::internal::as(SEXP, > Rcpp::traits::r_type_generic_tag) [with T = > Teuchos::ArrayRCP<long unsigned int>, SEXP = SEXPREC*]' > /share/apps/R/3.0.2/lib64/R/library/Rcpp/include/Rcpp/as.h:144:84: > instantiated from 'T Rcpp::as(SEXP) [with T = Teuchos::ArrayRCP<long > unsigned int>, SEXP > = SEXPREC*]' > buildMatrix.cpp:84:87: instantiated from here > /share/apps/R/3.0.2/lib64/R/library/Rcpp/include/Rcpp/internal/Exporter.h:31:31: > error: invalid conversion from 'SEXP' to 'long int' [-fpermissive] > /people/d3j508/trilinos-11.6.1/trilinos-11.6.1_Install/include/Teuchos_ArrayRCP.hpp:129:1: > error: initializing argument 1 of 'Teuchos::ArrayRCP<T>::ArrayRC > P(Teuchos::ArrayRCP<T>::size_type, const T&) [with T = long unsigned int, > Teuchos::ArrayRCP<T>::size_type = long int]' [-fpermissive] > make: *** [buildMatrix.o] Error 1 > ERROR: compilation failed for package 'Tpkg' > _______________________________________________ > Rcpp-devel mailing list > [email protected] > https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel > > >
_______________________________________________ Rcpp-devel mailing list [email protected] https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
