no resize() for Rcpp's Vector

415 views
Skip to first unread message

Jiqiang Guo

unread,
May 30, 2012, 4:07:40 PM5/30/12
to stan...@googlegroups.com
You could ignore the following except if you are interested in some Rcpp stuff. 

On Wed, May 30, 2012 at 2:15 PM, Bob Carpenter <ca...@alias-i.com> wrote:
I was thinking this would mean less change to the code.
Just replace the type with a template.

I wish Rcpp had better doc!  There's nowhere to even look
up what Rcpp::NumericVector does.  The quickref:

http://cran.r-project.org/web/packages/Rcpp/vignettes/Rcpp-quickref.pdf

makes it look an awful lot like std::vector.

Of course, you can always try it.  How do you size and
add things to an Rcpp::NumericVector?

Rcpp's Vector dose not support resize():

And I verified they have not implemented a resize() and others like std::vector() so far. 
So there is no adding.  From the quickref, but it is very easy to construct one.

std::vector<double> y(10);
NumericVector xx(y.begin(), y.end());

--
Jiqiang  

Bob Carpenter

unread,
May 30, 2012, 4:35:16 PM5/30/12
to stan...@googlegroups.com
I still don't think copying is going to be that
expensive (at least for std::vector -- who knows
what Rcpp::NumericVector is up to).

From the mailing list discussion Jiqiang linked, it looks like
it might involve LESS copying to create the Rcpp::Numeric
vector from an existing std::vector rather than passing
in an Rcpp:Numeric reference as I did with std::vector (because
of the dynamic resizing required in that scenario, each of
which involves a copy, and perhaps over-allocation to boot).

That is, create the std::vector then use the iterator
begin/end constructor for Rcpp::Numeric. Hopefully they'll
do the iterator diff (end - begin) and preallocate then fill.

- Bob


-------- Original Message --------
Subject: [stan-dev] no resize() for Rcpp's Vector
Date: Wed, 30 May 2012 16:07:40 -0400
From: Jiqiang Guo <guo...@gmail.com>
Reply-To: stan...@googlegroups.com
To: stan...@googlegroups.com



You could ignore the following except if you are interested in some Rcpp
stuff.

On Wed, May 30, 2012 at 2:15 PM, Bob Carpenter <ca...@alias-i.com
<mailto:ca...@alias-i.com>> wrote:

I was thinking this would mean less change to the code.
Just replace the type with a template.

I wish Rcpp had better doc! There's nowhere to even look
up what Rcpp::NumericVector does. The quickref:


http://cran.r-project.org/web/__packages/Rcpp/vignettes/Rcpp-__quickref.pdf
Reply all
Reply to author
Forward
0 new messages