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

Regression/bug in indmin #23680

Closed
thofma opened this issue Sep 12, 2017 · 4 comments
Closed

Regression/bug in indmin #23680

thofma opened this issue Sep 12, 2017 · 4 comments

Comments

@thofma
Copy link
Contributor

thofma commented Sep 12, 2017

On 0.6:

julia> versioninfo()
Julia Version 0.6.0
Commit 9036443 (2017-06-19 13:05 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i5-3320M CPU @ 2.60GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.9.1 (ORCJIT, ivybridge)

julia> a = [4]
1-element Array{Int64,1}:
 4

julia> indmin((i for i in a))
1

Latest master:

julia> versioninfo()
Julia Version 0.7.0-DEV.1760
Commit a5e9844 (2017-09-12 16:50 UTC)
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: Intel(R) Core(TM) i5-3320M CPU @ 2.60GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.9.1 (ORCJIT, ivybridge)
Environment:

julia> a = [4]
1-element Array{Int64,1}:
 4

julia> indmin((i for i in a))
ERROR: MethodError: no method matching keys(::Base.Generator{Array{Int64,1},getfield(Main, Symbol("##1#2"))})
Closest candidates are:
  keys(::Cmd) at process.jl:826
  keys(::Tuple) at tuple.jl:41
  keys(::Tuple, ::Tuple...) at tuple.jl:47
  ...
Stacktrace:
 [1] pairs(::Base.Generator{Array{Int64,1},getfield(Main, Symbol("##1#2"))}) at ./associative.jl:137
 [2] findmin at ./array.jl:2141 [inlined]
 [3] indmin(::Base.Generator{Array{Int64,1},getfield(Main, Symbol("##1#2"))}) at ./array.jl:2198
@JeffBezanson
Copy link
Member

This was intentional. (i for i in a) doesn't have indices; e.g. getindex doesn't work on it. Could you explain the use case a bit more?

@thofma
Copy link
Contributor Author

thofma commented Sep 12, 2017

Sure. I have an array a and a function f and in 0.6 I computed indmin((f(i) for i in a)) to find the minimum of f. I know I can do indmin([f(i) for i in a]), but I wanted to avoid creating the array.

@JeffBezanson
Copy link
Member

I see. It might make sense to add a method indmin(f, a), which makes it clear that you'll get indices of a as the answer.

@laborg
Copy link
Contributor

laborg commented Feb 21, 2022

Finally this has been fixed in #34678. See also #35316 for the two arg argmax/argmin.

@laborg laborg closed this as completed Feb 21, 2022
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

3 participants