Skip to content

Move the Statistics methods into a package extension - #869

Merged
maleadt merged 1 commit into
mainfrom
tb/statistics-ext
Nov 27, 2026
Merged

maleadt merged 1 commit into
mainfrom
tb/statistics-ext

Conversation

@maleadt

@maleadt maleadt commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

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 calls mean, median and 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:

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.

@maleadt
maleadt added this pull request to stack #870 November 27, 2026 11:51
Base automatically changed from tb/statistics to main November 27, 2026 13:14
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
maleadt merged commit 548f072 into main Nov 27, 2026
1 check was pending
@maleadt
maleadt deleted the tb/statistics-ext branch November 27, 2026 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant