Skip to content

Commit

Permalink
fix CRAN issues with UBSAN
Browse files Browse the repository at this point in the history
  • Loading branch information
david-cortes committed Jun 27, 2024
1 parent 873db84 commit 260a535
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
2 changes: 0 additions & 2 deletions src/Makevars.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
PKG_CPPFLAGS = -DARMA_32BIT_WORD -I../inst/include/ -DRSPARSE_R_PKG -DARMA_NO_DEBUG
PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS)
PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS) @FLOAT_LIBS@ $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)

CXX_STD = CXX11
2 changes: 0 additions & 2 deletions src/Makevars.win
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,3 @@ FLOAT_LIBS = $(shell ${R_SCMD} "float:::ldflags()")
PKG_CPPFLAGS = -I../inst/include/ -DARMA_32BIT_WORD -DARMA_DONT_USE_BLAS -DARMA_NO_DEBUG -DRSPARSE_R_PKG
PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS)
PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS) $(FLOAT_LIBS) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)

CXX_STD = CXX11
13 changes: 7 additions & 6 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,17 @@ const std::string currentDateTime() {
}

arma::fmat extract_float_matrix(Rcpp::S4 x) {
Rcpp::IntegerMatrix x_data = x.slot("Data");
float* ptr = reinterpret_cast<float*>(&x_data[0]);
arma::fmat x_mapped = arma::fmat(ptr, x_data.nrow(), x_data.ncol(), false, true);
SEXP x_data = x.slot("Data");
SEXP dims = Rf_getAttrib(x_data, R_DimSymbol);
float* ptr = reinterpret_cast<float*>(INTEGER(x_data));
arma::fmat x_mapped = arma::fmat(ptr, INTEGER(dims)[0], INTEGER(dims)[1], false, true);
return (x_mapped);
}

arma::fvec extract_float_vector(Rcpp::S4 x) {
Rcpp::IntegerVector x_data = x.slot("Data");
float* ptr = reinterpret_cast<float*>(&x_data[0]);
arma::fvec x_mapped = arma::fvec(ptr, x_data.length(), false, true);
SEXP x_data = x.slot("Data");
float* ptr = reinterpret_cast<float*>(INTEGER(x_data));
arma::fvec x_mapped = arma::fvec(ptr, Rf_xlength(x_data), false, true);
return (x_mapped);
}

Expand Down

0 comments on commit 260a535

Please sign in to comment.