Does the promote_op mechanism in v0.5 play nicely with generated functions? 
In Unitful.jl, I use a generated function to determine result units after 
computations involving quantities with units. I seem to get errors 
(@inferred tests fail) if I remove my promote_op specialization. Perhaps my 
problems are all a consequence 
of https://github.com/JuliaLang/julia/issues/18465 and they will go away 
soon...?

On Friday, September 23, 2016 at 5:54:03 AM UTC-7, Pablo Zubieta wrote:
>
> In julia 0.5 the following should work without needing doing anything to 
> promote_op
>
> import Base.+
> immutable Foo end
> +(a::Foo, b::Foo) =1.0
> Array{Foo}(0) + Array{Foo}(0))
>
> promote_op is supposed to be an internal method that you wouldn't need to 
> override. If it is not working i because the operation you are doing is 
> most likely not type stable. So instead of specializing it you could try to 
> remove any type instabilities in the method definitions over your types.
>
> On Friday, September 23, 2016 at 5:35:05 AM UTC+2, Sheehan Olver wrote:
>>
>>
>> The subject says it all: it looks like one can override promote_op to 
>> support the following behaviour:
>>
>> *julia> **import Base.+*
>>
>>
>> *julia> **immutable Foo end*
>>
>> WARNING: Method definition (::Type{Main.Foo})() in module Main at 
>> REPL[5]:1 overwritten at REPL[10]:1.
>>
>>
>> *julia> **+(a::Foo,b::Foo) = 1.0*
>>
>> *+ (generic function with 164 methods)*
>>
>>
>> *julia> **Base.promote_op(::typeof(+),::Type{Foo},::Type{Foo}) = Float64*
>>
>>
>> *julia> **Array(Foo,0) + Array(Foo,0)*
>>
>> *0-element Array{Float64,1}*
>>
>>
>> Is this documented somewhere?  What if we want to override /, -, etc., is 
>> the solution to write a promote_op for each case?
>>
>

Reply via email to