Skip to content

Commit e76352b

Browse files
add ODE_DEFAULT_NORM overloads
1 parent a9f73bb commit e76352b

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

ext/DiffEqBaseGTPSAExt.jl

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,26 @@ module DiffEqBaseGTPSAExt
22

33
if isdefined(Base, :get_extension)
44
using DiffEqBase
5-
import DiffEqBase: value
5+
import DiffEqBase: value, ODE_DEFAULT_NORM
66
using GTPSA
77
else
88
using ..DiffEqBase
9-
import ..DiffEqBase: value
9+
import ..DiffEqBase: value, ODE_DEFAULT_NORM
1010
using ..GTPSA
1111
end
1212

13-
value(x::TPS) = scalar(x);
13+
value(x::TPS) = scalar(x)
1414
value(::Type{TPS{T}}) where {T} = T
1515

16+
ODE_DEFAULT_NORM(u::TPS, t) = @fastmath abs(value(u))
17+
ODE_DEFAULT_NORM(f::F, u::TPS, t) where {F} = @fastmath abs(f(value(u)))
18+
19+
function ODE_DEFAULT_NORM(u::AbstractArray{TPS{T}}, t) where {T <: Union{AbstractFloat, Complex}}
20+
x = zero(real(T))
21+
@inbounds @fastmath for ui in u
22+
x += abs2(value(ui))
23+
end
24+
Base.FastMath.sqrt_fast(x / max(length(u), 1))
25+
end
1626

1727
end

0 commit comments

Comments
 (0)