-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Speedup render by avoiding repeated vector copies. #176
Merged
Merged
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
604a89a
Merge pull request #175 from mrc-ide/dev
giovannic 50a6d57
Update pkgdown.yml
giovannic ed06ad1
Fix logo on pkgdown
giovannic 066130b
Fix R build badge
giovannic 48e1a34
Speedup render by avoiding repeated vector copies.
plietar f0c21c5
Code review
plietar 17bc1d8
Switch the std::vector<double> instead of NumericVector.
plietar cf348b8
Update Rcpp to fix warnings.
plietar 250c388
Add test for error code path
plietar c9cdee3
Add benchmark for Render.
plietar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,36 @@ | ||
/* | ||
* 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 NumericVector, used to provide by-reference | ||
* semantics and guaranteed in-place mutation in the Render class. | ||
* | ||
*/ | ||
struct RenderVector { | ||
RenderVector(Rcpp::NumericVector data) : _data(data) { } | ||
|
||
void update(size_t index, float value) { | ||
if (index < 1 || index > _data.size()) { | ||
Rcpp::stop("index out-of-bounds"); | ||
} | ||
_data[index - 1] = value; | ||
} | ||
|
||
const Rcpp::NumericVector& data() const { | ||
return _data; | ||
} | ||
|
||
private: | ||
Rcpp::NumericVector _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(Rcpp::NumericVector data) { | ||
return Rcpp::XPtr<RenderVector>(new RenderVector(data), true); | ||
plietar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
//[[Rcpp::export]] | ||
void render_vector_update(Rcpp::XPtr<RenderVector> v, size_t index, float value) { | ||
plietar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
v->update(index, value); | ||
} | ||
|
||
//[[Rcpp::export]] | ||
Rcpp::NumericVector render_vector_data(Rcpp::XPtr<RenderVector> v) { | ||
return v->data(); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change comes from an Rcpp change at RcppCore/Rcpp#1256