-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Crash with argsort()
on an rarray
but not a column major xarray
#113
Comments
Trying to convert it directly into a // [[Rcpp::depends(xtensor)]]
// [[Rcpp::plugins(cpp14)]]
#include <xtensor-r/rarray.hpp>
#include <xtensor/xsort.hpp>
#include <xtensor/xio.hpp>
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
SEXP argsort_test_rarray() {
xt::rarray<int> x =
{{{1, 2, 3}, {4, 5, 6}},
{{7, 8, 9}, {10, 11, 12}}};
xt::rarray<int> x_sort = xt::argsort(x, 0);
return x_sort;
} |
Going through the stack of: i.e. all of these results look correct // [[Rcpp::depends(xtensor)]]
// [[Rcpp::plugins(cpp14)]]
#include <xtensor-r/rarray.hpp>
#include <xtensor/xsort.hpp>
#include <xtensor/xio.hpp>
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
SEXP argsort_long_route(xt::rarray<int> x, std::ptrdiff_t axis) {
// Go through xarray
xt::xarray<int, xt::layout_type::column_major> x_xarray(x);
// Call argsort() on the xarray
xt::xarray<int, xt::layout_type::column_major> x_sort = xt::argsort(x_xarray, axis);
// Back to an rarray
xt::rarray<int> x_rarray(x_sort);
return x_rarray;
} Rcpp::sourceCpp("~/Desktop/test.cpp")
x <- array(c(1:6, 12:7), c(2,3,2))
x
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 1 3 5
#> [2,] 2 4 6
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 12 10 8
#> [2,] 11 9 7
argsort_long_route(x, 0)
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 0 0 0
#> [2,] 1 1 1
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 1 1 1
#> [2,] 0 0 0
argsort_long_route(x, 1)
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 0 1 2
#> [2,] 0 1 2
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 2 1 0
#> [2,] 2 1 0
argsort_long_route(x, 2)
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 0 0 0
#> [2,] 0 0 0
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 1 1 1
#> [2,] 1 1 1 Created on 2019-04-24 by the reprex package (v0.2.1.9000) |
For some reason, calling
argsort()
on an rarray like this one crashes, but works on a column major xarray.The text was updated successfully, but these errors were encountered: