From 607497495574ba1e3ac26b318c52f8675fe89b1c Mon Sep 17 00:00:00 2001 From: Alexander Plavin Date: Wed, 3 Jan 2024 07:55:14 -0500 Subject: [PATCH] add geomean(inteval) --- Project.toml | 5 ++++- ext/IntervalSetsStatsBaseExt.jl | 8 ++++++++ test/runtests.jl | 2 ++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 ext/IntervalSetsStatsBaseExt.jl diff --git a/Project.toml b/Project.toml index 978c147..16eb6af 100644 --- a/Project.toml +++ b/Project.toml @@ -9,10 +9,12 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" [weakdeps] Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" +StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" [extensions] IntervalSetRandomExt = "Random" IntervalSetsStatisticsExt = "Statistics" +IntervalSetsStatsBaseExt = "StatsBase" [compat] Aqua = "0.7" @@ -25,8 +27,9 @@ Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" +StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d" [targets] -test = ["Aqua", "Dates", "Test", "Random", "OffsetArrays", "Statistics", "Unitful"] +test = ["Aqua", "Dates", "Test", "Random", "OffsetArrays", "StatsBase", "Statistics", "Unitful"] diff --git a/ext/IntervalSetsStatsBaseExt.jl b/ext/IntervalSetsStatsBaseExt.jl new file mode 100644 index 0000000..dda2400 --- /dev/null +++ b/ext/IntervalSetsStatsBaseExt.jl @@ -0,0 +1,8 @@ +module IntervalSetsStatsBaseExt + +using IntervalSets +using StatsBase + +StatsBase.geomean(d::AbstractInterval) = sqrt(leftendpoint(d) * rightendpoint(d)) + +end diff --git a/test/runtests.jl b/test/runtests.jl index f2db5c5..2f62f9a 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,6 +1,7 @@ using IntervalSets using Test using Dates +using StatsBase: geomean using Statistics import Statistics: mean using Random @@ -136,6 +137,7 @@ struct IncompleteInterval <: AbstractInterval{Int} end @test width(ClosedInterval(4.0,8.0)) ≡ 4.0 @test mean(0..1) == 0.5 + VERSION ≥ v"1.9" && @test geomean(1..100) == 10 @test promote(1..2, 1.0..2.0) === (1.0..2.0, 1.0..2.0) end