Skip to content

Commit a61b991

Browse files
committed
using Requires for Statistics
Because Statistics is no longer part of the Julia sysimage, the package loading time of FixedPointNumbers is then donimated by Statistics. This commit uses Requires to conditionally add the needed method without making more one-line package. This, of course, adds some additional overhead but I do believe it's currently the best tradeoff until we have first-class support on conditional package loading.
1 parent 0b8bcea commit a61b991

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ version = "0.8.4"
44

55
[deps]
66
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
7+
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
78
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
89

910
[compat]
11+
Requires = "1"
1012
julia = "1"
1113

1214
[extras]

src/FixedPointNumbers.jl

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Base: ==, <, <=, -, +, *, /, ~, isapprox,
99
signed, unsigned, copysign, flipsign, signbit,
1010
length
1111

12-
import Statistics # for _mean_promote
12+
using Requires
1313
import Random: Random, AbstractRNG, SamplerType, rand!
1414

1515
import Base.Checked: checked_neg, checked_abs, checked_add, checked_sub, checked_mul,
@@ -557,10 +557,6 @@ Base.mul_prod(x::FixedPoint, y::FixedPoint) = Treduce(x) * Treduce(y)
557557
Base.reduce_empty(::typeof(Base.mul_prod), ::Type{F}) where {F<:FixedPoint} = one(Treduce)
558558
Base.reduce_first(::typeof(Base.mul_prod), x::FixedPoint) = Treduce(x)
559559

560-
if isdefined(Statistics, :_mean_promote)
561-
Statistics._mean_promote(x::Real, y::FixedPoint) = Treduce(y)
562-
end
563-
564560
"""
565561
sd, ad = scaledual(s::Number, a)
566562
@@ -629,4 +625,15 @@ if VERSION >= v"1.1" # work around https://github.com/JuliaLang/julia/issues/341
629625
_precompile_()
630626
end
631627

628+
@static if VERSION >= v"1.9.0-DEV.873"
629+
# Statistics and SparseArrays are moved out from sysimage
630+
# https://github.com/JuliaLang/julia/pull/44247#issuecomment-1172847231
631+
@require Statistics="10745b16-79ce-11e8-11f9-7d13ad32a3b2" begin
632+
Statistics._mean_promote(x::Real, y::FixedPoint) = Treduce(y)
633+
end
634+
else
635+
import Statistics
636+
Statistics._mean_promote(x::Real, y::FixedPoint) = Treduce(y)
637+
end
638+
632639
end # module

0 commit comments

Comments
 (0)