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

broadcast(== produces Vector{Real} and not Vector{Bool} #19218

Closed
mauro3 opened this issue Nov 4, 2016 · 6 comments
Closed

broadcast(== produces Vector{Real} and not Vector{Bool} #19218

mauro3 opened this issue Nov 4, 2016 · 6 comments
Labels
needs tests Unit tests are required for this change

Comments

@mauro3
Copy link
Contributor

mauro3 commented Nov 4, 2016

              _
   _       _ _(_)_     |  A fresh approach to technical computing
  (_)     | (_) (_)    |  Documentation: http://docs.julialang.org
   _ _   _| |_  __ _   |  Type "?help" for help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 0.6.0-dev.1116 (2016-10-25 02:18 UTC)
 _/ |\__'_|_|_|\__'_|  |  Commit 9a2f0f1* (10 days old master)
|__/                   |  x86_64-pc-linux-gnu

julia> (==).(Real[1],[2])
1-element Array{Real,1}:
 false

julia> Real[1].==[2]
1-element BitArray{1}:
 false

Shouldn't both return the same type? Preferably a BitArray.

@stevengj
Copy link
Member

stevengj commented Nov 4, 2016

This is mostly a duplicate of #17623; the .== functions are not yet handled by broadcast. (That PR is currently stalled until broadcast functions with sparse arrays are improved; @Sacha0 is working on that.)

One difficulty with returning BitArray is that it doesn't work easily with fusion. e.g. in #17623 z .== y & y .> 0 will be fused into a single broadcast call, specialized broadcast methods for == etcetera are not called.

One option is to always return a BitArray from broadcast operations returning Bool. However, it's not clear to me that this is a good idea. Furthermore, given fusion, it seems that the advantage of bitarrays is greatly reduced: if you are producing multiple temporary arrays, a BitArray is much more attractive, combined with the fact that .& and .| operations for bitarrays can be faster than those operations on Bool arrays.

@mauro3
Copy link
Contributor Author

mauro3 commented Nov 4, 2016

Is this not also some promotion issue? It works with Number (well it return a Vector{Bool} but that is fine too):

julia> (==).(Real[1//2, 1//2], [1,2])
2-element Array{Real,1}:
 false
 false

julia> (==).(Number[1//2, 1//2], [1,2])
2-element Array{Bool,1}:
 false
 false

@stevengj
Copy link
Member

stevengj commented Nov 4, 2016

@mauro3, ah right, I didn't notice the Vector{Real} type. That is a separate issue from whether to return BitArray. cc @pabloferz

@stevengj stevengj changed the title Dot syntax not consistent between binary op. and functional form broadcast(== produces Vector{Real} and not Vector{Bool} Nov 4, 2016
@pabloferz
Copy link
Contributor

The Vector{Real} issue should be fixed by #18642.

@stevengj
Copy link
Member

I think this can be closed now: as of #17623, broadcast always returns a BitArray for functions returning Bool.

@tkelman
Copy link
Contributor

tkelman commented Dec 21, 2016

should add tests for that, if there aren't any yet

@tkelman tkelman added the needs tests Unit tests are required for this change label Dec 21, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs tests Unit tests are required for this change
Projects
None yet
Development

No branches or pull requests

4 participants