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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Jun 28 00:13:03 CEST 2011


Author: dmbates
Date: 2011-06-28 00:13:03 +0200 (Tue, 28 Jun 2011)
New Revision: 3108

Modified:
   pkg/RcppEigen/inst/include/RcppEigenForward.h
   pkg/RcppEigen/inst/include/RcppEigenWrap.h
Log:
Add a wrap method (compiles but currently untested) for Eigen::SparseMatrix<T>


Modified: pkg/RcppEigen/inst/include/RcppEigenForward.h
===================================================================
--- pkg/RcppEigen/inst/include/RcppEigenForward.h	2011-06-27 14:46:15 UTC (rev 3107)
+++ pkg/RcppEigen/inst/include/RcppEigenForward.h	2011-06-27 22:13:03 UTC (rev 3108)
@@ -26,6 +26,7 @@
 #include <Rconfig.h>
 #include <RcppEigenConfig.h>
 #include <Eigen/Dense>
+#include <Eigen/Sparse>
 /* forward declarations */
 namespace Rcpp {
     /* support for wrap */
@@ -34,6 +35,7 @@
     template<typename T> SEXP wrap( const Eigen::Matrix<T, 1, Eigen::Dynamic>& ) ;
     template<typename T> SEXP wrap( const Eigen::Array<T, Eigen::Dynamic, Eigen::Dynamic>& ) ;
     template<typename T> SEXP wrap( const Eigen::Array<T, Eigen::Dynamic, 1>& ) ;
+    template<typename T> SEXP wrap( const Eigen::SparseMatrix<T>& ) ;
     
 #if 0
     namespace traits {

Modified: pkg/RcppEigen/inst/include/RcppEigenWrap.h
===================================================================
--- pkg/RcppEigen/inst/include/RcppEigenWrap.h	2011-06-27 14:46:15 UTC (rev 3107)
+++ pkg/RcppEigen/inst/include/RcppEigenWrap.h	2011-06-27 22:13:03 UTC (rev 3108)
@@ -62,6 +62,17 @@
 		return ::Rcpp::wrap(object.data(), object.data() + object.size());
     }
 
+	template <typename T>
+    SEXP wrap(const Eigen::SparseMatrix<T>& object ) {
+		int       nnz = object.nonZeros(), p = object.outerSize();
+		const int *ip = object._innerIndexPtr(), *pp = object._outerIndexPtr();
+		const T   *xp = object._valuePtr();
+		
+		return List(_["Dim"] = Dimension(object.rows(), p),
+					_["i"]   = ::Rcpp::wrap(ip, ip + nnz),
+					_["p"]   = ::Rcpp::wrap(pp, pp + p + 1),
+					_["x"]   = ::Rcpp::wrap(xp, xp + nnz));
+	}
 #if 0
     /* support for Rcpp::as */
 	



More information about the Rcpp-commits mailing list