Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xt::linalg::dot() is not working with xarray_adaptor<> when shape is 2x2 #98

Open
potpath opened this issue Feb 14, 2019 · 1 comment
Open

Comments

@potpath
Copy link
Contributor

potpath commented Feb 14, 2019

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.

@wolfv
Copy link
Member

wolfv commented Mar 7, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants