Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Statistics to an extension #134

Merged
merged 3 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "InfiniteArrays"
uuid = "4858937d-0d70-526a-a4dd-2d5cb5dd786c"
version = "0.12.14"
version = "0.12.15"

[deps]
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
Expand All @@ -10,6 +10,12 @@ LazyArrays = "5078a376-72f3-5289-bfd5-ec5146d43c02"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

[weakdeps]
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

[extensions]
InfiniteArraysStatisticsExt = "Statistics"

[compat]
Aqua = "0.6"
ArrayLayouts = "1.0"
Expand All @@ -26,7 +32,8 @@ BandedMatrices = "aae01518-5342-5314-be14-df237901396f"
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
LazyBandedMatrices = "d7e5e226-e90b-4449-9968-0f923699bf6f"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Aqua", "Test", "BandedMatrices", "LazyBandedMatrices", "SparseArrays", "Base64"]
test = ["Aqua", "Test", "BandedMatrices", "LazyBandedMatrices", "Statistics", "SparseArrays", "Base64"]
10 changes: 10 additions & 0 deletions ext/InfiniteArraysStatisticsExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module InfiniteArraysStatisticsExt

using InfiniteArrays
using InfiniteArrays: InfRanges
using Statistics

Statistics.mean(r::InfRanges{<:Real}) = last(r)
Statistics.median(r::InfRanges{<:Real}) = last(r)

end
9 changes: 4 additions & 5 deletions src/InfiniteArrays.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
module InfiniteArrays

using LinearAlgebra, FillArrays, Infinities, LazyArrays, ArrayLayouts

import Base: *, +, -, /, \, ==, isinf, isfinite, sign, signbit, angle, show, isless,
Expand Down Expand Up @@ -51,8 +50,6 @@ import LinearAlgebra: BlasInt, BlasFloat, norm, diag, diagm, ishermitian, issymm
det, logdet, istriu, istril, adjoint, tr, AbstractTriangular,
norm2, norm1, normp, AdjOrTrans, HermOrSym

import Statistics: mean, median

import FillArrays: AbstractFill, getindex_value, fill_reshape, RectDiagonal, Fill, Ones, Zeros, Eye

import LazyArrays: LazyArrayStyle, LazyLayout,
Expand All @@ -62,7 +59,7 @@ import LazyArrays: LazyArrayStyle, LazyLayout,

import ArrayLayouts: RangeCumsum, LayoutVecOrMat, LayoutVecOrMats, LayoutMatrix, LayoutVector,
AbstractBandedLayout, MemoryLayout, UnknownLayout, reshapedlayout,
sub_materialize, sublayout, ZerosLayout
sub_materialize, sublayout, ZerosLayout, LayoutVecOrMat

import Infinities: ∞, Infinity, InfiniteCardinal

Expand Down Expand Up @@ -225,7 +222,9 @@ end
return LazyArrays.searchsortedlast_recursive(n, x, args...)
end


if !isdefined(Base, :get_extension)
include("../ext/InfiniteArraysStatisticsExt.jl")
end


end # module
2 changes: 0 additions & 2 deletions src/infrange.jl
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,6 @@ InfStepRange(r::InfUnitRange{T}) where {T} =
## sorting ##

sum(r::InfRanges{<:Real}) = last(r)
mean(r::InfRanges{<:Real}) = last(r)
median(r::InfRanges{<:Real}) = last(r)

in(x::Union{Infinity,RealInfinity}, r::InfRanges) = false # never reach it...
in(x::Infinity, r::InfRanges{<:Integer}) = false # never reach it...
Expand Down
5 changes: 4 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import Base.Broadcast: broadcasted, Broadcasted, instantiate

using Aqua
@testset "Project quality" begin
Aqua.test_all(InfiniteArrays, ambiguities=false, piracy=false)
Aqua.test_all(InfiniteArrays, ambiguities=false, piracy=false,
# only test formatting on VERSION >= v1.7
# https://github.com/JuliaTesting/Aqua.jl/issues/105#issuecomment-1551405866
project_toml_formatting = VERSION >= v"1.7")
end

@testset "construction" begin
Expand Down