Skip to content

Commit

Permalink
add geomean(inteval)
Browse files Browse the repository at this point in the history
  • Loading branch information
aplavin committed Jan 3, 2024
1 parent f0cfc84 commit 6074974
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"]
8 changes: 8 additions & 0 deletions ext/IntervalSetsStatsBaseExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module IntervalSetsStatsBaseExt

using IntervalSets
using StatsBase

StatsBase.geomean(d::AbstractInterval) = sqrt(leftendpoint(d) * rightendpoint(d))

end
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using IntervalSets
using Test
using Dates
using StatsBase: geomean
using Statistics
import Statistics: mean
using Random
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6074974

Please sign in to comment.