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

Implement argmin and argmax #701

Open
willow-ahrens opened this issue Feb 12, 2025 · 0 comments · May be fixed by #705
Open

Implement argmin and argmax #701

willow-ahrens opened this issue Feb 12, 2025 · 0 comments · May be fixed by #705

Comments

@willow-ahrens
Copy link
Collaborator

willow-ahrens commented Feb 12, 2025

The idea is to first use minby to compute the argmin, then return just the coordinates of the minimum. In python, we only need to handle a single axis (https://numpy.org/doc/2.1/reference/generated/numpy.argmin.html). In Julia, there may be multiple axes, in which case the index used is an e.g. CartesianIndex(i, j) (https://docs.julialang.org/en/v1/base/collections/#Base.argmin). The minby function is described here: https://finch-tensor.github.io/Finch.jl/stable/docs/user-defined_functions/#Finch.minby

An example of a one-dimensional argmin is:

A = Scalar((Inf, 0))
@finch begin
    A .= (Inf, 0)
    for i = _
      A[] <<minby>>= tuple(B[i], i)
   end
end
result = A[][2]

An example of a similar function exists here: hhttps://github.com/finch-tensor/Finch.jl/blob/2e89d2228a777a8238eccd145cfa6a7b405eb76c/src/interface/compare.jl#L1-L28

You may find some of these docs to be helpful:
https://finch-tensor.github.io/Finch.jl/stable/docs/internals/virtualization/

@01110011011101010110010001101111 01110011011101010110010001101111 linked a pull request Feb 23, 2025 that will close this issue
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 a pull request may close this issue.

1 participant