Closed DavisVaughan closed 5 years ago
template <typename T>
Rcpp::RObject rray__cube_impl(const xt::rarray<T>& x) {
xt::rarray<double> xt_out = xt::cube(xt::cast<double>(x));
Rcpp::RObject out = SEXP(xt_out);
out.attr("dimnames") = rray__dim_names(SEXP(x));
return out;
}
Rcpp::RObject rray__cube_impl(const xt::rarray<double>& x) {
xt::rarray<double> xt_out = xt::cube(x);
Rcpp::RObject out = SEXP(xt_out);
out.attr("dimnames") = rray__dim_names(SEXP(x));
return out;
}
// [[Rcpp::export(rng = false)]]
Rcpp::RObject rray__cube(Rcpp::RObject x) {
DISPATCH_UNARY(rray__cube_impl, x);
}
Use
xt::cube(xt::cast<double>(x))
which only results in 1 memory allocation but still has the nice properties of not integer overflowing. Base R always returns a double anyways