Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowing ARMA_64BIT_WORD if required #88

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
58 changes: 40 additions & 18 deletions inst/include/RcppArmadilloAs.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,25 +91,47 @@ namespace traits {
IntegerVector p = mat.slot("p") ;
Vector<RTYPE> x = mat.slot("x") ;

arma::SpMat<T> res(dims[0], dims[1]);

// create space for values, copy and set sentinel
arma::access::rw(res.values) = arma::memory::acquire_chunked<T>(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<arma::uword>(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<T> res(dims[0], dims[1]);
arma::SpMat<T> 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<arma::uword>::max();

// // create space for values, copy and set sentinel
// arma::access::rw(res.values) = arma::memory::acquire_chunked<T>(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<arma::uword>(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<T> res(
// Rcpp::as< arma::uvec >(i),
// Rcpp::as< arma::uvec >(p),
// Rcpp::as< arma::Col<T> >(x),
// (unsigned) dims[0],
// (unsigned) dims[1]
// );

return res;
}
Expand Down
5 changes: 4 additions & 1 deletion inst/include/RcppArmadilloConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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