[julia-users] Re: `<` and `isless` for GradientNumber (ForwardDiff.jl)

2015-12-10 Thread Pablo Zubieta
It doesn't work with the master branch of ForwardDiff.jl neither. So I 
filled a bug report:

https://github.com/JuliaDiff/ForwardDiff.jl/issues/76


[julia-users] Re: `<` and `isless` for GradientNumber (ForwardDiff.jl)

2015-12-10 Thread Pablo Zubieta
Ok, I looked a little deeper and for some reason

<(g::GradientNumber, x::Real)

is calling

<(x::Real, y::Real) = <(promote(x,y)...)

which in the case of the example above promotes both arguments to 
GradientNumber. The method `isless(g1::GradientNumber, g2::GradientNumber)` 
is not defined in the ForwardDiff.jl version I have, but I can see that 
there seems to be a solution to this now 

.

I will try to chechout the newest version. Anyway if that doesn't fix this 
I will report the bug there.

Sorry for the noise.

Cheers,
Pablo Zubieta


[julia-users] Re: `<` and `isless` for GradientNumber (ForwardDiff.jl)

2015-12-10 Thread Pablo Zubieta
Ok, I looked a little deeper and for some reason

<(g::GradientNumber, x::Real)

is calling

<(x::Real, y::Real) = <(promote(x,y)...)

which in the case of the example above promotes both arguments to 
GradientNumber. `isless(g1::GradientNumber, g2::GradientNumber)`. This 
method is not defined in the ForwardDiff.jl version I have but I can there 
seems to be a solution to this now 

.

I will try to chechout the newest version. Anyway if that doesn't fix this 
I will report the bug there.

Sorry for the noise.

Cheers,
Pablo Zubieta



[julia-users] Re: `<` and `isless` for GradientNumber (ForwardDiff.jl)

2015-12-10 Thread Pablo Zubieta
I'm using julia 0.4.1. Here's an example

using ForwardDiff

foo(l, x) = ifelse( abs(x) < l, sin(x), cos(x) )
bar(l, x) = ifelse( isless(abs(x),l), sin(x), cos(x) )

derivative(x->foo(2,x), 1.) # ERROR: < not defined for ForwardDiff.
GradientNumber{1,Float64,Tuple{Float64}}
derivative(x->bar(2,x), 1.) # 0.5403023058681398

derivative(x->foo(2,x), 3.) # ERROR: < not defined for ForwardDiff.
GradientNumber{1,Float64,Tuple{Float64}}
derivative(x->bar(2,x), 3.) # -0.1411200080598672



immutable FooType
v
end

value(f::FooType) = f.v
Base.isless(f::FooType, x::Real) = value(f) < x
Base.isless(x::Real, f::FooType) = x < value(f)

FooType(3) < 4 # true
FooType(3) < 1 # false

1 < FooType(3) # true
3 < FooType(3) # false