Skip to content

Commit

Permalink
microoptimizations of jacobian_2
Browse files Browse the repository at this point in the history
  • Loading branch information
SBuercklin committed Apr 4, 2024
1 parent 00ed499 commit 83ebdde
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/ToyAD.jl
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,10 @@ function jacobian(f::Function, x::Array{<:Real})
return j
end

function jacobian_2(f::Function, x)
function jacobian_2(f::Function, x::AbstractVector{T}) where {T<:Real}
cols = mapreduce(hcat, eachindex(x)) do idx
new_x = convert(Vector{Any}, deepcopy(x))
new_x[idx] = DualNumber(x[idx], 1.0)
new_x = convert(Vector{Union{T,DualNumber{T}}}, deepcopy(x))
new_x[idx] = DualNumber(x[idx], one(T))
return extract_derivative.(f(new_x))
end

Expand Down

0 comments on commit 83ebdde

Please sign in to comment.