Discussion:
[Rcpp-devel] trying to insert a number as first element of already existing vector
Jeff Newmiller
2018-12-10 16:29:52 UTC
Permalink
The archives probably weren't what Mark was hoping for, though they are good medicine. Reading the R documentation [1] is probably also good medicine that Mark is hoping (in vain) to avoid. And then there is the topic of conventional C++ memory handling, which is relevant but for which there are easily hundreds of tutorials unrelated to Rcpp. Syntactic sugar like Rcpp makes coding safer and reduces boilerplate code, but if you want performance then there really is no substitute for understanding what that sugar does for you.

[1] https://cran.r-project.org/doc/manuals/r-release/R-ints.html

https://stackoverflow.com/questions/41602024/should-i-prefer-rcppnumericvector-over-stdvector
...
Oh, as I said, the documentation on Rcpp is incredible but is there
anything discussing memory because
I'm pretty lost on that. Thanks again.
Are you talking about this list archives?
http://lists.r-forge.r-project.org/pipermail/rcpp-devel/
Serguei.
_______________________________________________
Rcpp-devel mailing list
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
--
Sent from my phone. Please excuse my brevity.
Mark Leeds
2018-12-10 17:56:17 UTC
Permalink
Thanks Jeff. I'll check those out. I recently found a gist of Gabor that
explains the relation
between Rcpp and the concept of pointers in C.

https://gist.github.com/ggrothendieck
Post by Jeff Newmiller
The archives probably weren't what Mark was hoping for, though they are
good medicine. Reading the R documentation [1] is probably also good
medicine that Mark is hoping (in vain) to avoid. And then there is the
topic of conventional C++ memory handling, which is relevant but for which
there are easily hundreds of tutorials unrelated to Rcpp. Syntactic sugar
like Rcpp makes coding safer and reduces boilerplate code, but if you want
performance then there really is no substitute for understanding what that
sugar does for you.
[1] https://cran.r-project.org/doc/manuals/r-release/R-ints.html
https://stackoverflow.com/questions/41602024/should-i-prefer-rcppnumericvector-over-stdvector
On December 10, 2018 8:01:40 AM PST, Serguei Sokol <
...
Oh, as I said, the documentation on Rcpp is incredible but is there
anything discussing memory because
I'm pretty lost on that. Thanks again.
Are you talking about this list archives?
http://lists.r-forge.r-project.org/pipermail/rcpp-devel/
Serguei.
_______________________________________________
Rcpp-devel mailing list
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
--
Sent from my phone. Please excuse my brevity.
Barth Riley
2018-12-09 09:03:33 UTC
Permalink
Dear Mark

Regarding your second question, the STL has a function called partial_sum() which can be used to compute the cumulative sum. Go to the following URL for details:

http://gallery.rcpp.org/articles/vector-cumulative-sum/

Barth
Mark Leeds
2018-12-09 09:19:48 UTC
Permalink
Thanks Barh. I'll check that out.
Post by Barth Riley
Dear Mark
Regarding your second question, the STL has a function called
partial_sum() which can be used to compute the cumulative sum. Go to the
http://gallery.rcpp.org/articles/vector-cumulative-sum/
Barth
Dirk Eddelbuettel
2018-12-10 12:15:08 UTC
Permalink
On 10 December 2018 at 13:04, Jan van der Laan wrote:
| Small addendum: A large part of the performance gain in my example comes
| from using NumericVector instead of std::vector<double>. Which avoids a
| conversion. An example using std::copy with Numeric vector runs in the
| same time as the version using memcpy.

+1

That sounds reasonable and matches my experience: std::memcpy is good yet
std::copy may itself be implemented with using it. And ussing care with the
interface is important: std::vector<> has its own memory allocation scheme so
we cannot do without a copy which we notice here in the timings.

Dirk
--
http://dirk.eddelbuettel.com | @eddelbuettel | ***@debian.org
Loading...