Skip to content

Commit 50962e9

Browse files
committed
test and fix ForwardDiff on fit_mean_Σ(Normal
1 parent 75f0d07 commit 50962e9

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

src/univariate/continuous/normal.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ end
3838

3939
function fit_mean_Σ(::Type{Normal}, mean::T1, σ::T2) where {T1 <: Real, T2 <: Real}
4040
_T = promote_type(T1,T2)
41-
fit_mean_Σ(Normal{_T}, mean, σ)
41+
mean_p = _T(mean)
42+
σ_p = _T(σ)
43+
#(mean_p, σ_p) = (mean, σ) # first make test fit_mean_Σ_ForwardDiff fail
44+
fit_mean_Σ(Normal{_T}, mean_p, σ_p)
4245
end
4346
function fit_mean_Σ(D::Type{Normal{T}}, mean::Real, σ::Real) where {T}
4447
Normal{T}(mean, σ)

test/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[deps]
22
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
33
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
4+
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
45
JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
56
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
67
LoggingExtras = "e6f89c97-d47a-5376-807f-9c37f3926c36"

test/univariate/continuous/normal.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,14 @@ end;
1616
@test mean(d) == m
1717
@test scale(d) == σ
1818
end;
19+
20+
@testset "fit_mean_Σ_ForwardDiff" begin
21+
m = 3.0
22+
σ = 2.0
23+
f(m) = begin
24+
d = fit_mean_Σ(Normal, m, σ)
25+
mode(d)
26+
end
27+
f(m)
28+
dm = ForwardDiff.derivative(f, m)
29+
end;

test/univariate/test_univariate.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ using Test
33
using Random: Random
44
using LoggingExtras
55
using Optim
6+
using ForwardDiff
67

78
pkgdir = dirname(dirname(pathof(DistributionFits)))
89
testdir = joinpath(pkgdir, "test")

0 commit comments

Comments
 (0)