-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #177 from mrc-ide/dev
Dev
- Loading branch information
Showing
11 changed files
with
205 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Package: individual | ||
Title: Framework for Specifying and Simulating Individual Based Models | ||
Version: 0.1.10 | ||
Version: 0.1.11 | ||
Authors@R: c( | ||
person( | ||
given = "Giovanni", | ||
|
@@ -23,6 +23,12 @@ Authors@R: c( | |
comment = c(ORCID = "0000-0003-3001-4959"), | ||
email = '[email protected]' | ||
), | ||
person( | ||
given = "Paul", | ||
family = "Liétar", | ||
role = c('aut'), | ||
email = '[email protected]' | ||
), | ||
person( | ||
given = "Imperial College of Science, Technology and Medicine", | ||
family = "", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* RenderVector.h | ||
* | ||
* Created on: 21 Dec 2023 | ||
* Author: pl2113 | ||
*/ | ||
|
||
#ifndef INST_INCLUDE_RENDER_VECTOR_H_ | ||
#define INST_INCLUDE_RENDER_VECTOR_H_ | ||
|
||
#include <Rcpp.h> | ||
|
||
/** | ||
* A thin wrapper around a std::vector<double>, used to provide by-reference | ||
* semantics and guaranteed in-place mutation in the Render class. | ||
* | ||
*/ | ||
struct RenderVector { | ||
RenderVector(std::vector<double> data) : _data(std::move(data)) { } | ||
|
||
void update(size_t index, double value) { | ||
// index is R-style 1-indexed, rather than C's 0-indexing. | ||
if (index < 1 || index > _data.size()) { | ||
Rcpp::stop("index out-of-bounds"); | ||
} | ||
_data[index - 1] = value; | ||
} | ||
|
||
const std::vector<double>& data() const { | ||
return _data; | ||
} | ||
|
||
private: | ||
std::vector<double> _data; | ||
}; | ||
|
||
#endif /* INST_INCLUDE_RENDER_VECTOR_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* render_vector.cpp | ||
* | ||
* Created on: 21 Dec 2023 | ||
* Author: pl2113 | ||
*/ | ||
|
||
|
||
#include "../inst/include/RenderVector.h" | ||
#include <Rcpp.h> | ||
|
||
|
||
//[[Rcpp::export]] | ||
Rcpp::XPtr<RenderVector> create_render_vector(std::vector<double> data) { | ||
return Rcpp::XPtr<RenderVector>(new RenderVector(std::move(data)), true); | ||
} | ||
|
||
//[[Rcpp::export]] | ||
void render_vector_update(Rcpp::XPtr<RenderVector> v, size_t index, double value) { | ||
v->update(index, value); | ||
} | ||
|
||
//[[Rcpp::export]] | ||
std::vector<double> render_vector_data(Rcpp::XPtr<RenderVector> v) { | ||
return v->data(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# | ||
# bench-render.R | ||
# | ||
# Created on: 22 Dec 2023 | ||
# Author: pl2113 | ||
# | ||
|
||
library(individual) | ||
library(bench) | ||
library(ggplot2) | ||
library(scales) | ||
|
||
source("./tests/performance/utils.R") | ||
|
||
render_single <- bench::press( | ||
timesteps=floor(10^seq(3,6,0.25)), | ||
{ | ||
render <- Render$new(timesteps) | ||
bench::mark( | ||
min_iterations = 50, | ||
check = FALSE, | ||
render={ | ||
# Use timesteps/2 to write in the middle of the array | ||
render$render("data", 0.5, timesteps/2) | ||
}) | ||
}) | ||
|
||
render_single %>% | ||
simplify_bench_output() %>% | ||
ggplot() + | ||
aes(x = timesteps, y = as.numeric(time), color=expression, fill=expression, group=as.factor(timesteps):expression) + | ||
geom_violin(position=position_dodge(width=0.02), alpha=0.3) + | ||
labs(y="time", fill="expression", color="expression") + | ||
scale_x_continuous(trans='log10', n.breaks=6, labels = label_comma()) + | ||
scale_y_continuous(trans='log10', n.breaks=6, labels = function(x) format(bench::as_bench_time(x))) + | ||
ggtitle("Render single timestep benchmark") | ||
|
||
render_all <- bench::press( | ||
timesteps=floor(10^seq(3,5,0.25)), | ||
{ | ||
data <- runif(timesteps) | ||
bench::mark( | ||
min_iterations = 5, | ||
check = FALSE, | ||
filter_gc = FALSE, | ||
render_all={ | ||
render <- Render$new(timesteps) | ||
mapply(function(x, i) render$render("data", x, i), data, seq_along(data)) | ||
}) | ||
}) | ||
|
||
render_all %>% | ||
simplify_bench_output(filter_gc=FALSE) %>% | ||
ggplot() + | ||
aes(x = timesteps, y = as.numeric(time), color=expression, fill=expression, group=as.factor(timesteps):expression) + | ||
geom_violin(position=position_dodge(width=0.01), alpha=0.3) + | ||
labs(y="time", fill="expression", color="expression") + | ||
scale_x_continuous(trans='log10', n.breaks=6, labels = label_comma()) + | ||
scale_y_continuous(trans='log10', n.breaks=6, labels = function(x) format(bench::as_bench_time(x))) + | ||
ggtitle("Render all timesteps benchmark") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters