Skip to content

Commit 94a3685

Browse files
remove df
1 parent a9d8d01 commit 94a3685

File tree

1 file changed

+19
-28
lines changed

1 file changed

+19
-28
lines changed

src/jacobians.jl

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,29 @@
11
# Compute the Jacobian matrix of a real-valued callable f.
22
function finite_difference_jacobian(f, x::AbstractArray{<:Number},
3-
fdtype::DataType=Val{:central}, funtype::DataType=Val{:Real}, wrappertype::DataType=Val{:Default},
4-
fx::Union{Void,AbstractArray{<:Number}}=nothing, epsilon::Union{Void,AbstractArray{<:Real}}=nothing, returntype=eltype(x),
5-
df::Union{Void,AbstractArray{<:Number}}=nothing)
3+
fdtype::DataType=Val{:central}, funtype::DataType=Val{:Real},
4+
wrappertype::DataType=Val{:Default},
5+
fx::Union{Void,AbstractArray{<:Number}}=nothing, epsilon::Union{Void,AbstractArray{<:Real}}=nothing, returntype=eltype(x))
66

77
J = zeros(returntype, length(x), length(x))
8-
finite_difference_jacobian!(J, f, x, fdtype, funtype, wrappertype, fx, epsilon, returntype, df)
8+
finite_difference_jacobian!(J, f, x, fdtype, funtype, wrappertype, fx,
9+
epsilon, returntype)
910
end
1011

11-
function finite_difference_jacobian!(J::AbstractMatrix{<:Number}, df::AbstractVector, f, x::AbstractArray{<:Number},
12-
fdtype::DataType=Val{:central}, funtype::DataType=Val{:Real}, wrappertype::DataType=Val{:Default},
13-
fx::Union{Void,AbstractArray{<:Number}}=nothing, epsilon::Union{Void,AbstractArray{<:Number}}=nothing, returntype=eltype(x))
12+
function finite_difference_jacobian!(J::AbstractMatrix{<:Number}, f,
13+
x::AbstractArray{<:Number},
14+
fdtype::DataType=Val{:central}, funtype::DataType=Val{:Real},
15+
wrappertype::DataType=Val{:Default},
16+
fx::Union{Void,AbstractArray{<:Number}}=nothing,
17+
epsilon::Union{Void,AbstractArray{<:Number}}=nothing, returntype=eltype(x))
1418

15-
finite_difference_jacobian!(J, f, x, fdtype, funtype, wrappertype, fx, epsilon, returntype, df)
19+
finite_difference_jacobian!(J, f, x, fdtype, funtype, wrappertype, fx, epsilon, returntype)
1620
end
1721

18-
function finite_difference_jacobian!(J::AbstractMatrix{<:Number}, f, x::AbstractArray{<:Number},
19-
fdtype::DataType=Val{:central}, funtype::DataType=Val{:Real}, wrappertype::DataType=Val{:Default},
20-
fx::Union{Void,AbstractArray{<:Number}}=nothing, epsilon::Union{Void,AbstractArray{<:Number}}=nothing, returntype=eltype(x),
21-
df::Union{Void,AbstractArray{<:Number}}=nothing)
22-
23-
finite_difference_jacobian!(J, f, x, fdtype, funtype, wrappertype, fx, epsilon, returntype, df)
24-
end
25-
26-
function finite_difference_jacobian!(J::AbstractMatrix{<:Real}, f, x::AbstractArray{<:Real},
22+
function finite_difference_jacobian!(J::AbstractMatrix{<:Real}, f,
23+
x::AbstractArray{<:Real},
2724
fdtype::DataType, ::Type{Val{:Real}}, ::Type{Val{:Default}},
28-
fx::Union{Void,AbstractArray{<:Real}}=nothing, epsilon::Union{Void,AbstractArray{<:Real}}=nothing, returntype=eltype(x),
29-
df::Union{Void,AbstractArray{<:Real}}=nothing)
25+
fx::Union{Void,AbstractArray{<:Real}}=nothing,
26+
epsilon::Union{Void,AbstractArray{<:Real}}=nothing, returntype=eltype(x))
3027

3128
# TODO: test and rework this to support GPUArrays and non-indexable types, if possible
3229
m, n = size(J)
@@ -66,16 +63,13 @@ function finite_difference_jacobian!(J::AbstractMatrix{<:Real}, f, x::AbstractAr
6663
else
6764
fdtype_error(Val{:Real})
6865
end
69-
if typeof(df) != Void
70-
df .= diag(J)
71-
end
7266
J
7367
end
7468

75-
function finite_difference_jacobian!(J::AbstractMatrix{<:Number}, f, x::AbstractArray{<:Number},
69+
function finite_difference_jacobian!(J::AbstractMatrix{<:Number}, f,
70+
x::AbstractArray{<:Number},
7671
fdtype::DataType, ::Type{Val{:Complex}}, ::Type{Val{:Default}},
77-
fx::Union{Void,AbstractArray{<:Number}}=nothing, epsilon::Union{Void,AbstractArray{<:Real}}=nothing, returntype=eltype(x),
78-
df::Union{Void,AbstractArray{<:Number}}=nothing)
72+
fx::Union{Void,AbstractArray{<:Number}}=nothing, epsilon::Union{Void,AbstractArray{<:Real}}=nothing, returntype=eltype(x))
7973

8074
# TODO: test and rework this to support GPUArrays and non-indexable types, if possible
8175
m, n = size(J)
@@ -107,9 +101,6 @@ function finite_difference_jacobian!(J::AbstractMatrix{<:Number}, f, x::Abstract
107101
else
108102
fdtype_error(Val{:Complex})
109103
end
110-
if typeof(df) != Void
111-
df .= diag(J)
112-
end
113104
J
114105
end
115106

0 commit comments

Comments
 (0)