xtensor-stack / xtensor-python

Python bindings for xtensor
BSD 3-Clause "New" or "Revised" License
348 stars 58 forks source link

Bug in sort #262

Open tdegeus opened 3 years ago

tdegeus commented 3 years ago

The following code

#include <xtensor.hpp>
#include <pybind11/pybind11.h>

namespace py = pybind11;

#define FORCE_IMPORT_ARRAY
#include <xtensor-python/pyarray.hpp>
#include <xtensor-python/pytensor.hpp>

template <class T>
inline auto foo(const T& arg)
{
    return xt::sort(arg);
}

PYBIND11_MODULE(mymodule, m)
{
    xt::import_numpy();
    m.doc() = "Module description";
    m.def("foo", &foo<xt::pytensor<size_t, 1>>, "Function description", py::arg("arg"));
}

Gives:

...\include\xtensor\xsort.hpp(155,31): error C2397: conversion from 'unsigned __int64' to '_Ty' requires a narrowing conversion with
          [
              _Ty=ptrdiff_t
          ]
...\include\xtensor\xsort.hpp(204): message : see reference to function template instantiation 'auto xt::detail::flat_sort_impl<xt::pytensor<size_t,1,xt::layout_type::dynamic>,eval_type>(const xt::xexpression<D> &)' being compiled with
          [
              D=xt::pytensor<size_t,1,xt::layout_type::dynamic>
          ]
...\main.cpp(13): message : see reference to function template instantiation 'auto xt::sort<D>(const xt::xexpression<D> &,ptrdiff_t)' being compiled with
          [
              D=xt::pytensor<size_t,1,xt::layout_type::dynamic>
          ]
...\main.cpp(20): message : see reference to function template instantiation 'auto foo<xt::pytensor<size_t,1,xt::layout_type::dynamic>>(const T &)' being compiled with
          [
              T=xt::pytensor<size_t,1,xt::layout_type::dynamic>
          ]

on Windows. It works fine on macOS, and gives a very vague error message on Linux.

For full CI, see https://github.com/tdegeus/xtensor-python_examples/pull/1