JuliaLang / julia

The Julia Programming Language
https://julialang.org/
MIT License
45.72k stars 5.48k forks source link

Change in element type of `setdiff` output from Julia 1.7 to 1.8 #46657

Open mtfishman opened 2 years ago

mtfishman commented 2 years ago

In Julia 1.7 I see:

julia> setdiff([1, 2, 3], [1.0, 2.0])
1-element Vector{Int64}:
 3

julia> versioninfo()
Julia Version 1.7.3
Commit 742b9abb4d (2022-05-06 12:58 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Xeon(R) E-2176M  CPU @ 2.70GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, skylake)
Environment:
  JULIA_EDITOR = vim

while in Julia 1.8 I see:

julia> setdiff([1, 2, 3], [1.0, 2.0])
1-element Vector{Float64}:
 3.0

julia> versioninfo()
Julia Version 1.8.0
Commit 5544a0fab76 (2022-08-17 13:38 UTC)
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 6 × Intel(R) Xeon(R) E-2176M  CPU @ 2.70GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-13.0.1 (ORCJIT, skylake)
  Threads: 1 on 6 virtual cores
Environment:
  LD_PRELOAD = libgtk3-nocsd.so.0
  LD_LIBRARY_PATH = /usr/lib/x86_64-linux-gnu/libcutensor/11.1/:/opt/intel/compilers_and_libraries_2020.0.166/linux/tbb/lib/intel64_lin/gcc4.7:/opt/intel/compilers_and_libraries_2020.0.166/linux/compiler/lib/intel64_lin:/opt/intel/compilers_and_libraries_2020.0.166/linux/mkl/lib/intel64_lin::/home/mfishman/software/itensor/lib
  JULIA_EDITOR = vim

This broke some code in ITensors.jl which implicitly assumed the previous behavior. It's not hard to work around this and I'm not sure if there was an implied guarantee that this wouldn't change from version to version, I'm curious to hear if this was intended/what led to this change.

The behavior of 1.7 makes more sense to me since setdiff outputs the elements unique to the first input, so it seems like it should have the same element type as the first input.

KristofferC commented 2 years ago

https://github.com/JuliaLang/julia/issues/45511

Seelengrab commented 2 years ago

I don't have 1.7 installed, but I'm curious what you get for this:

julia> setdiff([1,2,3], Float64[1,2,3.1], ['a', 'b', 'c'])
1-element Vector{Any}:
 3
mtfishman commented 2 years ago

On Julia 1.7 I get:

julia> setdiff([1,2,3], Float64[1,2,3.1], ['a', 'b', 'c'])
1-element Vector{Int64}:
 3

and on Julia 1.8 I get:

julia> setdiff([1,2,3], Float64[1,2,3.1], ['a', 'b', 'c'])
1-element Vector{Any}:
 3
rfourquet commented 2 years ago

This was changed in #41769. Fwiw, I think changing the eltype of the result was a mistake (https://github.com/JuliaLang/julia/pull/41769#issuecomment-898436916). You also now get things like

julia> intersect(BitSet(1:4), (x for x in 1:1))
Set{Any} with 1 element:
  1