[Rcpp-devel] Code review for xtensor R bindings

Dirk Eddelbuettel edd at debian.org
Wed Jun 7 00:06:11 CEST 2017


Howdy,

On 6 June 2017 at 14:15, Wolf Vollprecht wrote:
| I put together a small proof of concept for the xtensor R bindings over the
| weekend. 
| It lives here: https://github.com/QuantStack/xtensor-r

Nice!  Not sure I have spare cycles right now for this but that is very welcome.
 
| xtensor is an exciting C++ library which provides a unified C++ tensor
| interface for Python/NumPy, Julia and soon R.
| 
| My biggest question is in the memory management of R. Maybe you could do a
| quick code review?
| Is it enough to call Rcpp_release_object with the SEXP in the destructor of the
| rxarray (which I haven't implemented yet)?
| Also for the shape of the rxarray, I allocate another R-vector. Is that going
| to get destroyed upon destruction of the R-array?

The general idea when working with R objects is that

  -- on the way in from R to the C++ functions we construct object such that
     the existing memory (from R) is used; one example is how RcppArmadillo
     uses the 'advanced' constructors of Armadillo allowing to operate
     without copies; hence R managed memory is used while C++ functions are
     called; in general this side of the conversion is the templates as<>()
     converters;
     
  -- on the way back we use the *alloc functions from the C-level API of R to
     construct objects that use memory from R's pool, once we return these
     objects to R as SEXP they are indistinguishable to R from its own; these
     are the wrap() functions (and I think we may make on occassion make "one
     final copy" at his level, but I'd have to double-check).     

I haven't had a chance to look at what Wes is doing with Apache Arrow, and
what is happening with xtensor -- so thanks for getting the ball rolling.

Dirk
     
-- 
http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org


More information about the Rcpp-devel mailing list