Skip to content

Commit

Permalink
try to work without std::make_unique [skip vbump] (#354)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielinteractive authored Oct 12, 2023
1 parent 7d5502e commit beeb7c7
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 19 deletions.
5 changes: 2 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: mmrm
Title: Mixed Models for Repeated Measures
Version: 0.3.3.9000
Version: 0.3.4
Authors@R: c(
person("Daniel", "Sabanes Bove", , "[email protected]", role = c("aut", "cre")),
person("Julia", "Dedic", , "[email protected]", role = "aut"),
Expand Down Expand Up @@ -72,7 +72,7 @@ Suggests:
microbenchmark,
mockery,
parallelly (>= 1.32.0),
parsnip (>= 1.0.4),
parsnip (>= 1.1.0),
purrr,
rmarkdown,
sasr,
Expand All @@ -97,7 +97,6 @@ LazyData: true
NeedsCompilation: yes
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
SystemRequirements: C++14
Collate:
'between-within.R'
'catch-routine-registration.R'
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# mmrm 0.3.3.9000
# mmrm 0.3.4

### New Features

Expand Down
18 changes: 9 additions & 9 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
)

register_on_load(
"parsnip", c("1.0.4", NA),
"parsnip", c("1.1.0", NA),
callback = parsnip_add_mmrm,
message = emit_tidymodels_register_msg
)
Expand Down Expand Up @@ -74,24 +74,24 @@ register_on_load <- function(pkg,
check_package_version <- function(pkg, ver = c(NA_character_, NA_character_)) {
assert_character(ver, len = 2L)
pkg_ver <- utils::packageVersion(pkg)
ver <- lapply(ver, numeric_version, strict = FALSE)
ver <- numeric_version(ver, strict = FALSE)

warn_version <- function(pkg, pkg_ver, ver) {
ver_na <- is.na(vapply(ver, is.na, logical(1L)))
ver_na <- is.na(ver)
warning(sprintf(
"Cannot register mmrm for use with %s (v%s). Version %s required.",
pkg, pkg_ver,
if (!any(ver_na)) {
sprintf("%s to %s", ver[[1]], ver[[2]])
} else if (!is.na(ver[[1]])) {
paste0(">= ", ver[[1]])
} else if (!is.na(ver[[2]])) {
paste0("<= ", ver[[1]])
sprintf("%s to %s", ver[1], ver[2])
} else if (ver_na[2]) {
paste0(">= ", ver[1])
} else if (ver_na[1]) {
paste0("<= ", ver[2])
}
))
}

if (identical(pkg_ver < ver[[1]], TRUE) || identical(pkg_ver > ver[[2]], TRUE)) {
if (identical(pkg_ver < ver[1], TRUE) || identical(pkg_ver > ver[2], TRUE)) {
warn_version(pkg, pkg_ver, ver)
return(invisible(FALSE))
}
Expand Down
1 change: 0 additions & 1 deletion src/Makevars
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
CXX_STD = CXX14
PKG_CXXFLAGS = -D TMBAD_FRAMEWORK -D EIGEN_PERMANENTLY_DISABLE_STUPID_WARNINGS
7 changes: 4 additions & 3 deletions src/chol_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "covariance.h"
#include "utils.h"

// Base class of spatial and non-spatial Cholesky.
template <class Type>
struct lower_chol_base {
Expand Down Expand Up @@ -98,7 +99,7 @@ struct lower_chol_spatial: virtual lower_chol_base<Type> {

template <class T, class Base, class D1, class D2>
struct cache_obj {
std::map<int, std::unique_ptr<Base>> cache;
std::map<int, std::shared_ptr<Base>> cache;
int n_groups;
bool is_spatial;
int n_visits;
Expand All @@ -108,9 +109,9 @@ struct cache_obj {
for (int r = 0; r < n_groups; r++) {
// Use unique pointers here to better manage resource.
if (is_spatial) {
this->cache[r] = std::make_unique<D1>(theta.segment(r * theta_one_group_size, theta_one_group_size), cov_type);
this->cache[r] = std::make_shared<D1>(theta.segment(r * theta_one_group_size, theta_one_group_size), cov_type);
} else {
this->cache[r] = std::make_unique<D2>(theta.segment(r * theta_one_group_size, theta_one_group_size), n_visits, cov_type);
this->cache[r] = std::make_shared<D2>(theta.segment(r * theta_one_group_size, theta_one_group_size), n_visits, cov_type);
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions vignettes/package_structure.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,7 @@ This file implements the `P`, `Q` and `R` matrix calculations which are needed f
### `Makevars`

This file specifies additional flags used in the source code compilation.
We specify here the use of `C++14` such that `std::make_unique()` is available.
Also we ask `TMB` to use the `TMB` automatic differentiation framework (instead of the default `CppAD` framework) to be more efficient, and disable useless warnings from the `Eigen` library compilation.
We ask `TMB` to use the `TMB` automatic differentiation framework (instead of the default `CppAD` framework) to be more efficient, and disable useless warnings from the `Eigen` library compilation.

Note that additional flags such as `-Wno-ignored-attributes` cannot be included here because they are compiler specific. These can instead be specified in local `~/.R/Makevars` files.

Expand Down

0 comments on commit beeb7c7

Please sign in to comment.