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

Uninitialised output 'argsort' #2237

Open
tdegeus opened this issue Nov 29, 2020 · 2 comments
Open

Uninitialised output 'argsort' #2237

tdegeus opened this issue Nov 29, 2020 · 2 comments
Labels

Comments

@tdegeus
Copy link
Member

tdegeus commented Nov 29, 2020

This

#include <xtensor.hpp>

int main()
{
    xt::xtensor<double, 2> A = {{1.0, 1.0, 1.0, 1.0}};
    auto isort = xt::argsort(A, 1);
    std::cout << isort << std::endl;

    return 0;
}

gives incorrect output:

{{0, 0, 0, 0}}

while

#include <xtensor.hpp>

int main()
{
    xt::xtensor<double, 2> A = {{1.0, 1.0, 1.0, 1.0},
                                {1.4, 1.3, 1.2, 1.1}};
    auto isort = xt::argsort(A, 1);
    std::cout << isort << std::endl;

    return 0;
}

does give reasonable output:

{{0, 1, 2, 3},
 {3, 2, 1, 0}}

Also in my original problem:

    auto eps = GM::Epsd(this->plastic_Eps());
    auto epsy = this->plastic_CurrentYieldRight();
    std::cout << eps << std::endl;
    std::cout << epsy << std::endl;
    std::cout << xt::adapt(eps.shape()) << std::endl;
    std::cout << xt::adapt(epsy.shape()) << std::endl;
    auto deps = xt::eval(epsy - eps);
    auto isort = xt::argsort(deps, 1);
    std::cout << deps << std::endl;
    std::cout << isort << std::endl;

I'm getting

{{ 0.,  0.,  0.,  0.}}
{{ 1.,  1.,  1.,  1.}}
{1, 4}
{1, 4}
{{ 1.,  1.,  1.,  1.}}
{{13835058055282163712, 13835058055282163712, 4, 0}}
@tdegeus tdegeus changed the title Uninitialised output 'argsort'? Uninitialised output 'argsort' Nov 29, 2020
@tdegeus
Copy link
Member Author

tdegeus commented Nov 29, 2020

See #2238

@ImNotMT
Copy link

ImNotMT commented Mar 18, 2021

so far still not fixed. this bug is caused the following (for argsort(axis=1)):
when xarray.shape(0) is 1, both data_secondary_stride and inds_secondary_strideis would be 0.
the following functions will not do anything since range from indices_ptr to indices_ptr + 0 is 0.
std::iota(indices_ptr, indices_ptr + inds_secondary_stride, 0);
std::sort(indices_ptr, indices_ptr + inds_secondary_stride, comp);

for walk around, I have to flatten input xarray first if its shape(0) is 1, and add newaxis to the output of argsort.

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

No branches or pull requests

3 participants