8000 Keep dims by JohanMabille · Pull Request #1474 · xtensor-stack/xtensor · GitHub
[go: up one dir, main page]

Skip to content

Keep dims #1474

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

Merged
merged 7 commits into from
Mar 27, 2019
Merged

Keep dims #1474

merged 7 commits into from
Mar 27, 2019

Conversation

JohanMabille
Copy link
Member

No description provided.

@JohanMabille JohanMabille merged commit 29a4290 into xtensor-stack:master Mar 27, 2019
@JohanMabille JohanMabille deleted the keep_dims branch March 27, 2019 15:58
@DavisVaughan
Copy link
Contributor

Oooooh I've been waiting on this one for awhile. Any advice on how to use it, for dummies?

@JohanMabille
Copy link
Member Author
JohanMabille commented Mar 27, 2019

Here is a simple example:

xt::xtensor<double, 4> a = xt::reshape_view(xt::arange<double>(5 * 5 * 5 * 5), {5, 5, 5, 5});

auto res = xt::sum(a, {0, 2}, xt::keep_dims | xt::evaluation_strategy::immediate | initial(5));   
auto reso = xt::sum(a, {0, 2}, xt::keep_dims | xt::evaluation_strategy::immediate);
bool check = (res == reso); // check is true

@DavisVaughan
Copy link
Contributor

So it has to have an evaluation strategy to be able to specify keep_dims. So, for instance, argmin() won't be able to do it?

@JohanMabille
Copy link
Member Author

There is an default evaluation strategy (lazy), you don't have to specify it:

xt::xtensor<double, 4> a = xt::reshape_view(xt::arange<double>(5 * 5 * 5 * 5), {5, 5, 5, 5});

auto res = xt::sum(a, {0, 2}, xt::keep_dims | initial(5));   
auto reso = xt::sum(a, {0, 2}, xt::keep_dims);
bool check = (res == reso); // check is true

Sorry for the confusion, it was a copy paste from a unit test.
However, argmin is not a reducer, thus it does not really make sense to define and use keep_dims for it.

@DavisVaughan
Copy link
Contributor

Just FYI, I just ran into this open numpy issue regarding adding keepdim to argmin. So it is something they have thought about! numpy/numpy#8710

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

Successfully merging this pull request may close these issues.

3 participants
0