Calculus.jl icon indicating copy to clipboard operation
Calculus.jl copied to clipboard

Calculus breaks Base.gradient function with ambiguous methods

Open david-pl opened this issue 7 years ago • 1 comments

Since a recent update, there seems to be a problem with the gradient fucntion.

The following works fine:

julia> gradient([1:3;])
3-element Array{Float64,1}:
 1.0
 1.0
 1.0

julia> using Calculus

julia> gradient([1:3;])
3-element Array{Float64,1}:
 1.0
 1.0
 1.0

However, if Calculus is used before calling gradient, you get

julia> using Calculus

julia> gradient([1:3;])
ERROR: MethodError: gradient(::Array{Int64,1}, ::Array{Int64,1}) is ambiguous. Candidates:
  gradient(f, x::Union{Array{T,1}, T}) where T<:Number in Calculus at /home/david/.julia/v0.6/Calculus/src/derivative.jl:17
  gradient(F::AbstractArray{T,1} where T, h::Array{T,1} where T) in Base.LinAlg at linalg/dense.jl:186
Possible fix, define
  gradient(::AbstractArray{T,1} where T, ::Array{T<:Number,1})
Stacktrace:
 [1] gradient(::Array{Int64,1}) at ./linalg/generic.jl:282

Even directly calling the function from base with Base.LinAlg.gradient throws the above error. I am using v"0.3.1", but this also happens when pinning to v"0.3.0". Older version fail to pre-compile with Julia 0.6.2.

david-pl avatar May 07 '18 12:05 david-pl

This is a bug. Calculus should not be extending Base.gradient.

mlubin avatar May 12 '18 14:05 mlubin