Buffer size of strided adapters?
I tried to adapt a splat tensor. However, xtensor threw a runtime error with message xbuffer_storage not resizable. It seems that xtensor expects that buffer size equals to tensor size. I don't think that would be the case with user-provided strides.
#include <xtensor/xadapt.hpp>
#include <xtensor/xio.hpp>
#include <array>
int main()
{
const float data = 1;
const std::array<int, 2> shape = { 2, 2 };
const std::array<int, 2> strides = { 0, 0 };
// Expected
std::cout << xt::adapt(&data, 1, xt::no_ownership(), shape, strides) << '\n';
// Actual working
std::cout << xt::adapt(&data, 4, xt::no_ownership(), shape, strides) << '\n';
}
The error makes sense. You are using the following overload
https://github.com/xtensor-stack/xtensor/blob/308458574baa95b0dabb981a4bae97fa29ff673f/include/xtensor/xadapt.hpp#L161
In this case the size has to match up prod(shape) = 4. The error is telling you exactly that: your shape is not corresponding to your size.
But you had realised this. Instead, you want to pretend to have more entries than you have (let's say broadcast) by setting (one of) the stride(s) to zero. Well, yes, I do agree that that should be legal. Personally I would say that the size argument is useless and pedantically checking the user, thereby limiting potential legal use cases (regardless wether we like them or not ;)). Given that it is there, indeed, I think that we should consider that strides makes this case legal.
P.S. The fastest way to getting this implemented is to open a PR ;)