[Rcpp-devel] NumericVector
James Li
jamesyili at gmail.com
Fri Aug 16 19:39:21 CEST 2013
Hi Romain and Dirk,
Sorry I did not see Romain's earlier response. That is very helpful!
Thank you both for your prompt assistance and for developing such a useful
tool.
-James
On Friday, August 16, 2013, Dirk Eddelbuettel wrote:
>
> Hi James,
>
> On 16 August 2013 at 12:57, James Li wrote:
> | Hi Dirk,
> |
> | N could be anywhere between 3-10.
>
> Eek. 10 is a lot.
>
> | Thanks! I will definitely look into how to do those.
> |
> | Also, if
> |
> | Rcpp::NumericVector vec3 =Rcpp::NumericVector( Rcpp::Dimension(4, 5, 6));
> |
> | In this case, how do we access element vec3[1,2,3]?
>
> Well a) you cannot use [] to index, only () as the [] only allows a single
> index (and , is a special operator for C/C++). Romain already sent you a
> first cut at something homegrown.
>
> Alternatively, if you find a matrix library dealing with N up to 10 ... you
> may want to consider writing glue code to access it from R via Rcpp.
>
> Cheers, Dirk
>
> | Thanks again,
> | James
> |
> | On Friday, August 16, 2013, Dirk Eddelbuettel wrote:
> |
> |
> | Hi James,
> |
> | On 16 August 2013 at 11:59, James Li wrote:
> | | Dear Dirk and Rcpp-devel members,
> | |
> | | I am currently passing a multidimensional (N > 2) array (i.e.
> | | array(NA, dim = rep(3,5)) ) from R via Rcpp using
> |
> |
> | How big is 'N' going to be?
> |
> | | "in C++:"
> | |
> | | //[[Rcpp::export]]
> | | Rcpp::List check_arrayC (Rcpp::NumericVector x, Rcpp::IntegerVector
> | modes){
> | | //do stuff to x
> | | return Rcpp::List::create(Rcpp::_["data"] = x,
> Rcpp::_["modes"] =
> | modes);
> | | }
> | |
> | |
> | | "in R:"
> | |
> | | a <- array(1:32, dim=rep(2,5))
> | | b <- check_arrayC(a, dim(a))
> | |
> | | While I know that a multidimensional array is stored as a
> contiguous
> | | array internally, is there currently a more natural/efficient way
> to
> | | pass it back and forth within Rcpp?
> | |
> | | Also from Dirk's book, it seems that an instance of
> | | Rcpp::NumericVector can be instantiated into a multidimensional
> array
> | | via
> | |
> | | Rcpp::NumericVector vec3 =Rcpp::NumericVector( Rcpp::Dimension(4,
> 5, 6));
> | |
> | | In this case, how do we access element vec3[1,2,3]?
> | |
> | | Some background about what I am trying to do: I would like to
> create a
> | | multidimensional array wrapper class around the base R multi-way
> array
> | | class. I would also like to be able to pass this multidimensional
> | | array via Rcpp to do all the heavy-lifting in c++. Ideally, I could
> | | also convert the mda into a Boost::multi_array.
> |
> | For a moderately-sized project (at work, not open source) I had a
> very good
> | experience using Armadillo 'cubes' (3-d matrices) which I
> occassionally
> | stored in 'fields' (which I though of as lists of such cubes). I
> think in
> | most (all?) cases I reduces data to 2-d matrices before returning
> that
> | R. That worked great.
> |
> | Beyond that ... you are on your own as there is very little C++
> support
> | already useable by Rcpp. You'd have to write custom as<>() and
> wrap()
> | methods (which is not hard and may well be worth it).
> |
> | Cheers, Dirk
> |
> | | Thanks in advance for any help.
> | |
> | | -James
> | |
> | | --
> | | James Li | Ph.D. Candidate | http://jamesyili.com/
> | | Dept. of Statistical Science | Cornell University
> | | _______________________________________________
> | | Rcpp-devel mailing list
> | | Rcpp-devel at lists.r-forge.r-project.org <javascript:;>
> | |
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
> |
> | --
> | Dirk Eddelbuettel | edd at debian.org <javascript:;> |
> http://dirk.eddelbuettel.com
> |
> |
> |
> | --
> | James Li | Ph.D. Candidate | http://jamesyili.com/
> | Dept. of Statistical Science | Cornell University
>
> --
> Dirk Eddelbuettel | edd at debian.org <javascript:;> |
> http://dirk.eddelbuettel.com
>
--
James Li *|* Ph.D. Candidate *|* http://jamesyili.com/
Dept. of Statistical Science *|* Cornell University
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20130816/76ae9113/attachment-0001.html>
More information about the Rcpp-devel
mailing list