xtensor
xtensor copied to clipboard
[C++20] Issues
xtensor is not tested with C++20 since C++20 is not officially out yet. However it would be nice to enable these tests as "allow to fail" and see what happens.
From #1955, the following test cases lead to segfault:
#include "xtensor/xio.hpp"
#include "xtensor/xreducer.hpp"
#include "xtensor/xarray.hpp"
#include "xtensor/xadapt.hpp"
#include <iostream>
#include <cstring>
int main(int argc, char** argv){
if (argc != 2){
printf("Pass test number as first arg\n");
return EXIT_FAILURE;
}
int case_num = atoi(argv[1]);
xt::xarray<double> xarr = {0.,1.,2.,3.,4.,5.,6.,7.,8.};
xarr.reshape({3,3});
switch (case_num){
case 1: {
auto sum = xt::sum(xarr, xt::evaluation_strategy::immediate);
std::cout << sum << std::endl;
} break;
case 4: {
auto real_sum = xt::eval(xt::sum(xarr, xt::evaluation_strategy::immediate));
std::cout << real_sum << std::endl;
} break;
// badalloc/segfault computing "square"
case 6: {
auto sum = xt::sum(xarr, xt::evaluation_strategy::immediate);
auto square = xt::square(xarr/sum);
std::cout << square << std::endl;
} break;
}
}
I'm noticing problems with xt::tile and xt::pad on gcc-10 with c++20 as well. For example, this fails with std::bad_alloc:
#include <iostream>
#include "xtensor/xtensor.hpp"
#include <xtensor/xpad.hpp>
#include "xtensor/xio.hpp"
int main(int argc, char* argv[]) {
xt::xtensor<double,2> a = {{30.0, -180.0}};
std::cout << a << std::endl;
std::cout << xt::tile(a, {10,1}) << std::endl;
}
platform: x86 xtensor: 0.21.8 xtl: 0.6.21 xsimd: 7.4.9
Do we have a workaround?
Appears to still be a problem on head?
https://godbolt.org/z/cej6eqh3b
Assigning to a view with broadcasting also does not work on GCC with C++20.
https://godbolt.org/z/3nPj8dr4v
xt::xarray<double> a = {{{0., 1., 2.}, {3., 4., 5.}}, {{6., 7., 8.}, {9., 10., 11.}}};
xt::xarray<double> b = {12., 13., 14.};
xt::strided_view(a, {1}) = b;
std::cout << a << std::endl;
// exptected:
// {{{ 0., 1., 2.},
// { 3., 4., 5.}},
// {{ 12., 13., 14.},
// { 12., 13., 14.}}}
// actual:
// {{{ 0., 1., 2.},
// { 3., 4., 5.}},
// {{ 6., 7., 8.},
// { 9., 10., 11.}}}