It is because promote_op(::Any, T) = (@_pure_meta; T)

julia> @which Base.promote_op(sin,Int64)
promote_op(::Any, T) at promotion.jl:226

julia> Base.promote_op(sin,Int64)
Int64

It seems promote_op assumes that all functions that does not specialize on 
it return element type of array.
On Friday, May 20, 2016 at 3:41:49 PM UTC+3, Scott T wrote:
>
> Noticed this when playing around with the new f.(x) syntax, which I 
> assumed would work like map.
>
> julia> map(sin, 3)
> 0.1411200080598672
>
> julia> map(sin, [3])
> 1-element Array{Float64,1}:
>  0.14112
>
> Map works like I'm used to: number goes to number, array goes to array.
>
> julia> sin.(3)  # same as broadcast(sin, 3)
> ERROR: InexactError()
>  in fill!(::Array{Int64,0}, ::Float64) at ./array.jl:155
>  in (::Base.Broadcast.#_F_#5)(::Array{Int64,0}, ::Int64) at 
> ./broadcast.jl:95
>  in broadcast!(::Function, ::Array{Int64,0}, ::Int64) at ./broadcast.jl:213
>  in broadcast(::Function, ::Int64) at ./broadcast.jl:220
>  in broadcast(::Function, ::Int64) at ./deprecated.jl:1130
>  in eval(::Module, ::Any) at ./boot.jl:225
>  in macro expansion at ./REPL.jl:92 [inlined]
>  in (::Base.REPL.##1#2{Base.REPL.REPLBackend})() at ./event.jl:46
>
> julia> sin.([3])  # same as broadcast(sin, [3])
> ERROR: InexactError()
>  in macro expansion at ./broadcast.jl:95 [inlined]
>  in macro expansion at ./cartesian.jl:64 [inlined]
>  in (::Base.Broadcast.#_F_#6)(::Array{Int64,1}, ::Array{Int64,1}) at 
> ./broadcast.jl:90
>  in broadcast!(::Function, ::Array{Int64,1}, ::Array{Int64,1}) at 
> ./broadcast.jl:213
>  in broadcast(::Function, ::Array{Int64,1}) at ./broadcast.jl:220
>  in eval(::Module, ::Any) at ./boot.jl:225
>  in macro expansion at ./REPL.jl:92 [inlined]
>  in (::Base.REPL.##1#2{Base.REPL.REPLBackend})() at ./event.jl:46
>
> Broadcast doesn't like integers in sin for some reason
>
> julia> sin.(3.)  # same as broadcast(sin, 3.)
> 0-dimensional Array{Float64,0}:
> 0.14112
>
> julia> sin.([3.])  # same as broadcast(sin, [3.])
> 1-element Array{Float64,1}:
>  0.14112
>
> And it produces a 0D array when called on a Number. So broadcast works 
> differently from map. 
>
> Is the error when called on an Int a bug, given that sin(3) is obviously 
> fine? And should calling it on a Number yield a Number or a 0D array? 
>

Reply via email to