Closed DavisVaughan closed 5 years ago
I should also add that it looks like matrix and higher dimension examples are working, so its just a 1D thing.
// [[Rcpp::depends(xtensorrr)]]
// [[Rcpp::plugins(cpp14)]]
#include <xtensor/xarray.hpp>
#include <xtensor/xio.hpp>
#include <xtensor-r/rarray.hpp>
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
xt::rarray<double> rarray_matrix_sum_cpp() {
xt::rarray<double> x = {{1, 2}, {3, 4}};
xt::rarray<double> res = xt::sum(x, 0);
std::cout << res << std::endl;
return(res);
}
> rarray_matrix_sum_cpp()
{ 4., 6.}
[1] 4 6
On the top of my head, I think that the issue is that R does not really have a notion of 0-D array.
xtensor reducers in fact return an expression of dimension Original dimension - Number of reducing axes
which is 0-D when reducing over the only dimension of a 1-D array.
Maybe a way to work around this is to check if the assigned expression is 0-D and return a scalar to R in that case...
This can probably be closed b/c of pr #77
Thanks!
Hi team, I'm working through some reducer examples, and think there might be a bug with
rarray
s and reducers. First off, here is a cpp script you can hopefully use to reproduce the issue.Running
xtensor_sum_cpp()
is fine. We see the10
result.Running
rarray_sum_cpp()
is...problematic. I can't try to do the same example and print outres
. That crashes for me. What I can do is convertres
toSEXP
and try to print that out. Strangely I getNULL
.I'm allowing 1D arrays in
rray
again, so this would be an issue (previously i removed them).Any ideas?