Julia: Regression/bug in indmin

Created on 12 Sep 2017  Â·  3Comments  Â·  Source: JuliaLang/julia

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

Most helpful comment

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.

All 3 comments

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?

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.

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.

Was this page helpful?
0 / 5 - 0 ratings