From 8f306977d747c6e87c2764c31ba4f7dd688317ef Mon Sep 17 00:00:00 2001 From: "George G. Vega Yon" Date: Mon, 2 May 2016 16:16:21 -0700 Subject: [PATCH 1/5] Adding \!defined(ARMA_64BIT_WORD) in config.hpp. --- inst/include/armadillo_bits/config.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inst/include/armadillo_bits/config.hpp b/inst/include/armadillo_bits/config.hpp index 2d4ddcc1..aa33ba1a 100644 --- a/inst/include/armadillo_bits/config.hpp +++ b/inst/include/armadillo_bits/config.hpp @@ -187,7 +187,7 @@ #undef ARMA_USE_EXTERN_CXX11_RNG #endif -#if defined(ARMA_32BIT_WORD) +#if defined(ARMA_32BIT_WORD) && !defined(ARMA_64BIT_WORD) #undef ARMA_64BIT_WORD #endif From d4b9e563b37cebc926c498eb9f2467682a7a1eb8 Mon Sep 17 00:00:00 2001 From: "George G. Vega Yon" Date: Tue, 3 May 2016 10:00:17 -0700 Subject: [PATCH 2/5] Allowing for ARMA_64BIT_WORD (default still ARMA_32BIT_WORD) --- inst/include/RcppArmadilloConfig.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/inst/include/RcppArmadilloConfig.h b/inst/include/RcppArmadilloConfig.h index 7da6795e..53a5fe14 100644 --- a/inst/include/RcppArmadilloConfig.h +++ b/inst/include/RcppArmadilloConfig.h @@ -100,7 +100,9 @@ // Under C++11 and C++14, Armadillo now defaults to using int64_t for // integers. This prevents us from passing integer vectors to R as // only used int32_t -- so we select the shorter representation here. -#define ARMA_32BIT_WORD 1 +#if !defined(ARMA_64BIT_WORD) + #define ARMA_32BIT_WORD 1 +#endif #endif From e8b7c21a7de6b8b696cb39f9df754a235c6454de Mon Sep 17 00:00:00 2001 From: "George G. Vega Yon" Date: Tue, 3 May 2016 10:05:31 -0700 Subject: [PATCH 3/5] Previous commits where messy --- inst/include/RcppArmadilloConfig.h | 4 +--- inst/include/armadillo_bits/config.hpp | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/inst/include/RcppArmadilloConfig.h b/inst/include/RcppArmadilloConfig.h index 53a5fe14..7da6795e 100644 --- a/inst/include/RcppArmadilloConfig.h +++ b/inst/include/RcppArmadilloConfig.h @@ -100,9 +100,7 @@ // Under C++11 and C++14, Armadillo now defaults to using int64_t for // integers. This prevents us from passing integer vectors to R as // only used int32_t -- so we select the shorter representation here. -#if !defined(ARMA_64BIT_WORD) - #define ARMA_32BIT_WORD 1 -#endif +#define ARMA_32BIT_WORD 1 #endif diff --git a/inst/include/armadillo_bits/config.hpp b/inst/include/armadillo_bits/config.hpp index aa33ba1a..2d4ddcc1 100644 --- a/inst/include/armadillo_bits/config.hpp +++ b/inst/include/armadillo_bits/config.hpp @@ -187,7 +187,7 @@ #undef ARMA_USE_EXTERN_CXX11_RNG #endif -#if defined(ARMA_32BIT_WORD) && !defined(ARMA_64BIT_WORD) +#if defined(ARMA_32BIT_WORD) #undef ARMA_64BIT_WORD #endif From 7088826b30bcfeff1b23f0b216e073676f9af8f2 Mon Sep 17 00:00:00 2001 From: "George G. Vega Yon" Date: Tue, 3 May 2016 10:09:26 -0700 Subject: [PATCH 4/5] Allowing ARMA_64BIT_WORD if required --- inst/include/RcppArmadilloConfig.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/inst/include/RcppArmadilloConfig.h b/inst/include/RcppArmadilloConfig.h index 7da6795e..42b4085f 100644 --- a/inst/include/RcppArmadilloConfig.h +++ b/inst/include/RcppArmadilloConfig.h @@ -100,7 +100,10 @@ // Under C++11 and C++14, Armadillo now defaults to using int64_t for // integers. This prevents us from passing integer vectors to R as // only used int32_t -- so we select the shorter representation here. -#define ARMA_32BIT_WORD 1 +// unless int64_t is explicitly required during compilation. +#if !defined(ARMA_64BIT_WORD) + #define ARMA_32BIT_WORD 1 +#endif #endif From 4a9c1d89bd1c9ced3a188bb898b33348881f63b6 Mon Sep 17 00:00:00 2001 From: "George G. Vega Yon" Date: Tue, 3 May 2016 15:56:46 -0700 Subject: [PATCH 5/5] Changing export for dgCMatrix based on armadillo batch creator --- inst/include/RcppArmadilloAs.h | 58 +++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 18 deletions(-) diff --git a/inst/include/RcppArmadilloAs.h b/inst/include/RcppArmadilloAs.h index fe5e0432..646b383e 100644 --- a/inst/include/RcppArmadilloAs.h +++ b/inst/include/RcppArmadilloAs.h @@ -91,25 +91,47 @@ namespace traits { IntegerVector p = mat.slot("p") ; Vector x = mat.slot("x") ; - arma::SpMat res(dims[0], dims[1]); - - // create space for values, copy and set sentinel - arma::access::rw(res.values) = arma::memory::acquire_chunked(x.size() + 1); - arma::arrayops::copy(arma::access::rwp(res.values), x.begin(), x.size()); - arma::access::rw(res.values[x.size()]) = T(0.0); // sets sentinel - - // create space for row_indices, copy and set sentinel - arma::access::rw(res.row_indices) = arma::memory::acquire_chunked(i.size() + 1); - std::copy(i.begin(), i.end(), arma::access::rwp(res.row_indices)); - arma::access::rw(res.values[i.size()]) = arma::uword(0); // sets sentinel - - // the space for col_ptrs is already initialized when we call the - // constructor a few lines above so we only need to fill the appropriate - // values, and the sentinel is already set to uword_max as well. + // arma::SpMat res(dims[0], dims[1]); + arma::SpMat res((unsigned) dims[0], (unsigned) dims[1]); + + // Resizing + res.mem_resize((unsigned) x.size()); + + // Copying elements + std::copy(i.begin(), i.end(), arma::access::rwp(res.row_indices)); std::copy(p.begin(), p.end(), arma::access::rwp(res.col_ptrs)); - - // set the number of non-zero elements - arma::access::rw(res.n_nonzero) = x.size(); + std::copy(x.begin(), x.end(), arma::access::rwp(res.values)); + + // Setting the sentinel + arma::access::rw(res.col_ptrs[(unsigned) dims[1] + 1]) = + std::numeric_limits::max(); + + // // create space for values, copy and set sentinel + // arma::access::rw(res.values) = arma::memory::acquire_chunked(x.size() + 1); + // arma::arrayops::copy(arma::access::rwp(res.values), x.begin(), x.size()); + // arma::access::rw(res.values[x.size()]) = T(0.0); // sets sentinel + // + // // create space for row_indices, copy and set sentinel + // arma::access::rw(res.row_indices) = arma::memory::acquire_chunked(i.size() + 1); + // std::copy(i.begin(), i.end(), arma::access::rwp(res.row_indices)); + // arma::access::rw(res.values[i.size()]) = arma::uword(0); // sets sentinel + // + // // the space for col_ptrs is already initialized when we call the + // // constructor a few lines above so we only need to fill the appropriate + // // values, and the sentinel is already set to uword_max as well. + // std::copy(p.begin(), p.end(), arma::access::rwp(res.col_ptrs)); + // + // // set the number of non-zero elements + // arma::access::rw(res.n_nonzero) = x.size(); + + // // Using BATCH constructor + // arma::SpMat res( + // Rcpp::as< arma::uvec >(i), + // Rcpp::as< arma::uvec >(p), + // Rcpp::as< arma::Col >(x), + // (unsigned) dims[0], + // (unsigned) dims[1] + // ); return res; }