Skip to content

Commit 2baeb85

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 c6b8a9c commit 2baeb85

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,
@@ -493,10 +493,6 @@ Base.mul_prod(x::FixedPoint, y::FixedPoint) = Treduce(x) * Treduce(y)
493493
Base.reduce_empty(::typeof(Base.mul_prod), ::Type{F}) where {F<:FixedPoint} = one(Treduce)
494494
Base.reduce_first(::typeof(Base.mul_prod), x::FixedPoint) = Treduce(x)
495495

496-
if isdefined(Statistics, :_mean_promote)
497-
Statistics._mean_promote(x::Real, y::FixedPoint) = Treduce(y)
498-
end
499-
500496
"""
501497
sd, ad = scaledual(s::Number, a)
502498
@@ -560,4 +556,15 @@ if VERSION >= v"1.1" # work around https://github.com/JuliaLang/julia/issues/341
560556
_precompile_()
561557
end
562558

559+
@static if VERSION >= v"1.9.0-DEV.873"
560+
# Statistics and SparseArrays are moved out from sysimage
561+
# https://github.com/JuliaLang/julia/pull/44247#issuecomment-1172847231
562+
@require Statistics="10745b16-79ce-11e8-11f9-7d13ad32a3b2" begin
563+
Statistics._mean_promote(x::Real, y::FixedPoint) = Treduce(y)
564+
end
565+
else
566+
import Statistics
567+
Statistics._mean_promote(x::Real, y::FixedPoint) = Treduce(y)
568+
end
569+
563570
end # module

0 commit comments

Comments
 (0)