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

lack of functionality in "unravel" function #1792

Open
tort-dla-psa opened this issue Nov 1, 2019 · 3 comments
Open

lack of functionality in "unravel" function #1792

tort-dla-psa opened this issue Nov 1, 2019 · 3 comments

Comments

@tort-dla-psa
Copy link

@tort-dla-psa tort-dla-psa commented Nov 1, 2019

In numpy we have this:

>>>np.unravel_index(0, [1,32,32,1])
(0, 0, 0, 0)

>>>np.unravel_index([0,1,2], [1,32,32,1])
(array([0, 0, 0]), array([0, 0, 0]), array([0, 1, 2]), array([0, 0, 0]))

But in xtensor we can only use unravel with one index. Also we'll get by this not an xarray of
dimensions, but this:

"xt::get_strides_t<std::vector<int, std::allocator>>"

Why is it so?

@tort-dla-psa
Copy link
Author

@tort-dla-psa tort-dla-psa commented Nov 1, 2019

also there's nothing about unravel in the docs

@tort-dla-psa
Copy link
Author

@tort-dla-psa tort-dla-psa commented Nov 1, 2019

there is a closed issue about unravel docs, but still no docs for it #1309

@tdegeus
Copy link
Member

@tdegeus tdegeus commented Nov 1, 2019

As far as I can see there is an xt::unravel_indices(...) to do what you want. It's output can be converted to a 'normal' matrix using xt::from_indices(...). E.g.

xt::xtensor<size_t,2> a = xt::zeros<size_t>({5, 2});
xt::xtensor<size_t,1> i = {0, 1, 2, 3};
xt::xtensor<size_t,2> idx = xt::from_indices(xt::unravel_indices(i, a.shape()));
std::cout << idx << std::endl;

But I do agree that we need to work on consistency with NumPy here. Also I feel that the overloads are not super flexible.

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

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.