Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimal changes to jacobian in calculus.jl to allow for nonsquare Jacobians #372

Merged
merged 3 commits into from
Oct 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions src/calculus.jl
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,9 @@ evaluated at the vector `vals`. If `vals` is omitted, it is evaluated at zero.
"""
function jacobian(vf::Array{TaylorN{T},1}) where {T<:Number}
numVars = get_numvars()
@assert length(vf) == numVars
jac = Array{T}(undef, numVars, numVars)
jac = Array{T}(undef, numVars, length(vf))

@inbounds for comp = 1:numVars
@inbounds for comp in eachindex(vf)
jac[:,comp] = vf[comp][1][1:end]
end

Expand All @@ -264,10 +263,10 @@ end
function jacobian(vf::Array{TaylorN{T},1}, vals::Array{S,1}) where {T<:Number,S<:Number}
R = promote_type(T,S)
numVars = get_numvars()
@assert length(vf) == numVars == length(vals)
jac = Array{R}(undef, numVars, numVars)
@assert numVars == length(vals)
jac = Array{R}(undef, numVars, length(vf))

for comp = 1:numVars
for comp in eachindex(vf)
@inbounds grad = gradient( vf[comp] )
@inbounds for nv = 1:numVars
jac[nv,comp] = evaluate(grad[nv], vals)
Expand All @@ -294,10 +293,9 @@ it is evaluated at zero.
"""
function jacobian!(jac::Array{T,2}, vf::Array{TaylorN{T},1}) where {T<:Number}
numVars = get_numvars()
@assert length(vf) == numVars
@assert (numVars, numVars) == size(jac)
@assert (length(vf), numVars) == size(jac)
for comp2 = 1:numVars
for comp1 = 1:numVars
for comp1 in eachindex(vf)
@inbounds jac[comp1,comp2] = vf[comp1][1][comp2]
end
end
Expand All @@ -306,10 +304,10 @@ end
function jacobian!(jac::Array{T,2}, vf::Array{TaylorN{T},1},
vals::Array{T,1}) where {T<:Number}
numVars = get_numvars()
@assert length(vf) == numVars == length(vals)
@assert (numVars, numVars) == size(jac)
@assert numVars == length(vals)
@assert (length(vf), numVars) == size(jac)
for comp = 1:numVars
@inbounds for nv = 1:numVars
@inbounds for nv in eachindex(vf)
jac[nv,comp] = evaluate(differentiate(vf[nv], comp), vals)
end
end
Expand Down
Loading