Skip to content

Commit

Permalink
Remove destructive invalidation and fix compile times
Browse files Browse the repository at this point in the history
```julia
using DifferentialEquations, SnoopCompile

function lorenz(du,u,p,t)
 du[1] = 10.0(u[2]-u[1])
 du[2] = u[1]*(28.0-u[3]) - u[2]
 du[3] = u[1]*u[2] - (8/3)*u[3]
end

u0 = [1.0;0.0;0.0]
tspan = (0.0,100.0)
prob = ODEProblem(lorenz,u0,tspan)
alg = Rodas5(chunk_size = Val{3}(), linsolve = DiffEqBase.LUFactorize())
tinf = @snoopi_deep solve(prob,alg)
```

Before:

After:

```julia
# InferenceTimingNode: 1.002721/2.089656 on Core.Compiler.Timings.ROOT() with 3 direct children
```

Fixes SciML/DifferentialEquations.jl#785
  • Loading branch information
ChrisRackauckas committed Dec 10, 2021
1 parent 18341a9 commit 9c7fd7a
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/Symbolics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,14 @@ using Requires
export symbolics_to_sympy
include("init.jl")


include("semipoly.jl")

# Hacks to make wrappers "nicer"
const NumberTypes = Union{AbstractFloat,Integer,Complex{<:AbstractFloat},Complex{<:Integer}}
(::Type{T})(x::SymbolicUtils.Symbolic) where {T<:NumberTypes} = throw(ArgumentError("Cannot convert Sym to $T since Sym is symbolic and $T is concrete. Use `substitute` to replace the symbolic unwraps."))
for T in [Num, Complex{Num}]
@eval begin
(::Type{S})(x::$T) where {S<:Union{NumberTypes,AbstractArray}} = S(Symbolics.unwrap(x))::S
#(::Type{S})(x::$T) where {S<:Union{NumberTypes,AbstractArray}} = S(Symbolics.unwrap(x))::S

SymbolicUtils.simplify(n::$T; kw...) = wrap(SymbolicUtils.simplify(unwrap(n); kw...))
SymbolicUtils.simplify_fractions(n::$T; kw...) = wrap(SymbolicUtils.simplify_fractions(unwrap(n); kw...))
Expand Down

0 comments on commit 9c7fd7a

Please sign in to comment.