[Rcpp-commits] r3442 - pkg/RcppEigen/inst/include
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Jan 18 19:34:10 CET 2012
Author: dmbates
Date: 2012-01-18 19:34:09 +0100 (Wed, 18 Jan 2012)
New Revision: 3442
Modified:
pkg/RcppEigen/inst/include/RcppEigenWrap.h
Log:
Allow for wrapping sparse row-major matrices.
Modified: pkg/RcppEigen/inst/include/RcppEigenWrap.h
===================================================================
--- pkg/RcppEigen/inst/include/RcppEigenWrap.h 2012-01-15 23:16:13 UTC (rev 3441)
+++ pkg/RcppEigen/inst/include/RcppEigenWrap.h 2012-01-18 18:34:09 UTC (rev 3442)
@@ -91,19 +91,16 @@
// for plain sparse objects
template <typename T>
SEXP eigen_wrap_plain_dense( const T& object, Rcpp::traits::false_type ){
- typedef typename T::Scalar Scalar ;
- const int RTYPE = Rcpp::traits::r_sexptype_traits<Scalar>::rtype ;
- int nnz = object.nonZeros(), p = object.outerSize();
- Dimension dim(object.innerSize(), p);
- const int *ip = object._innerIndexPtr(), *pp = object._outerIndexPtr();
- const Scalar *xp = object._valuePtr();
- IntegerVector iv(ip, ip + nnz), pv(pp, pp + p + 1);
- Vector<RTYPE> xv(xp, xp + nnz);
- S4 ans("dgCMatrix");
- ans.slot("Dim") = dim;
- ans.slot("i") = iv;
- ans.slot("p") = pv;
- ans.slot("x") = xv;
+ typedef typename T::Scalar Scalar;
+ const int RTYPE = Rcpp::traits::r_sexptype_traits<Scalar>::rtype;
+ const int nnz = object.nonZeros();
+ S4 ans(T::IsRowMajor ? "dgRMatrix" : "dgCMatrix");
+ ans.slot("Dim") = Dimension(object.rows(), object.cols());
+ ans.slot(T::IsRowMajor ? "j" : "i") =
+ IntegerVector(object._innerIndexPtr(), object._innerIndexPtr() + nnz);
+ ans.slot("p") = IntegerVector(object._outerIndexPtr(),
+ object._outerIndexPtr() + object.outerSize() + 1);
+ ans.slot("x") = Vector<RTYPE>(object._valuePtr(), object._valuePtr() + nnz);
return ans;
}
More information about the Rcpp-commits
mailing list