[Rcpp-commits] r2040 - in pkg/RcppArmadillo/inst: include/RcppArmadillo unitTests

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Aug 18 22:14:23 CEST 2010


Author: romain
Date: 2010-08-18 22:14:23 +0200 (Wed, 18 Aug 2010)
New Revision: 2040

Modified:
   pkg/RcppArmadillo/inst/include/RcppArmadillo/Mat_meat.h
   pkg/RcppArmadillo/inst/include/RcppArmadillo/Mat_proto.h
   pkg/RcppArmadillo/inst/unitTests/runit.RcppArmadillo.R
Log:
Mat( sugar matrix expression) 

Modified: pkg/RcppArmadillo/inst/include/RcppArmadillo/Mat_meat.h
===================================================================
--- pkg/RcppArmadillo/inst/include/RcppArmadillo/Mat_meat.h	2010-08-18 19:52:45 UTC (rev 2039)
+++ pkg/RcppArmadillo/inst/include/RcppArmadillo/Mat_meat.h	2010-08-18 20:14:23 UTC (rev 2040)
@@ -38,8 +38,7 @@
 	// std::complex<double> != Rcomplex
 	isnt_same_type<eT, typename Rcpp::traits::storage_type<RTYPE>::type >::check();
   	
-	u32 n = X.size() ;
-	set_size( n, 1 ) ;
+	set_size( X.size(), 1 ) ;
 		
 	iterator first = begin(), last = end(); 
 	for( u32 i=0; first != last; ++i){
@@ -47,4 +46,31 @@
 	}
 }
 
+template <typename eT>
+template <int RTYPE, bool NA, typename MATRIX>
+inline Mat<eT>::Mat( const Rcpp::MatrixBase<RTYPE,NA,MATRIX>& X ) 
+	: n_rows( 0 )
+	, n_cols( 0 )
+	, n_elem( 0 )
+	, use_aux_mem(false)
+	, mem(mem)
+{
+	
+	arma_extra_debug_sigprint_this(this);
+	
+	// TODO : deal with complex expressions because 
+	// std::complex<double> != Rcomplex
+	isnt_same_type<eT, typename Rcpp::traits::storage_type<RTYPE>::type >::check();
+  	
+	u32 nr = X.nrow(), nc = X.ncol(), i_col, i_row ;
+	set_size( nr, nc ) ;
+		
+	iterator first = begin() ;
+	for( i_col=0; i_col < nc; ++i_col){
+		for( i_row = 0; i_row < nr ; ++i_row ){
+			*first++ = X(i_row,i_col) ;
+		}
+	}
+}
+
 #endif

Modified: pkg/RcppArmadillo/inst/include/RcppArmadillo/Mat_proto.h
===================================================================
--- pkg/RcppArmadillo/inst/include/RcppArmadillo/Mat_proto.h	2010-08-18 19:52:45 UTC (rev 2039)
+++ pkg/RcppArmadillo/inst/include/RcppArmadillo/Mat_proto.h	2010-08-18 20:14:23 UTC (rev 2040)
@@ -26,4 +26,7 @@
 template <int RTYPE, bool NA, typename VECTOR>
 inline Mat( const Rcpp::VectorBase<RTYPE,NA,VECTOR>& X ) ;
 
+template <int RTYPE, bool NA, typename VECTOR>
+inline Mat( const Rcpp::MatrixBase<RTYPE,NA,VECTOR>& X ) ;
+
 #endif

Modified: pkg/RcppArmadillo/inst/unitTests/runit.RcppArmadillo.R
===================================================================
--- pkg/RcppArmadillo/inst/unitTests/runit.RcppArmadillo.R	2010-08-18 19:52:45 UTC (rev 2039)
+++ pkg/RcppArmadillo/inst/unitTests/runit.RcppArmadillo.R	2010-08-18 20:14:23 UTC (rev 2040)
@@ -283,3 +283,18 @@
 	
 }
 
+
+test.armadillo.sugar.matrix.ctor <- function(){
+
+	fx <- cxxfunction( signature(x= "numeric") , '
+	NumericVector xx(x) ;
+	arma::mat m = diag( xx ) ; 
+    return wrap( m ) ;
+    
+	', plugin = "RcppArmadillo" )
+	checkEquals( fx(1:10), 
+		diag( 1:10 ) , 
+		msg = "Mat( sugar expression )" )
+	
+}
+



More information about the Rcpp-commits mailing list