# Approximate set intersection for floating point numbers

**URL:** <https://discourse.julialang.org/t/approximate-set-intersection-for-floating-point-numbers/61047>\
**Category:** General Usage\
**Tags:** question\
**Created:** [May 12, 2021, 9:40pm UTC](https://discourse.julialang.org/t/approximate-set-intersection-for-floating-point-numbers/61047 "2021-05-12T21:40:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cadojo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cadojo/32/25328_2.png) [@cadojo](https://discourse.julialang.org/u/cadojo)\
**Post date:** [May 12, 2021, 9:40pm UTC](https://discourse.julialang.org/t/approximate-set-intersection-for-floating-point-numbers/61047/1 "2021-05-12T21:40:57Z")

</div>

I have two sets of numbers, say…

```nohighlight
x = randn(1_000_000) |> Set
y = randn(1_000_000) |> Set

```

I’d like to find the **approximate** intersection of the two sets, to some tolerance. I could…

```nohighlight
for xi in x
    for yi in y
        if isapprox(xi, yi; atol = 1e-8)
            print("Intersection at ...")
        end
    end
end

```

But this is super slow, since it’s O(n^2). Integer `Set` intersection is super fast. Are there any packages that have implemented approximate set intersection for floating point types?

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [May 12, 2021, 9:45pm UTC](https://discourse.julialang.org/t/approximate-set-intersection-for-floating-point-numbers/61047/2 "2021-05-12T21:45:05Z")

</div>

Sort them both first and work through them both in order.
