InitialValues.jl icon indicating copy to clipboard operation
InitialValues.jl copied to clipboard

suppport union

Open Roger-luo opened this issue 3 years ago • 3 comments

just want to make ThreadsX.reduce(union, xs) work

Roger-luo avatar Aug 21 '21 06:08 Roger-luo

Codecov Report

Merging #60 (94a1b6c) into master (cd91162) will not change coverage. The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #60   +/-   ##
=======================================
  Coverage   93.33%   93.33%           
=======================================
  Files           2        2           
  Lines          60       60           
=======================================
  Hits           56       56           
  Misses          4        4           
Flag Coverage Δ
unittests 93.33% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/InitialValues.jl 90.90% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update cd91162...94a1b6c. Read the comment docs.

codecov[bot] avatar Aug 21 '21 07:08 codecov[bot]

Thanks for the PR!

I thought it made sense, and I was about to merge it, and then realized that there was a bit of subtle issue with Numbers:

julia> union(1)
1-element Vector{Int64}:
 1

Ideally, isequal(union(INIT, x), union(x)) holds, but it wouldn't be the case here. It might still make sense but let me ponder about this a bit.


FYI, it'd be a bit more efficient if you do

using ThreadsX
using Transducers: OnInit
ThreadsX.reduce(union!, 1:10; init = OnInit(Set{Int}))

if the element type is known or

using ThreadsX
using BangBang
ThreadsX.reduce(union!!, 1:10)

if the element type is unknown. You can also do ThreadsX.Set(Iterators.flatten(xs)) if the sets you are trying to union over have "fast enough" iterate.

tkf avatar Aug 21 '21 07:08 tkf

ah thanks! I didn't know there is OnInit!

Roger-luo avatar Aug 21 '21 08:08 Roger-luo