[Rcpp-commits] r3504 - pkg/RcppEigen/inst/include

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Mar 13 23:36:11 CET 2012


Author: dmbates
Date: 2012-03-13 23:36:11 +0100 (Tue, 13 Mar 2012)
New Revision: 3504

Modified:
   pkg/RcppEigen/inst/include/RcppEigenWrap.h
Log:
Change the wrap methods to avoid creating Rcpp::Dimension objects (which are implicitly created by the Rcpp::Matrix constructor).


Modified: pkg/RcppEigen/inst/include/RcppEigenWrap.h
===================================================================
--- pkg/RcppEigen/inst/include/RcppEigenWrap.h	2012-03-13 22:35:12 UTC (rev 3503)
+++ pkg/RcppEigen/inst/include/RcppEigenWrap.h	2012-03-13 22:36:11 UTC (rev 3504)
@@ -34,7 +34,9 @@
 
 //FIXME: Should extend this selection according to T
 			S4 ans(std::string(f->is_super ? "dCHMsuper" : "dCHMsimpl"));
-			ans.slot("Dim") = Dimension(f->n, f->n);
+			IntegerVector  dd(2);
+			dd[0] = dd[1] = f->n;
+			ans.slot("Dim") = dd;
 			ans.slot("perm") = ::Rcpp::wrap((int*)f->Perm, (int*)f->Perm + f->n);
 			ans.slot("colcount") = ::Rcpp::wrap((int*)f->ColCount, (int*)f->ColCount + f->n);
 			IntegerVector tt(f->is_super ? 6 : 4);
@@ -78,14 +80,20 @@
         // for plain dense objects
         template <typename T> 
         SEXP eigen_wrap_plain_dense( const T& obj, Rcpp::traits::true_type ){
-            // FIXME: deal with RowMajor, etc ...
-            const int RTYPE = Rcpp::traits::r_sexptype_traits<typename T::Scalar>::rtype ;
             if( T::ColsAtCompileTime == 1 ) {
                 return wrap( obj.data(), obj.data() + obj.size() ) ;
             } else {
-                Rcpp::Matrix<RTYPE> x( obj.rows(), obj.cols(), obj.data() ) ;
-                return x; 
-            }   
+				if (T::IsRowMajor)
+					throw std::invalid_argument("R requires column-major dense matrices");
+				typedef  typename T::Scalar                                Scalar;
+				const int RTYPE = Rcpp::traits::r_sexptype_traits<Scalar>::rtype ;
+				typedef typename ::Rcpp::traits::storage_type<RTYPE>::type STORAGE;
+				int m(obj.rows()), n(obj.cols());
+				SEXP ans = ::Rf_allocMatrix(RTYPE, m, n);
+				std::copy(obj.data(), obj.data() + m * n, 
+						  ::Rcpp::internal::r_vector_start<RTYPE,STORAGE>(ans));
+				return ans;
+            }
         }
         
         // for plain sparse objects



More information about the Rcpp-commits mailing list