`xt::linalg::dot()` is not working with `xarray_adaptor<>` when shape is 2x2
This is shown in the following code example.
#include "xtensor/xadapt.hpp"
#include "xtensor-blas/xlinalg.hpp"
int main()
{
std::vector<double> vec{0, 1, 2, 3};
std::vector<size_t> shape{2, 2};
auto arr = xt::adapt(
vec,
shape
);
auto arr2 = xt::adapt(
vec.data(),
vec.size(),
xt::no_ownership(),
shape,
std::vector<int>{2, 1}
);
std::cout << arr << std::endl;
std::cout << xt::linalg::dot(arr, arr) << std::endl;
std::cout << arr2 << std::endl;
std::cout << xt::linalg::dot(arr2, arr2) << std::endl;
return 0;
}
Output:
{{ 0., 1.},
{ 2., 3.}}
{{ 2., 3.},
{ 6., 11.}}
{{ 0., 1.},
{ 2., 3.}}
terminate called after throwing an instance of 'std::runtime_error'
what(): No valid layout chosen.
This is caused by the dynamic layout_type and get_leading_stride() in https://github.com/QuantStack/xtensor-blas/blob/master/include/xtensor-blas/xblas_utils.hpp#L129.
Hi @potpath indeed. We currently don't have support for dynamic layout in xtensor-blas. Also, it would be quite hard (potentially)...
We could check if the dynamic layout is in fact row- or column major (we actually do this in the view code in xtensor). If it is not, we could allocate a new container, and store the data with the default layout (however, this will have bad performance characteristics).
I think we should also make it possible to pass a layout parameter to the adapt function you're using (as last argument), I'll open a bug report on xtensor.