Re: [Rcpp-devel] Not able to convert from Rcpp::NumericVector to Teuchos::ArrayRCP

2014-05-22 Thread Romain François
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 will not be useful as it tries to use the constructor taking a SEXP 
: 

template 
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  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  class Exporter<  Teuchos::ArrayRCP > : public 
RangeExporter< Teuchos::ArrayRCP >{
  public:
Exporter( SEXP x) : RangeExporter< Teuchos::ArrayRCP >(x){}  
  }

}
}


Romain

Le 23 mai 2014 à 00:42, Chaomei Lo  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 col_counts = Rcpp::as 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 in the following line, it gave me errors as shown 
> below in red.  Would you please help me with this ?
>  
> Teuchos::ArrayRCP 
> col_counts=Rcpp::as>(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::Exporter(SEXP) [with T = 
> Teuchos::Array
> RCP, 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, 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 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::ArrayRC
> P(Teuchos::ArrayRCP::size_type, const T&) [with T = long unsigned int, 
> Teuchos::ArrayRCP::size_type = long int]' [-fpermissive]
> make: *** [buildMatrix.o] Error 1
> ERROR: compilation failed for package 'Tpkg'
> ___
> Rcpp-devel mailing list
> Rcpp-devel@lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

___
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

Re: [Rcpp-devel] file name changed in package

2014-05-22 Thread Dirk Eddelbuettel

On 22 May 2014 at 15:38, Chaomei Lo wrote:
| Hi, Dirk,
|  
| 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 col_counts = Rcpp::as>
| (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
|  in the following line, it gave me errors as shown below in red.  
Would
| you please help me with this ?
|  
| Teuchos::ArrayRCP col_counts=Rcpp::as>
| (col_cts);

"There is a vignette for that":  Rcpp-extending, which describes how to
create as<>() and wrap() for your chosen library.

There are examples in existing packages such as RcppArmadillo, RcppBDT and
more.  There are examples on the Rcpp Gallery.

Dirk

-- 
Dirk Eddelbuettel | e...@debian.org | http://dirk.eddelbuettel.com
___
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel


[Rcpp-devel] Not able to convert from Rcpp::NumericVector to Teuchos::ArrayRCP

2014-05-22 Thread Chaomei Lo
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
col_counts = Rcpp::as>(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 in the following line, it gave me errors as shown
below in red.  Would you please help me with this ?

*Teuchos::ArrayRCP
col_counts=Rcpp::as>(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::Exporter(SEXP) [with T =
Teuchos::Array
RCP, 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, 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, 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::ArrayRC
P(Teuchos::ArrayRCP::size_type, const T&) [with T = long unsigned int,
Teuchos::ArrayRCP::size_type = long int]' [-fpermissive]
make: *** [buildMatrix.o] Error 1
ERROR: compilation failed for package 'Tpkg'
___
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

[Rcpp-devel] file name changed in package

2014-05-22 Thread Chaomei Lo
Hi, Dirk,

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
col_counts = Rcpp::as>(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 in the following line, it gave me errors as shown
below in red.  Would you please help me with this ?

*Teuchos::ArrayRCP
col_counts=Rcpp::as>(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::Exporter(SEXP) [with T =
Teuchos::Array
RCP, 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, 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, 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::ArrayRC
P(Teuchos::ArrayRCP::size_type, const T&) [with T = long unsigned int,
Teuchos::ArrayRCP::size_type = long int]' [-fpermissive]
make: *** [buildMatrix.o] Error 1
ERROR: compilation failed for package 'Tpkg'
___
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel