[Rcpp-commits] r725 - pkg/RcppArmadillo/src
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Feb 17 16:13:36 CET 2010
Author: romain
Date: 2010-02-17 16:13:36 +0100 (Wed, 17 Feb 2010)
New Revision: 725
Modified:
pkg/RcppArmadillo/src/RcppArmadillo.h
Log:
simplify wrap using memptr()
Modified: pkg/RcppArmadillo/src/RcppArmadillo.h
===================================================================
--- pkg/RcppArmadillo/src/RcppArmadillo.h 2010-02-17 14:11:51 UTC (rev 724)
+++ pkg/RcppArmadillo/src/RcppArmadillo.h 2010-02-17 15:13:36 UTC (rev 725)
@@ -38,6 +38,7 @@
#ifdef HAS_CUBE
template <typename T> SEXP wrap ( const arma::Cube<T>& ) ;
#endif
+
RCPPARMA_FORWARD(int)
RCPPARMA_FORWARD(double)
RCPPARMA_FORWARD(float)
@@ -57,83 +58,32 @@
namespace Rcpp{
namespace RcppArmadillo{
-/* needs cast : float, unsigned int */
-template <typename T> SEXP wrap_Mat__dispatch( const arma::Mat<T>& mat, ::Rcpp::traits::true_type ){
- ::Rcpp::SimpleVector< ::Rcpp::traits::r_sexptype_traits<T>::rtype > vec(
- ::Rcpp::Dimension( mat.n_rows, mat.n_cols ) );
- typedef typename ::Rcpp::traits::storage_type< ::Rcpp::traits::r_sexptype_traits<T>::rtype >::type STORAGE_TYPE ;
- int n = mat.n_elem ;
- RCPPARMA_COPY_CAST(mat,vec,n,STORAGE_TYPE);
- return vec ;
+template <typename T>
+SEXP arma_wrap( const T& object, const ::Rcpp::Dimension& dim){
+ ::Rcpp::RObject x = ::Rcpp::wrap( object.memptr() , object.memptr() + object.n_elem ) ;
+ x.attr( "dim" ) = dim ;
+ return x;
}
-/* no cast : double, int */
-template <typename T> SEXP wrap_Mat__dispatch( const arma::Mat<T>& mat, ::Rcpp::traits::false_type ){
- ::Rcpp::SimpleVector< ::Rcpp::traits::r_sexptype_traits<T>::rtype > vec(
- ::Rcpp::Dimension( mat.n_rows, mat.n_cols ) );
- int n = mat.n_elem ;
- RCPPARMA_COPY(mat,vec,n) ;
- return vec ;
-}
-
-
-template <typename T> SEXP wrap_Col__dispatch( const arma::Col<T>& column, ::Rcpp::traits::true_type ){
- int n = column.n_rows ;
- ::Rcpp::SimpleVector< ::Rcpp::traits::r_sexptype_traits<T>::rtype > vec(
- ::Rcpp::Dimension( n, 1 ) );
- typedef typename ::Rcpp::traits::storage_type< ::Rcpp::traits::r_sexptype_traits<T>::rtype >::type STORAGE_TYPE ;
- RCPPARMA_COPY_CAST(column,vec,n,STORAGE_TYPE) ;
- return vec ;
-}
-
-template <typename T> SEXP wrap_Col__dispatch( const arma::Col<T>& column, ::Rcpp::traits::false_type ){
- int n = column.n_rows ;
- ::Rcpp::SimpleVector< ::Rcpp::traits::r_sexptype_traits<T>::rtype > vec(
- ::Rcpp::Dimension( n, 1 ) );
- RCPPARMA_COPY(column,vec,n) ;
- return vec ;
-}
-
-template <typename T> SEXP wrap_Row__dispatch( const arma::Row<T>& row, ::Rcpp::traits::true_type){
- int n = row.n_cols ;
- ::Rcpp::SimpleVector< ::Rcpp::traits::r_sexptype_traits<T>::rtype > vec(
- ::Rcpp::Dimension( 1, n ) );
- typedef typename ::Rcpp::traits::storage_type< ::Rcpp::traits::r_sexptype_traits<T>::rtype >::type STORAGE_TYPE ;
- RCPPARMA_COPY_CAST(row,vec,n,STORAGE_TYPE) ;
- return vec ;
-}
-
-template <typename T> SEXP wrap_Row__dispatch( const arma::Row<T>& row, ::Rcpp::traits::false_type){
- int n = row.n_cols ;
- ::Rcpp::SimpleVector< ::Rcpp::traits::r_sexptype_traits<T>::rtype > vec(
- ::Rcpp::Dimension( 1, n ) );
- RCPPARMA_COPY(row,vec,n) ;
- return vec ;
-}
-
} /* namespace RcppArmadillo */
/* wrap */
-template <typename T> SEXP wrap ( const arma::Mat<T>& mat ){
- return RcppArmadillo::wrap_Mat__dispatch( mat, typename ::Rcpp::traits::r_sexptype_needscast<T>() ) ;
+template <typename T> SEXP wrap ( const arma::Mat<T>& data ){
+ return RcppArmadillo::arma_wrap( data, Dimension( data.n_rows, data.n_cols ) ) ;
} ;
-template <typename T> SEXP wrap( const arma::Col<T>& column ){
- return RcppArmadillo::wrap_Col__dispatch( column, typename ::Rcpp::traits::r_sexptype_needscast<T>() ) ;
-}
+template <typename T> SEXP wrap( const arma::Col<T>& data ){
+ return RcppArmadillo::arma_wrap( data, Dimension( data.n_elem, 1) ) ;
+} ;
-template <typename T> SEXP wrap( const arma::Row<T>& row ){
- return RcppArmadillo::wrap_Row__dispatch( row, typename ::Rcpp::traits::r_sexptype_needscast<T>() ) ;
-}
+template <typename T> SEXP wrap( const arma::Row<T>& data ){
+ return RcppArmadillo::arma_wrap(data, Dimension( 1, data.n_elem ) ) ;
+} ;
#ifdef HAS_CUBE
template <typename T> SEXP wrap( const arma::Cube<T>& cube ){
- int n = cube.n_elem;
- SimpleVector< traits::r_sexptype_traits<T>::rtype > vec(
- Dimension( cube.n_rows, cube.n_cols, cube.n_slices ) );
- RCPPARMA_COPY(cube,vec,n);
- return vec ;
+ return RcppArmadillo::arma_wrap(data, Dimension( data.n_rows, data.n_cols, data.n_slices ) ) ;
}
#endif
More information about the Rcpp-commits
mailing list