Skip to content

Commit

Permalink
Fix using TaylorDiff with DoubleFloats
Browse files Browse the repository at this point in the history
  • Loading branch information
SouthEndMusic committed Jul 22, 2024
1 parent b60c6a4 commit 7e0b9ab
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions GaussTuranExampleTemp/example.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using Optim
using DoubleFloats
using TaylorDiff
using PreallocationTools
using Integrals
using DoubleFloats

# This fix is needed to avoid crashing: https://github.com/JuliaLang/julia/pull/54201
include("linear_algebra_fix.jl")

FT = Float64 # Double64
FT = Double64
n = 5
s = 1
a = FT(0.0)
Expand Down Expand Up @@ -44,7 +44,7 @@ I = Integrals.GaussTuran(
max_int_error_upper = maximum(abs(I(x -> f(x, j)) - I.cache.rhs_upper[j])
for j in 1:(I.cache.N))
@show max_int_error_upper
# max_int_error_upper = 2.220446049250313e-16
# max_int_error_upper = 2.465190328815662e-32

# Integration error |I(fⱼ) - ₐ∫ᵇfⱼ(x)dx| last n functions fⱼ
max_int_error_lower = maximum(
Expand All @@ -53,9 +53,9 @@ for
j in (I.cache.N + 1):(I.cache.N + I.cache.n)
)
@show max_int_error_lower
# max_int_error_lower = 2.0211055051788662e-12
# max_int_error_lower = 9.079315240327527e-30

# Example with eˣ
exp_error = abs(I(Base.exp) - (Base.exp(1) - 1))
@show exp_error;
# exp_error = 1.5543122344752192e-15
# exp_error = 6.43662141695295e-18
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ IntegralsCubaExt = "Cuba"
IntegralsCubatureExt = "Cubature"
IntegralsFastGaussQuadratureExt = "FastGaussQuadrature"
IntegralsForwardDiffExt = "ForwardDiff"
IntegralsMCIntegrationExt = "MCIntegration"
IntegralsGaussTuranExt = ["Optim", "TaylorDiff", "PreallocationTools"]
IntegralsMCIntegrationExt = "MCIntegration"
IntegralsZygoteExt = ["Zygote", "ChainRulesCore"]

[compat]
Expand Down
6 changes: 3 additions & 3 deletions ext/IntegralsGaussTuranExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ function GaussTuranLoss!(f, ΔX::AbstractVector{T}, cache) where {T}
cumsum!(X, ΔX)
X .+= a

# Evaluating f!
# Evaluating f
for (i, x) in enumerate(X)
# Threads.@threads for j = 1:N
for j in 1:N
M_upper[j, i:n:N] .= derivatives(x -> f(x, j), x, one(T), Val(2s + 1)).value
M_upper[j, i:n:N] .= derivatives(x -> f(x, j), x, 1, Val(2s + 1)).value
end
Threads.@threads for j in (N + 1):(N + n)
M_lower[j - N, i:n:N] .= derivatives(x -> f(x, j), x, one(T), Val(2s + 1)).value
M_lower[j - N, i:n:N] .= derivatives(x -> f(x, j), x, 1, Val(2s + 1)).value
end
end

Expand Down

0 comments on commit 7e0b9ab

Please sign in to comment.