Skip to content

Commit

Permalink
Compatibility with NonlinearSolve.jl (#12)
Browse files Browse the repository at this point in the history
* stricter test tols

* overload eps() and add DA(Bool)
  • Loading branch information
afossa authored Jul 11, 2024
1 parent b5e58e6 commit 7f29d0f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/DACE.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ module DACE
# custom constructors #
# ------------------- #

# concrete DA types
DA(b::Bool) = DA(b ? 1.0 : 0.0)
DA(x::Rational) = DA(convert(Float64,x))

# concrete DA types
DAAllocated() = DA(0.0)
DAAllocated(x::Real) = DA(x)

Expand Down Expand Up @@ -75,6 +77,8 @@ module DACE
end

Base.float(a::DA) = a
Base.eps(a::DA) = eps(cons(a))
Base.eps(::Type{T}) where {T<:DA} = eps(Float64)

# power operators
Base.:^(da::DA, p::Integer) = DACE.powi(da, p)
Expand Down
6 changes: 3 additions & 3 deletions test/special_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ using SpecialFunctions
DACE.init(1,3)

x = DACE.random(-1)
@test isapprox(DACE.cons(erf(x)), erf(DACE.cons(x)), atol=1e-8, rtol=1e-5)
@test isapprox(DACE.cons(erf(x)), erf(DACE.cons(x)), atol=1e-15, rtol=1e-15)

end

@testset "Test erfc" begin
DACE.init(1,3)

x = DACE.random(-1)
@test isapprox(DACE.cons(erfc(x)), erfc(DACE.cons(x)), atol=1e-8, rtol=1e-5)
@test isapprox(DACE.cons(erfc(x)), erfc(DACE.cons(x)), atol=1e-15, rtol=1e-15)

end

Expand Down

0 comments on commit 7f29d0f

Please sign in to comment.