[Rcpp-commits] r3379 - in pkg/RcppArmadillo/inst/include: . RcppArmadillo
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Nov 17 12:14:52 CET 2011
Author: romain
Date: 2011-11-17 12:14:49 +0100 (Thu, 17 Nov 2011)
New Revision: 3379
Modified:
pkg/RcppArmadillo/inst/include/RcppArmadillo/Mat_meat.h
pkg/RcppArmadillo/inst/include/RcppArmadilloConfig.h
pkg/RcppArmadillo/inst/include/RcppArmadilloSugar.h
pkg/RcppArmadillo/inst/include/RcppArmadilloWrap.h
Log:
step 2, not over yet, but close, will finish later, gotta go
Modified: pkg/RcppArmadillo/inst/include/RcppArmadillo/Mat_meat.h
===================================================================
--- pkg/RcppArmadillo/inst/include/RcppArmadillo/Mat_meat.h 2011-11-17 10:55:59 UTC (rev 3378)
+++ pkg/RcppArmadillo/inst/include/RcppArmadillo/Mat_meat.h 2011-11-17 11:14:49 UTC (rev 3379)
@@ -61,6 +61,37 @@
+
+
+ template <typename eT, int RTYPE, bool NA, typename MATRIX>
+ inline void fill_ptr_matrix__impl( eT* ptr, const Rcpp::MatrixBase<RTYPE,NA,MATRIX>& X, int nr, int nc, ::Rcpp::traits::true_type ){
+ int k, i_col, i_row ;
+ for( i_col=0, k=0 ; i_col < nc; ++i_col){
+ for( i_row = 0; i_row < nr ; ++i_row, ++k ){
+ ptr[k] = Rcpp::internal::caster< typename Rcpp::traits::storage_type<RTYPE>::type, eT>( X(i_row,i_col)) ;
+ }
+ }
+ }
+
+ template <typename eT, int RTYPE, bool NA, typename MATRIX>
+ inline void fill_ptr_matrix__impl( eT* ptr, const Rcpp::MatrixBase<RTYPE,NA,MATRIX>& X, int nr, int nc, ::Rcpp::traits::false_type ){
+ int k, i_col, i_row ;
+ for( i_col=0, k=0 ; i_col < nc; ++i_col){
+ for( i_row = 0; i_row < nr ; ++i_row, ++k ){
+ ptr[k] = X(i_row,i_col) ;
+ }
+ }
+ }
+
+
+
+ template <typename eT, int RTYPE, bool NA, typename MATRIX>
+ inline void fill_ptr_matrix( eT* ptr, const Rcpp::MatrixBase<RTYPE,NA,MATRIX>& X, int nr, int nc){
+ return fill_ptr_matrix__impl<eT, RTYPE, NA, MATRIX>( ptr, X, nr, nc,
+ typename ::Rcpp::traits::r_sexptype_needscast<eT>()
+ ) ;
+ }
+
}
template <typename eT>
@@ -95,24 +126,13 @@
arma_extra_debug_sigprint_this(this);
- // TODO : deal with complex expressions because
- // std::complex<double> != Rcomplex
-#if !defined(ARMA_USE_CXX11)
- arma_type_check_cxx1998< is_same_type< eT, typename Rcpp::traits::storage_type<RTYPE>::type >::value == false >::apply();
-#else
- static_assert( is_same_type< eT, typename Rcpp::traits::storage_type<RTYPE>::type >::value , "error: incorrect or unsupported type" )
-#endif
-
-
- u32 nr = X.nrow(), nc = X.ncol(), i_col, i_row, k ;
+ RcppArmadillo::check<eT, typename Rcpp::traits::storage_type<RTYPE>::type >() ;
+
+ u32 nr = X.nrow(), nc = X.ncol() ;
set_size( nr, nc ) ;
- eT* ptr = memptr() ;
- for( i_col=0, k=0 ; i_col < nc; ++i_col){
- for( i_row = 0; i_row < nr ; ++i_row, ++k ){
- ptr[k] = X(i_row,i_col) ;
- }
- }
+ RcppArmadillo::fill_ptr_matrix( memptr(), nr, nc );
+
}
#endif
Modified: pkg/RcppArmadillo/inst/include/RcppArmadilloConfig.h
===================================================================
--- pkg/RcppArmadillo/inst/include/RcppArmadilloConfig.h 2011-11-17 10:55:59 UTC (rev 3378)
+++ pkg/RcppArmadillo/inst/include/RcppArmadilloConfig.h 2011-11-17 11:14:49 UTC (rev 3379)
@@ -2,7 +2,7 @@
//
// RcppArmadilloConfig.h: Rcpp/Armadillo glue
//
-// Copyright (C) 2010 Dirk Eddelbuettel, Romain Francois and Douglas Bates
+// Copyright (C) 2010-2011 Dirk Eddelbuettel, Romain Francois and Douglas Bates
//
// This file is part of RcppArmadillo.
//
Modified: pkg/RcppArmadillo/inst/include/RcppArmadilloSugar.h
===================================================================
--- pkg/RcppArmadillo/inst/include/RcppArmadilloSugar.h 2011-11-17 10:55:59 UTC (rev 3378)
+++ pkg/RcppArmadillo/inst/include/RcppArmadilloSugar.h 2011-11-17 11:14:49 UTC (rev 3379)
@@ -2,7 +2,7 @@
//
// RcppArmadilloSugar.h: Rcpp/Armadillo glue
//
-// Copyright (C) 2010 Dirk Eddelbuettel, Romain Francois and Douglas Bates
+// Copyright (C) 2010-2011 Dirk Eddelbuettel, Romain Francois and Douglas Bates
//
// This file is part of RcppArmadillo.
//
@@ -23,100 +23,13 @@
#define RcppArmadillo__RcppArmadilloSugar__h
namespace Rcpp{
-namespace RcppArmadillo{
- template <int RTYPE, bool NA, typename T>
- class r_forward {
- public:
-
- typedef typename Rcpp::traits::storage_type<RTYPE>::type T1 ;
- typedef typename Rcpp::VectorBase<RTYPE,NA,T> SUGAR ;
- typedef typename arma::Mat<T1>::iterator mat_iterator ;
-
- inline static void apply(
- arma::Mat<T1>& out,
- const arma::Op< Rcpp::VectorBase<RTYPE,NA,T> , r_forward<RTYPE,NA,T> >& in
- ){
- const SUGAR& m = in.m ;
- int n = m.size() ;
- // deal with dimensions
- out.set_size( n, 1 ) ;
- mat_iterator first = out.begin(), last = out.end();
- // perhaps we should just use std::copy
- for( int i=0; first != last ; ++i){
- *first++ = m[i];
- }
- }
- } ;
+// forward is not needed anymore, but we just leave this
+// for backwards compatibility
+template <typename T>
+inline const T& forward(const T& x) { return x; }
- template <bool NA, typename T>
- class Complex_Imposter {
- public:
- typedef typename Rcpp::VectorBase<CPLXSXP,NA,T> SUGAR_EXP ;
- typedef std::complex<double> elem_type ;
-
- Complex_Imposter( const SUGAR_EXP& vec_) : vec(vec_){}
- inline int size() const { return vec.size() ; }
- inline std::complex<double> operator[]( int i ) const {
- Rcomplex x = vec[i] ;
- return std::complex<double>( x.r, x.i ) ;
- }
-
- private:
- const SUGAR_EXP& vec ;
- } ;
-
-
- template <bool NA, typename T>
- class r_complex_forward {
- public:
- typedef std::complex<double> T1 ;
- typedef Complex_Imposter<NA,T> SUGAR ;
- typedef arma::Mat<T1>::iterator mat_iterator ;
-
- inline static void apply(
- arma::Mat<T1>& out,
- const arma::Op< Complex_Imposter<NA,T> , r_complex_forward<NA,T> >& in
- ){
- const SUGAR& m = in.m ;
- int n = m.size() ;
- // deal with dimensions
- out.set_size( n, 1 ) ;
- mat_iterator first = out.begin(), last = out.end();
- for( int i=0; first != last ; ++i){
- *first++ = m[i] ;
- }
- }
-
- } ;
-
-}
-
-
-template <int RTYPE, bool NA, typename T>
-inline arma::Op<
- VectorBase<RTYPE,NA,T> ,
- RcppArmadillo::r_forward<RTYPE,NA,T>
->
-forward( const VectorBase<RTYPE,NA,T>& x ) {
- return arma::Op< VectorBase<RTYPE,NA,T> , RcppArmadillo::r_forward<RTYPE,NA,T> >( x ) ;
-}
-
-
-template <bool NA, typename T>
-inline arma::Op<
- RcppArmadillo::Complex_Imposter<NA,T> ,
- RcppArmadillo::r_complex_forward<NA,T>
->
-forward( const VectorBase<CPLXSXP,NA,T>& x ) {
- return arma::Op<
- RcppArmadillo::Complex_Imposter<NA,T> ,
- RcppArmadillo::r_complex_forward<NA,T> >( x ) ;
-}
-
-
-
} // Rcpp
#endif
Modified: pkg/RcppArmadillo/inst/include/RcppArmadilloWrap.h
===================================================================
--- pkg/RcppArmadillo/inst/include/RcppArmadilloWrap.h 2011-11-17 10:55:59 UTC (rev 3378)
+++ pkg/RcppArmadillo/inst/include/RcppArmadilloWrap.h 2011-11-17 11:14:49 UTC (rev 3379)
@@ -2,7 +2,7 @@
//
// RcppArmadilloWrap.h: Rcpp/Armadillo glue
//
-// Copyright (C) 2010 Dirk Eddelbuettel, Romain Francois and Douglas Bates
+// Copyright (C) 2010-2011 Dirk Eddelbuettel, Romain Francois and Douglas Bates
//
// This file is part of RcppArmadillo.
//
More information about the Rcpp-commits
mailing list