Skip to content

Commit

Permalink
avoid conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
sbfnk committed Mar 12, 2024
1 parent 01cc3a0 commit 0780ec2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion inst/stan/estimate_infections.stan
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ model {
generated quantities {
array[ot_h] int imputed_reports;
vector[estimate_r > 0 ? 0: ot_h] gen_R;
array[ot_h - 1] real r;
vector[ot_h - 1] r;
real gt_mean;
real gt_var;
vector[return_likelihood ? ot : 0] log_lik;
Expand Down
4 changes: 2 additions & 2 deletions inst/stan/functions/generated_quantities.stan
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ vector calculate_Rt(vector infections, int seeding_time,
}

// Calculate growth rate
array[] real calculate_growth(vector infections, int seeding_time) {
vector calculate_growth(vector infections, int seeding_time) {
int t = num_elements(infections);
int ot = t - seeding_time;
vector[t] log_inf = log(infections);
vector[ot] growth = log_inf[(seeding_time + 1):t] - log_inf[seeding_time:(t - 1)];
return(to_array_1d(growth));
return(growth);
}
6 changes: 4 additions & 2 deletions inst/stan/simulate_infections.stan
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ generated quantities {
matrix[n, t] infections; //latent infections
matrix[n, t - seeding_time] reports; // observed cases
array[n, t - seeding_time] int imputed_reports;
array[n, t - seeding_time - 1] real r;
matrix[n, t - seeding_time - 1] r;
for (i in 1:n) {
// generate infections from Rt trace
vector[delay_type_max[gt_id] + 1] gt_rev_pmf;
Expand Down Expand Up @@ -94,6 +94,8 @@ generated quantities {
imputed_reports[i] = report_rng(
to_vector(reports[i]), rep_phi[i], model_type
);
r[i] = calculate_growth(to_vector(infections[i]), seeding_time + 1);
r[i] = to_row_vector(
calculate_growth(to_vector(infections[i]), seeding_time + 1)
);
}
}

0 comments on commit 0780ec2

Please sign in to comment.