Broadcasted equal of tuples

question

#1

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

#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)

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

#2

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


#3

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:

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.


#4

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


#5

You can use

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