Repository navigation
Move the Statistics methods into a package extension - #869
Merged
Merged
Conversation
GPUArrays loaded Statistics.jl for every user, although its methods only matter to code that loads Statistics.jl itself. They now live in StatisticsExt. The overrides that only exist because Statistics.jl's generic methods index into the array (`_mean`, `covzm` and the two-argument `corzm`) move to their own file, in one section per upstream fix (JuliaStats/Statistics.jl#223, #224 and #225), so each can be deleted once GPUArrays requires a Statistics.jl release with it. Julia 1.10 always loads the Statistics.jl it ships with, so that means dropping 1.10.
maleadt
force-pushed
the
tb/statistics-ext
branch
from
November 27, 2026 13:14
e1b5104 to
2ade6c0
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #868.
GPUArrays loads Statistics.jl for every user, although its Statistics methods only matter to code that loads Statistics.jl itself. This moves them into a package extension,
StatisticsExt, and Statistics.jl from[deps]to[weakdeps]. Nothing changes for code that callsmean,medianand so on, since that already loads Statistics.jl.The overrides that only exist because Statistics.jl's generic methods index into the array, rather than to run on the GPU, move to
ext/StatisticsExt/workarounds.jl. There is one section per upstream fix:_mean: Infer the accumulator type ofmeaninstead of callingfon the first element JuliaStats/Statistics.jl#223 (the accumulator type comes fromfirst(A))covzm: Fixcovof a matrix with no variables JuliaStats/Statistics.jl#224 (the result type comes fromfirst(C))corzm: Normalize dense rectangular correlation matrices with broadcasts JuliaStats/Statistics.jl#225 (cov2cor!loops over the elements)Each section can be deleted once GPUArrays requires a Statistics.jl release with its fix. Julia 1.10 always loads the Statistics.jl it ships with, so that means dropping 1.10. Until then, the sections could at most be skipped on newer Statistics.jl with a
pkgversion(Statistics)check. The file is included from one line at the end of the extension.Tested: the statistics testsuite on JLArray (515/515),
Array(500/500), JLArray without Float64 (319/319) and CuArray (515/515), and that the extension loads on Julia 1.10 and 1.12 once Statistics.jl is loaded, and not before.