xtensor
xtensor copied to clipboard
reshape view doesn't infer shape from -1
https://github.com/xtensor-stack/xtensor/issues/926
behold my code:
int main() {
xt::xarray<float> a = xt::zeros<float>({3, 3, 3});
auto b = xt::reshape_view(a, {3, -1});
cout << xt::adapt(a.shape()) << endl;
cout << xt::adapt(b.shape()) << endl;
}
and it's unexpected output
{3, 3, 3}
{ 3, 18446744073709551615}
While nowhere in the documentation does it claim to handle -1 as numpy does, and this is probably just my fault for assuming this, it would be very convenient if it did.
As method reshape
seems to support having one entry -1
, see docs. In my opinion reshape_view
should also support this. However, in your case -1
seems to be casted to a signed integer. So I think this is a bug. But maybe others disagree?
@tdegeus I agree with @JosephSummerhays1 I've done this several times and it's a nightmare to find when xt::xarray<T>::reshape
does it. I also find myself doing xt::reshape_view(data, {data.size() / lastAxisLength, lastAxisLength})
this is pretty ugly.