# Broadcasted equal of tuples

**URL:** <https://discourse.julialang.org/t/broadcasted-equal-of-tuples/5160>\
**Category:** General Usage\
**Tags:** question\
**Created:** [August 1, 2017, 6:08am UTC](https://discourse.julialang.org/t/broadcasted-equal-of-tuples/5160 "2017-08-01T06:08:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![phlavenk](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/phlavenk/32/1873_2.png) [@phlavenk](https://discourse.julialang.org/u/phlavenk)\
**Post date:** [August 1, 2017, 6:08am UTC](https://discourse.julialang.org/t/broadcasted-equal-of-tuples/5160/1 "2017-08-01T06:08:29Z")

</div>

I’m not sure this is a bug or a well though change but I see a huge discrepancy in results:

```julia
#v0.5.1 (win64, binnary):
foo = (1, 0.5)
bar = [foo, foo]
foo .== bar

2-element BitArray{1}:  
 true                   
 true

#v0.6 (win64, binnary):
foo = (1, 0.5)
bar = [foo, foo]
foo .== bar

2-element BitArray{1}:
 false                
 false            

```

Should I report an issue?

So, the solution how to treat anything as a scalar is, as suggested by @rdeits, encapsulate with `Ref(foo)`

```julia
broadcast((x,y)->println(x," -- ", y), bar, Ref(foo))

```

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [August 1, 2017, 8:16am UTC](https://discourse.julialang.org/t/broadcasted-equal-of-tuples/5160/2 "2017-08-01T08:16:47Z")

</div>

The v0.6 one is corrected. `foo[1] == 1` while `bar[1] == (1,0.5)`, so `foo[1] != bar[1]` and so it cannot `.==`.

---

<div class="post-metadata">

**Author:** ![phlavenk](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/phlavenk/32/1873_2.png) [@phlavenk](https://discourse.julialang.org/u/phlavenk)\
**Post date:** [August 1, 2017, 12:00pm UTC](https://discourse.julialang.org/t/broadcasted-equal-of-tuples/5160/3 "2017-08-01T12:00:40Z")

</div>

Ok, this decision seems right, but currently it breaks lots of my code.  
I see the broacasting of v0.5 and v0.6 are the same:

```julia
broadcast((x,y)->println(x," -- ", y), bar, foo)
(1, 0.5) -- 1                                          
(1, 0.5) -- 0.5                                        
2-element Array{Void,1}:                               
 nothing                                               
 nothing                                               

```

Just all the vectorised comparison function such as .==, .\<= etc have been in 0.5 defined separately without the broadcast machinery.

So my question is, how can I simply encapsulate the tuple to get it broadcasted as a scalar, so I can compare the whole tuple. Sure I can make the array from the “scalar” tuple by hand, but that’s just getting things complicated as I would also need to check the size of the other operands.

I’ve tried to understand how exactly the broadcast machinery works, but without a debugger I gaved up - there are just so many calls involved…  
I was thinking of some ultrathin magic container that replicates the scalar value to array of any length determined from other arguments during the broadcast call, but will not be used in the function call. Simmilar the `zeroarray` in the Images.jl package adapts its type and size to match other arguments of `channelview` function call.

The reason for this is that I’ve used tuples, arrays of tuples and dot comparisons quite often (based on the mess my test cases generated running on the 0.6 version). Thank you for any hint on to how to solve it.

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [August 1, 2017, 12:37pm UTC](https://discourse.julialang.org/t/broadcasted-equal-of-tuples/5160/4 "2017-08-01T12:37:36Z")

</div>

Try `Ref(foo)` to encapsulate `foo` as a scalar.

---

<div class="post-metadata">

**Author:** ![PabloZubieta](https://avatars.discourse-cdn.com/v4/letter/p/ee7513/32.png) [@PabloZubieta](https://discourse.julialang.org/u/PabloZubieta)\
**Post date:** [August 1, 2017, 1:20pm UTC](https://discourse.julialang.org/t/broadcasted-equal-of-tuples/5160/5 "2017-08-01T13:20:21Z")

</div>

You can use

```julia
(foo,) .== [foo, foo] #or
Ref(foo) .== [foo, foo]

```
