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

union(a,b) return type should be the same as union(b,a) #29481

Open
dlfivefifty opened this issue Oct 2, 2018 · 6 comments
Open

union(a,b) return type should be the same as union(b,a) #29481

dlfivefifty opened this issue Oct 2, 2018 · 6 comments
Milestone

Comments

@dlfivefifty
Copy link
Contributor

This is surprising:

julia> union([1,2,3], Set([4,5,6]))
6-element Array{Int64,1}:
 1
 2
 3
 4
 5
 6

julia> union(Set([4,5,6]), [1,2,3])
Set([4, 2, 3, 5, 6, 1])

In the process of fixing this, I'd propose support more general union types (like Intervals, see JuliaMath/IntervalSets.jl#41) I'd propose redesigning union to use a lazy Unioned intermediary that mimics Broadcasted. I might make a proof-of-concept in LazyArrays.jl.

CC @timholy

@oscardssmith
Copy link
Member

Union and intersection should probably always return sets. It's almost always the most efficient method, and it would improve consistency.

@StefanKarpinski
Copy link
Member

For better or for worse, this is pretty much written in stone until 2.0.

@dlfivefifty
Copy link
Contributor Author

For better or for worse, this is pretty much written in stone until 2.0.

Sure, this can wait til 2.0. In the meantime I'll do a proposed "replacement" in LazyArrays.jl that can be considered for moving into Base when 2.0 development starts.

Union and intersection should probably always return sets

I assume you mean a subtype of AbstractSet: if we have sparse vectors a Set won't necessarily be the most efficient. I'm also not sure this works when its infinite sets like intervals, where the elements cannot be enumerated, but that depends on the currently undefined definition of AbstractSet.

@StefanKarpinski StefanKarpinski added this to the 2.0+ milestone Oct 2, 2018
@oscardssmith
Copy link
Member

Yeah, that's probably true.

@matbesancon
Copy link
Contributor

at least it can be specified in the docstrings, something like union(S{A},I{B}) -> S{C} where elements of both types A and B are promotable/convertible to C

@dlfivefifty
Copy link
Contributor Author

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

4 participants