Stream: helpdesk (published)

Topic: is this a bug in `symdiff` ?


view this post on Zulip pg. (Mar 12 2022 at 21:25):

julia> a = [1,2,3]
3-element Vector{Int64}:
 1
 2
 3

julia> b = [3,4,4,5,6]
5-element Vector{Int64}:
 3
 4
 4
 5
 6

julia> symdiff(a,b)
4-element Vector{Int64}:
 1
 2
 5
 6

I would expect the result to be 1,2,4,5,6.

view this post on Zulip pg. (Mar 12 2022 at 21:34):

if a,b are sets the result is correct

julia> symdiff(Set(a),Set(b))
Set{Int64} with 5 elements:
  5
  4
  6
  2
  1

view this post on Zulip Brian Chen (Mar 12 2022 at 21:40):

Going one level down in the call stack:

julia> symdiff!(Int[], [1, 2, 3], [3, 4, 5, 6])
5-element Vector{Int64}:
 1
 2
 4
 5
 6

julia> symdiff!(Int[], [1, 2, 3], [3, 4, 4, 5, 6])
4-element Vector{Int64}:
 1
 2
 5
 6

view this post on Zulip Brian Chen (Mar 12 2022 at 21:41):

And one more (ref. https://github.com/JuliaLang/julia/blob/master/base/array.jl#L2666-L2667):

julia> symdiff!(Set{Int}(), Int[], [1, 2, 3], [3, 4, 5, 6])
Set{Int64} with 5 elements:
  5
  4
  6
  2
  1

julia> symdiff!(Set{Int}(), Int[], [1, 2, 3], [3, 4, 4, 5, 6])
Set{Int64} with 4 elements:
  5
  6
  2
  1

view this post on Zulip pg. (Mar 12 2022 at 21:45):

thanks! seems like it should call union(setdiff(a,b),setdiff(b,a)) or call symdiff! with the larger vector first

I opened an issue here: https://github.com/JuliaLang/julia/issues/44591

view this post on Zulip Brian Chen (Mar 12 2022 at 21:47):

Great, will post my findings on the issue then.

view this post on Zulip pg. (Mar 12 2022 at 21:48):

thank you!


Last updated: Nov 22 2024 at 04:41 UTC