[julia-users] Re: How does promote_op work?

2016-09-23 Thread Pablo Zubieta
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 operat

[julia-users] Re: How does promote_op work?

2016-09-23 Thread Andrew Keller
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 pr

[julia-users] Re: How does promote_op work?

2016-09-23 Thread Sheehan Olver
OK, here's a better example of the issue: in the following code I would want it to return an *Array(Foo,0)*, not an *Array(Any,0). *Is this possible without overriding promote_op? *julia> **immutable Foo{T}* *x::T* *end* *julia> **import Base.+* *julia> **+(a::Foo,b::Foo) =

[julia-users] Re: How does promote_op work?

2016-09-23 Thread Pablo Zubieta
Sheehan, are you planning on doing a lot of operations with empty arrays? On 0.5 with your example julia> [Foo(1), Foo(2)] + [Foo(1), Foo(0)] 2-element Array{Foo,1}: Foo{Float64}(1.0) Foo{Int64}(1) The problem is empty arrays, when the type cannot be inferred broadcast uses the types of each

[julia-users] Re: How does promote_op work?

2016-09-23 Thread Pablo Zubieta
Andrew, I do not understand the details but I believe there are some restrictions when using generated functions. You are not supposed to use functions with side effects, closures, comprehensions and functions like promote_op which rely on inference confuse inference when in generated functions

[julia-users] Re: How does promote_op work?

2016-09-24 Thread Steven G. Johnson
On Friday, September 23, 2016 at 6:15:25 PM UTC-4, Pablo Zubieta wrote: > > The problem is empty arrays, when the type cannot be inferred broadcast > uses the types of each element to build the array. When there are no > elements it doesn't know what type to choose. > (For the empty array bro

Re: [julia-users] Re: How does promote_op work?

2016-09-23 Thread Sheehan Olver
An empty array triggered a bug caused by not dispatching correctly, which I worked around with isempty. But I could have also overriden promote_op and not had to deal with empty arrays as a special case. > On 24 Sep. 2016, at 8:15 am, Pablo Zubieta wrote: > > Sheehan, are you planning on doi

Re: [julia-users] Re: How does promote_op work?

2016-09-23 Thread Pablo Zubieta
Sheehan, empty arrays are a problem in general, for now I'd say its better to handle the empty case separately for functions. Note that the only problematic case should be broadcasting with non-type stable functions over empty arrays. Unless that is extremely important for you, you might consid