On Tue, Sep 25, 2012 at 3:00 AM,
wrote:
>
> Someone just asked on StackOverflow about creating 3d arrays:
> http://stackoverflow.com/questions/12569992/constructing-3d-array-in-rcpp
>
> The best I could come up with is below. Did I miss something better?
>
> Full disclosure: The last I needed this
> Indeed, changing the sample size from 5 to 500 results in;
For completeness, I've included an iterator example, tested over a
range of sample sizes, and plotted the results with the code below.
From where I sit, it looks like the relative timings flatten out (more
or less) at 1e4.
I'm not sure
>> benchmark(fun1(), fun2(), fun3(), fun4(), order = "relative",
> replications = 1e5L)
> test replications elapsed relative user.self sys.self user.child
> sys.child
> 4 fun4() 106.161.000 6.060 NA
> NA
> 3 fun3() 106.191.005 5.91
On 25 September 2012 at 16:19, Rodney Sparapani wrote:
| Very good. Just one quick question since I have come across
| this in the documentation somewhere, but I can't seem to find
| it anymore. Can you pass optimization flags like so?
|
| f3<- cxxfunction(signature(), plugin="Rcpp", body='
|
On 09/25/2012 03:41 PM, Dirk Eddelbuettel wrote:
In the interest of constructive criticism, my version (and I must posted
essentially the same maybe ten times already on this very list):
R> f3<- cxxfunction(signature(), plugin="Rcpp", body='
+RNGScope scope;
+NumericVector rn = Rcpp::rn
Hi,
On Tue, Sep 25, 2012 at 4:41 PM, Dirk Eddelbuettel wrote:
>
> On 25 September 2012 at 13:53, Rodney Sparapani wrote:
> | You just need an explicit type conversion like so:
> |
> | funk2 <- cxxfunction(body='RNGScope scope;
> |NumericVector rn(5);
> |for (int i=0; i < 5
On 25 September 2012 at 21:08, Jeffrey Pollock wrote:
| I was interested to see if there was any real speed difference between the
| different methods suggested, and it looks like... there isn't...
Good move -- measuring is a good idea.
And yes: at the end of the days everything is just a call t
On 25 September 2012 at 13:53, Rodney Sparapani wrote:
| You just need an explicit type conversion like so:
|
| funk2 <- cxxfunction(body='RNGScope scope;
|NumericVector rn(5);
|for (int i=0; i < 5; i++) rn[i] = as(rnorm(1,0,1));
|return wrap(rn);',
|
Indeed, changing the sample size from 5 to 500 results in;
> benchmark(fun1(), fun2(), fun3(), fun4(), order = "relative",
replications = 1e5L)
test replications elapsed relative user.self sys.self user.child
sys.child
4 fun4() 106.161.000 6.060 NA
NA
3 f
There does appear to be a difference between the native Rf_rnorm and the R
rnorm function when the sample sizes get large. In fact, the Rf_rnorm appears
to be about twice as fast (using benchmark). Not surprisingly, doing a loop in
R is about 50 times slower.
From: Jonathan Olmsted [mailto:jp
Jeff and List,
I was interested in the same fairly recently. The full shebang is here <
http://www.rochester.edu/college/gradstudents/jolmsted/blog/2012/08/22/rcpp-rng-performance/>.
I, unlike you, found some difference between the various approaches.
If I had to guess why we come up with differe
I was interested to see if there was any real speed difference between the
different methods suggested, and it looks like... there isn't...
library(inline)
library(Rcpp)
library(rbenchmark)
fun1 <- cxxfunction(body = '
RNGScope scope;
NumericVector rn(5);
Yes - I agree that iterating is not the best way to go, but I am using this for
an agent based simulation where iteration is really my only option. I won't be
generating more than a few thousand records, so the time shouldn't be much of a
factor. Of course, in R it is painfully slow - so that
On Tue, Sep 25, 2012 at 1:53 PM, Rodney Sparapani wrote:
> On 09/25/2012 01:37 PM, Goldfeld, Keith wrote:
>
>>> code<- 'Rcpp::RNGScope scope;
>>
>>
>> +Rcpp::NumericVector rn(5);
>>
>> +for (int i=0; i< 5; i++) {
>>
>> +rn(i) = rnor
Of course - that did the trick. Thanks so much.
-Original Message-
From: Rodney Sparapani [mailto:rspar...@mcw.edu]
Sent: Tuesday, September 25, 2012 2:53 PM
To: Goldfeld, Keith
Cc: 'rcpp-devel@lists.r-forge.r-project.org'
Subject: Re: [Rcpp-devel] NumericVector Double mismatch when ind
On 09/25/2012 01:37 PM, Goldfeld, Keith wrote:
code<- 'Rcpp::RNGScope scope;
+Rcpp::NumericVector rn(5);
+for (int i=0; i< 5; i++) {
+rn(i) = rnorm(1,0,1);
+}
+return Rcpp::wrap(rn);
I am a new Rcpp user, and I have been trying to do a simple exercise of
generating random numbers to put into a vector. To start off, the following
code works:
> code <- 'Rcpp::RNGScope scope;
+ Rcpp::NumericVector rn(5);
+ rn = rnorm(5,0,1);
+ return Rcpp::wrap(rn);
17 matches
Mail list logo