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

Support for argmin, argmax? #183

Open
pitsianis opened this issue Nov 29, 2021 · 2 comments
Open

Support for argmin, argmax? #183

pitsianis opened this issue Nov 29, 2021 · 2 comments

Comments

@pitsianis
Copy link

pitsianis commented Nov 29, 2021

As the title says, is there a way to support ThreadsX.argmin and ThreadsX.argmax?
Sorry I am too new with Julia to be able to help.

The way I see it is to define the argmax reduction

oneargmax((mxi,mx),(i,ai)) = (mx<ai) ? (i,ai) : (mxi,mx)

# but I do not know how to define the generic initial value for the foldl/reduce  in ThreadsX
myargmax(f, itr; init=(nothing,-1)) = ThreadsX.mapreduce(identity, oneargmax, zip(itr,Iterators.map(f,itr)); simd = Val(true), init)
@tkf
Copy link
Owner

tkf commented Nov 30, 2021

I think I didn't implement them since there was no argmax(f, xs) etc. in Base before Julia 1.7. Now that we already have 1.7-rc, I think it's safe to implement them here.

I think your function is a useful implementation, but, to nitpick, we need to use isless instead of < for Base-compatibility.

@pitsianis
Copy link
Author

You are not nitpicking, you are informing.
I have resolved my need for this with explicit initial values and I am getting great performance from an old Xeon Phi with 256 threads

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