Skip to content

Commit

Permalink
Generalizations to make batching work
Browse files Browse the repository at this point in the history
  • Loading branch information
avik-pal committed Nov 19, 2023
1 parent 0026bc1 commit ce3d7aa
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,10 @@ end

__init_identity_jacobian(u::Number, _) = u
function __init_identity_jacobian(u, fu)
return convert(parameterless_type(_mutable(u)),
Matrix{eltype(u)}(I, length(fu), length(u)))
J = similar(u, promote_type(eltype(u), eltype(fu)), length(fu), length(u))
fill!(J, 0)
J[diagind(J)] .= 1
return J
end
function __init_identity_jacobian(u::StaticArray, fu)
return convert(MArray{Tuple{length(fu), length(u)}},
Expand All @@ -291,8 +293,10 @@ function __init_low_rank_jacobian(u::StaticArray, fu, threshold::Int)
return U, Vᵀ
end
function __init_low_rank_jacobian(u, fu, threshold::Int)
Vᵀ = convert(parameterless_type(_mutable(u)), zeros(eltype(u), length(u), threshold))
U = convert(parameterless_type(_mutable(u)), zeros(eltype(u), threshold, length(u)))
Vᵀ = similar(u, promote_type(eltype(u), eltype(fu)), length(u), threshold)
U = similar(u, promote_type(eltype(u), eltype(fu)), threshold, length(u))
fill!(Vᵀ, 0)
fill!(U, 0)
return U, Vᵀ
end

Expand Down

0 comments on commit ce3d7aa

Please sign in to comment.