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

hmin and / or imin #18

Open
dcampora opened this issue Jul 13, 2020 · 1 comment
Open

hmin and / or imin #18

dcampora opened this issue Jul 13, 2020 · 1 comment

Comments

@dcampora
Copy link

Hi there,

Thanks a lot for your work on std-simd, it's looking very well so far!

I was attempting my first code at using your library. I have previously used Vc, as well as other vectorization libraries. I bumped into the following use-case: I would like to calculate the index of the lowest element in a vector, out of some active elements in a mask. Looking at the following document:

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/n4808.pdf

I found that there is hmin, which can accept a const_where_expression, which sort-of does what I want but not quite, since this returns the value of the lowest element, not the index. In order to further fetch the index, I figured one can create yet another mask comparing with the obtained value, and then find the index of that. Ie. see the following pseudo-code:

Testcase

const auto best_scatter = std::experimental::parallelism_v2::hmin(std::experimental::const_where_expression(mask, scatter));
const auto best_mask = best_scatter == scatter;
const auto best_scatter_index = std::experimental::parallelism_v2::find_first_set(best_mask);

With this, I have two questions:

  • I cannot find hmin anywhere in the library. Perhaps I am looking at an outdated documentation?
  • The above code looks cumbersome. Would you suggest a better practice using std-simd?
@boblytton
Copy link

As a user, having member functions simd::min_element & simd::max_element instead of hmin and hmax would reduce my cognitive burden. They would give a nod to the std algorithms that return by iterator rather than value.

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