From bd10a793120ba87dc4089d99326b0d37478292c9 Mon Sep 17 00:00:00 2001 From: Travers Date: Tue, 3 Sep 2024 15:47:06 -0700 Subject: [PATCH] . --- README.md | 6 +++--- .../blockshuffle_xgboost_model/convert_xgboost_json.R | 4 ++-- src/io/io_common.h | 8 +++++++- src/io/xgboost_blockshuffle_model.h | 3 ++- vignettes/vignette.html | 4 ++-- vignettes/vignette.rmd | 4 ++-- 6 files changed, 18 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index a791d8b..693890c 100644 --- a/README.md +++ b/README.md @@ -30,8 +30,8 @@ package. It is not compatible with the original `qs` format. install.packages("qs2") ``` -On Mac or Linux, you can enable multi-threading by compile from source. -It is enabled by default on Windows. +On Mac or Linux, you can enable multi-threading by compiling from +source. It is enabled by default on Windows. ``` r remotes::install_cran("qs2", type = "source", configure.args = " --with-TBB --with-simd=AVX2") @@ -42,7 +42,7 @@ framework via the `RcppParallel` package. ## Converting qs2 to RDS -Because the `qs2` format directly uses R serialization you can convert +Because the `qs2` format directly uses R serialization, you can convert it to RDS and vice versa. ``` r diff --git a/inst/analysis/blockshuffle_xgboost_model/convert_xgboost_json.R b/inst/analysis/blockshuffle_xgboost_model/convert_xgboost_json.R index eb0135d..bc01e20 100644 --- a/inst/analysis/blockshuffle_xgboost_model/convert_xgboost_json.R +++ b/inst/analysis/blockshuffle_xgboost_model/convert_xgboost_json.R @@ -43,7 +43,7 @@ if(standalone) { a(OUT) <- c("#include ", "using namespace Rcpp;") } else { a(OUT) <- c("#ifndef _QS2_XGBOOST_BLOCKSHUFFLE_MODEL_H", "#define _QS2_XGBOOST_BLOCKSHUFFLE_MODEL_H") - a(OUT) <- c("#include ", "#include ", "#include ") + a(OUT) <- c("#include ", "#include ", "#include ", '#include "io_common.h"') } a(OUT) <- ' @@ -65,7 +65,7 @@ struct XgTree { const std::vector & split_indices, const std::vector & left_children, const std::vector & right_children) : - nodes(std::make_unique(split_conditions.size())) { + nodes(MAKE_UNIQUE_BLOCK_CUSTOM(XgNode, split_conditions.size())) { for(size_t i = 0; i < split_conditions.size(); ++i) { nodes[i].split_idx = split_indices[i]; nodes[i].split_cond = split_conditions[i]; diff --git a/src/io/io_common.h b/src/io/io_common.h index 654e605..b3932c9 100644 --- a/src/io/io_common.h +++ b/src/io/io_common.h @@ -40,6 +40,12 @@ static constexpr uint32_t SHUFFLE_MASK = (1ULL << 31); #define MAKE_UNIQUE_BLOCK(SIZE) new char[SIZE] #endif +#if __cplusplus >= 201402L // Check for C++14 or above + #define MAKE_UNIQUE_BLOCK_CUSTOM(_TYPE_, SIZE) std::make_unique<_TYPE_[]>(SIZE) +#else + #define MAKE_UNIQUE_BLOCK_CUSTOM(_TYPE_, SIZE) new _TYPE_[SIZE] +#endif + // std::make_shared on an array requires c++20 (yes it is true) // If you try to use make_shared on c++17 or lower it won't compile or will segfault. #if __cplusplus >= 202002L // Check for C++20 or above @@ -82,7 +88,7 @@ inline constexpr unsigned char operator "" _u8(unsigned long long arg) noexcept return static_cast(arg); } -#define QS_MT_SERIALIZATION_DEBUG +// #define QS_MT_SERIALIZATION_DEBUG #if defined(QS_MT_SERIALIZATION_DEBUG) #include #include diff --git a/src/io/xgboost_blockshuffle_model.h b/src/io/xgboost_blockshuffle_model.h index 3f1276f..18aaffc 100644 --- a/src/io/xgboost_blockshuffle_model.h +++ b/src/io/xgboost_blockshuffle_model.h @@ -5,6 +5,7 @@ #include #include #include +#include "io_common.h" namespace XgboostBlockshuffleModel { @@ -24,7 +25,7 @@ struct XgTree { const std::vector & split_indices, const std::vector & left_children, const std::vector & right_children) : - nodes(std::make_unique(split_conditions.size())) { + nodes(MAKE_UNIQUE_BLOCK_CUSTOM(XgNode, split_conditions.size())) { for(size_t i = 0; i < split_conditions.size(); ++i) { nodes[i].split_idx = split_indices[i]; nodes[i].split_cond = split_conditions[i]; diff --git a/vignettes/vignette.html b/vignettes/vignette.html index 9100664..c0e66f4 100644 --- a/vignettes/vignette.html +++ b/vignettes/vignette.html @@ -335,13 +335,13 @@

qs2

Installation

-

On Mac or Linux, you can enable multi-threading by compile from source. It is enabled by default on Windows.

+

On Mac or Linux, you can enable multi-threading by compiling from source. It is enabled by default on Windows.

Multi-threading in qs2 uses the Intel Thread Building Blocks framework via the RcppParallel package.

Converting qs2 to RDS

-

Because the qs2 format directly uses R serialization you can convert it to RDS and vice versa.

+

Because the qs2 format directly uses R serialization, you can convert it to RDS and vice versa.

file_qs2 <- tempfile(fileext = ".qs2")
 file_rds <- tempfile(fileext = ".RDS")
 x <- runif(1e6)
diff --git a/vignettes/vignette.rmd b/vignettes/vignette.rmd
index dc2e07d..9dd0568 100644
--- a/vignettes/vignette.rmd
+++ b/vignettes/vignette.rmd
@@ -44,7 +44,7 @@ Use the file extension `qs2` to distinguish it from the original `qs` package. I
 install.packages("qs2")
 ```
 
-On Mac or Linux, you can enable multi-threading by compile from source. It is enabled by default on Windows. 
+On Mac or Linux, you can enable multi-threading by compiling from source. It is enabled by default on Windows. 
 
 ```{r eval=FALSE}
 remotes::install_cran("qs2", type = "source", configure.args = " --with-TBB --with-simd=AVX2")
@@ -55,7 +55,7 @@ Multi-threading in `qs2` uses the `Intel Thread Building Blocks` framework via t
 
 ## Converting qs2 to RDS
 
-Because the `qs2` format directly uses R serialization you can convert it to RDS and vice versa.
+Because the `qs2` format directly uses R serialization, you can convert it to RDS and vice versa.
 
 ```{r eval=FALSE}
 file_qs2 <- tempfile(fileext = ".qs2")