Charles L.
Charles L.

Reputation: 63

xtensor bad alloc when using trapz

I have this simple code :

xt::xarray<double> array1 = {1.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0};

auto trapz_result1 = xt::trapz(array1);

it crashes :

terminate called after throwing an instance of 'std::bad_alloc'
what():  std::bad_alloc

somewhere inside this xmath code :

xstrided_slice_vector slice1(yd.dimension(), all());
xstrided_slice_vector slice2(yd.dimension(), all());
slice1[saxis] = range(1, xnone());
slice2[saxis] = range(xnone(), yd.shape()[saxis] - 1);

auto trap = dx * (strided_view(yd, slice1) + strided_view(yd, slice2)) * 0.5;

return eval(sum(trap, {saxis}));

this crashes on eval(sum(trap, {saxis}));

I can't find any example on the internet of anyone using this function, im not entirely sure it works.

Upvotes: 0

Views: 14

Answers (0)

Related Questions