[Rcpp-commits] r3673 - in pkg/RcppCNPy: . inst src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Jul 6 15:13:32 CEST 2012


Author: edd
Date: 2012-07-06 15:13:32 +0200 (Fri, 06 Jul 2012)
New Revision: 3673

Modified:
   pkg/RcppCNPy/ChangeLog
   pkg/RcppCNPy/inst/NEWS.Rd
   pkg/RcppCNPy/src/cnpyMod.cpp
Log:
 o saveing now transposes correctly too
 o updated NEWS and ChangeLog vis-a-vis tests/ directory


Modified: pkg/RcppCNPy/ChangeLog
===================================================================
--- pkg/RcppCNPy/ChangeLog	2012-07-06 13:08:17 UTC (rev 3672)
+++ pkg/RcppCNPy/ChangeLog	2012-07-06 13:13:32 UTC (rev 3673)
@@ -1,8 +1,10 @@
 2012-07-06  Dirk Eddelbuettel  <edd at debian.org>
 
 	* src/cnpy.h: Include cstdint for int64_t if C++11 has been enabled
-	* src/cnpyMod.cpp (npyLoad): Support integer types if C++11 avail.
+	* src/cnpyMod.cpp: Support integer types if C++11 available
 
+	* tests/: Simple set of regression tests added
+
 2012-07-05  Dirk Eddelbuettel  <edd at dexter>
 
 	* src/cnpyMod.cpp: Added transpose() method to transparently deal

Modified: pkg/RcppCNPy/inst/NEWS.Rd
===================================================================
--- pkg/RcppCNPy/inst/NEWS.Rd	2012-07-06 13:08:17 UTC (rev 3672)
+++ pkg/RcppCNPy/inst/NEWS.Rd	2012-07-06 13:13:32 UTC (rev 3673)
@@ -10,6 +10,7 @@
     type which is available only when the \code{-std=c++0x} switch is
     used at build-time (and CRAN still discourages use of it)
     \item Added support for reading gzip'ed files ending in ".npy.gz"
+    \item Added (simple) regression tests in directory \code{tests/}
   }
 }
 \section{Changes in version 0.0.1 (2012-07-04)}{

Modified: pkg/RcppCNPy/src/cnpyMod.cpp
===================================================================
--- pkg/RcppCNPy/src/cnpyMod.cpp	2012-07-06 13:08:17 UTC (rev 3672)
+++ pkg/RcppCNPy/src/cnpyMod.cpp	2012-07-06 13:13:32 UTC (rev 3673)
@@ -92,26 +92,34 @@
 
 void npySave(std::string filename, Rcpp::RObject x, std::string mode) { 
     if (::Rf_isMatrix(x)) {
-        if (::Rf_isInteger(x)) {
-            Rcpp::IntegerMatrix mat(x);
-            std::vector<unsigned int> shape = Rcpp::as<std::vector<unsigned int> >(Rcpp::IntegerVector::create(mat.nrow(), mat.ncol()));
+        if (::Rf_isNumeric(x)) {
+            Rcpp::NumericMatrix mat = transpose(Rcpp::NumericMatrix(x));
+            std::vector<unsigned int> shape = 
+                Rcpp::as<std::vector<unsigned int> >(Rcpp::IntegerVector::create(mat.ncol(), mat.nrow()));
             cnpy::npy_save(filename, mat.begin(), &(shape[0]), 2, mode);
-        } else if (::Rf_isNumeric(x)) {
-            Rcpp::NumericMatrix mat(x);
-            std::vector<unsigned int> shape = Rcpp::as<std::vector<unsigned int> >(Rcpp::IntegerVector::create(mat.nrow(), mat.ncol()));
+#ifdef RCPP_HAS_LONG_LONG_TYPES
+        } else if (::Rf_isInteger(x)) {
+            Rcpp::IntegerMatrix mat = transpose(Rcpp::IntegerMatrix(x));
+            std::vector<unsigned int> shape = 
+                Rcpp::as<std::vector<unsigned int> >(Rcpp::IntegerVector::create(mat.ncol(), mat.nrow()));
             cnpy::npy_save(filename, mat.begin(), &(shape[0]), 2, mode);
+#endif
         } else {
             REprintf("Unsupported matrix type\n");
         }
     } else if (::Rf_isVector(x)) {
-        if (::Rf_isInteger(x)) {
+        if (::Rf_isNumeric(x)) {
+            Rcpp::NumericVector vec(x);
+            std::vector<unsigned int> shape = 
+                Rcpp::as<std::vector<unsigned int> >(Rcpp::IntegerVector::create(vec.length()));
+            cnpy::npy_save(filename, vec.begin(), &(shape[0]), 1, mode);
+#ifdef RCPP_HAS_LONG_LONG_TYPES
+        } else if (::Rf_isInteger(x)) {
             Rcpp::IntegerVector vec(x);
-            std::vector<unsigned int> shape = Rcpp::as<std::vector<unsigned int> >(Rcpp::IntegerVector::create(vec.length()));
+            std::vector<unsigned int> shape = 
+                Rcpp::as<std::vector<unsigned int> >(Rcpp::IntegerVector::create(vec.length()));
             cnpy::npy_save(filename, vec.begin(), &(shape[0]), 1, mode);
-        } else if (::Rf_isNumeric(x)) {
-            Rcpp::NumericVector vec(x);
-            std::vector<unsigned int> shape = Rcpp::as<std::vector<unsigned int> >(Rcpp::IntegerVector::create(vec.length()));
-            cnpy::npy_save(filename, vec.begin(), &(shape[0]), 1, mode);
+#endif
         } else {
             REprintf("Unsupported vector type\n");
         }



More information about the Rcpp-commits mailing list