Skip to content

Crash with argsort() on an rarray but not a column major xarray #113

@DavisVaughan

Description

@DavisVaughan

For some reason, calling argsort() on an rarray like this one crashes, but works on a column major xarray.

// [[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]]
void argsort_test_xarray() {
  xt::xarray<int, xt::layout_type::column_major> x =
    {{{1, 2, 3}, {4, 5, 6}},
     {{7, 8, 9}, {10, 11, 12}}};

  std::cout << x << std::endl;

  auto x_sort = xt::argsort(x, 0);

  std::cout << x_sort << std::endl;
}

// [[Rcpp::export]]
void argsort_test_rarray() {
  xt::rarray<int> x =
    {{{1, 2, 3}, {4, 5, 6}},
     {{7, 8, 9}, {10, 11, 12}}};

  std::cout << x << std::endl;

  auto x_sort = xt::argsort(x, 0);

  std::cout << x_sort << std::endl;
}
> Rcpp::sourceCpp('~/Desktop/test.cpp')
> argsort_test_xarray()
{{{ 1,  2,  3},
  { 4,  5,  6}},
 {{ 7,  8,  9},
  {10, 11, 12}}}
{{{0, 0, 0},
  {0, 0, 0}},
 {{1, 1, 1},
  {1, 1, 1}}}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions