Skip to content

Commit

Permalink
refactor: remove type-pirated functions
Browse files Browse the repository at this point in the history
moved to SciMLBase
  • Loading branch information
AayushSabharwal committed Jan 29, 2024
1 parent 4693404 commit 4df987c
Showing 1 changed file with 0 additions and 37 deletions.
37 changes: 0 additions & 37 deletions src/cache.jl
Original file line number Diff line number Diff line change
@@ -1,40 +1,3 @@

function Base.getproperty(cache::SciMLBase.AbstractOptimizationCache, x::Symbol)
if x in (:u0, :p)
return getfield(cache.reinit_cache, x)
end
return getfield(cache, x)
end

SciMLBase.has_reinit(cache::SciMLBase.AbstractOptimizationCache) = true
function SciMLBase.reinit!(cache::SciMLBase.AbstractOptimizationCache; p = missing,
u0 = missing)
if p === missing && u0 === missing
p, u0 = cache.p, cache.u0
else # at least one of them has a value
if p === missing
p = cache.p
end
if u0 === missing
u0 = cache.u0
end
if (eltype(p) <: Pair && !isempty(p)) || (eltype(u0) <: Pair && !isempty(u0)) # one is a non-empty symbolic map
hasproperty(cache.f, :sys) && hasfield(typeof(cache.f.sys), :ps) ||
throw(ArgumentError("This cache does not support symbolic maps with `remake`, i.e. it does not have a symbolic origin." *
" Please use `remake` with the `p` keyword argument as a vector of values, paying attention to parameter order."))
hasproperty(cache.f, :sys) && hasfield(typeof(cache.f.sys), :states) ||
throw(ArgumentError("This cache does not support symbolic maps with `remake`, i.e. it does not have a symbolic origin." *
" Please use `remake` with the `u0` keyword argument as a vector of values, paying attention to state order."))
p, u0 = SciMLBase.process_p_u0_symbolic(cache, p, u0)
end
end

cache.reinit_cache.p = p
cache.reinit_cache.u0 = u0

return cache
end

struct OptimizationCache{F, RC, LB, UB, LC, UC, S, O, D, P, C} <:
SciMLBase.AbstractOptimizationCache
f::F
Expand Down

0 comments on commit 4df987c

Please sign in to comment.