xtensor icon indicating copy to clipboard operation
xtensor copied to clipboard

[C++20] Issues

Open JohanMabille opened this issue 5 years ago • 3 comments

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;
	}
}

JohanMabille avatar Mar 05 '20 08:03 JohanMabille

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

jlucier avatar Nov 03 '20 20:11 jlucier

Do we have a workaround?

Appears to still be a problem on head?

https://godbolt.org/z/cej6eqh3b

lednakashim avatar Aug 23 '22 00:08 lednakashim

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.}}}

yosh-matsuda avatar Sep 10 '22 13:09 yosh-matsuda