From 5e06f5cc134391e5c781da935d91df902d004440 Mon Sep 17 00:00:00 2001 From: Sebastian Funk Date: Wed, 11 Dec 2024 14:25:38 +0000 Subject: [PATCH] 181: pre-assign sizes to variables (#182) * Revert "177: use `num_elements` instead of `size` (#178)" This reverts commit 2cfa80242e406533f41eba9c1f33472e2af3ff82. * assign sizes to variables * rename variables to match data --- DESCRIPTION | 2 +- NEWS.md | 2 +- inst/WORDLIST | 1 + inst/stan/functions/primarycensored.stan | 6 ++++-- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index d240910..5394437 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -19,7 +19,7 @@ Authors@R: comment = c(ORCID = "0000-0003-2386-4031")), person(given = "Sebastian", family = "Funk", - role = c("ctb"), + role = c("aut"), email = "sebastian.funk@lshtm.ac.uk", comment = c(ORCID = "0000-0002-2842-3406"))) Description: Provides functions for working with primary diff --git a/NEWS.md b/NEWS.md index f1dadb0..0c6180c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -11,7 +11,7 @@ Development release. ## Bug fixes - Added a missing `@family` tag to the `pcens` functions. This omission resulted in the Weibull analytical solution not being visible in the package documentation. -- Changed a call to `size()` to use `num_elements()` instead as an underlying type conversion was causing issues on some platforms. +- Added precalculation of vector sizes to the `primarycensored_cdf()` stan function, avoiding errors on some platforms due to narrowing conversions in aggregate initialisation. - Changed `D` to be of type real in `pcens_model.stan` in order to support infinite `relative_obs_time`. # primarycensored 1.0.0 diff --git a/inst/WORDLIST b/inst/WORDLIST index 19a0d9b..f3b4392 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -63,6 +63,7 @@ pcd pcens pdist pprimarycensored +precalculation primaryeventdistributions propto pwindow diff --git a/inst/stan/functions/primarycensored.stan b/inst/stan/functions/primarycensored.stan index 5534b7a..351db3d 100644 --- a/inst/stan/functions/primarycensored.stan +++ b/inst/stan/functions/primarycensored.stan @@ -37,8 +37,10 @@ real primarycensored_cdf(data real d, int dist_id, array[] real params, } else { // Use numerical integration for other cases real lower_bound = max({d - pwindow, 1e-6}); - array[num_elements(params) + num_elements(primary_params)] real theta = append_array(params, primary_params); - array[4] int ids = {dist_id, primary_id, num_elements(params), num_elements(primary_params)}; + int n_params = size(params); + int n_primary_params = size(primary_params); + array[n_params + n_primary_params] real theta = append_array(params, primary_params); + array[4] int ids = {dist_id, primary_id, n_params, n_primary_params}; vector[1] y0 = rep_vector(0.0, 1); result = ode_rk45(primarycensored_ode, y0, lower_bound, {d}, theta, {d, pwindow}, ids)[1, 1];