From 7baa48745868bf6bf5611c647b28a65702fa489b Mon Sep 17 00:00:00 2001 From: Yichao Yu Date: Thu, 14 Sep 2017 18:56:02 -0400 Subject: [PATCH] Fix most of depwarns and errors on 0.7 * The adjoint overloading is a serious type piracy * The `current_module()` depwarn is not fixed since fixing it requires threading the module over all functions in an API visible way. --- src/Calculus.jl | 1 - src/derivative.jl | 6 +++++- test/derivative.jl | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Calculus.jl b/src/Calculus.jl index 5cd4fdf..19d03ff 100644 --- a/src/Calculus.jl +++ b/src/Calculus.jl @@ -2,7 +2,6 @@ isdefined(Base, :__precompile__) && __precompile__() module Calculus import Compat - import Base.ctranspose export check_derivative, check_gradient, check_hessian, diff --git a/src/derivative.jl b/src/derivative.jl index c7d9d31..bee2e04 100644 --- a/src/derivative.jl +++ b/src/derivative.jl @@ -23,7 +23,11 @@ function Base.gradient(f, dtype::Symbol = :central) Calculus.gradient(f,dtype) end -ctranspose(f::Function) = derivative(f) +if isdefined(Base, :adjoint) + Base.adjoint(f::Function) = derivative(f) +else + Base.ctranspose(f::Function) = derivative(f) +end function jacobian{T <: Number}(f, x::Vector{T}, dtype::Symbol) finite_difference_jacobian(f, x, dtype) diff --git a/test/derivative.jl b/test/derivative.jl index 02117d0..05096a8 100644 --- a/test/derivative.jl +++ b/test/derivative.jl @@ -14,7 +14,7 @@ f2(x::Vector) = sin(x[1]) @test norm(derivative(f2, :vector, :central)([0.0]) .- cos(0.0)) < 10e-4 # -# ctranspose overloading +# adjoint overloading # f3(x::Real) = sin(x)