From 2379d0d804b428510db3ee2e0528443f3350a448 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20M=C3=BCller-Widmann?= Date: Tue, 9 Sep 2025 11:07:03 +0200 Subject: [PATCH] Move SparseArrays and Statistics to extensions --- Project.toml | 11 ++++++++++- ext/SparseArraysExt.jl | 14 ++++++++++++++ ext/StatisticsExt.jl | 8 ++++++++ src/DistributedArrays.jl | 2 -- src/mapreduce.jl | 9 --------- 5 files changed, 32 insertions(+), 12 deletions(-) create mode 100644 ext/SparseArraysExt.jl create mode 100644 ext/StatisticsExt.jl diff --git a/Project.toml b/Project.toml index 31f4244..0a5157e 100644 --- a/Project.toml +++ b/Project.toml @@ -8,19 +8,28 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" Primes = "27ebfcd6-29c5-5fa9-bf4b-fb8fc14df3ae" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b" + +[weakdeps] SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" +[extensions] +SparseArraysExt = "SparseArrays" +StatisticsExt = "Statistics" + [compat] ExplicitImports = "1.13.2" Primes = "0.4, 0.5" +SparseArrays = "<0.0.1, 1" Statistics = "<0.0.1, 1" julia = "1.10" [extras] ExplicitImports = "7d51a73a-1435-4ff3-83d9-f097790105c7" +SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b" +Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["ExplicitImports", "Test", "SpecialFunctions"] +test = ["ExplicitImports", "SparseArrays", "SpecialFunctions", "Statistics", "Test"] diff --git a/ext/SparseArraysExt.jl b/ext/SparseArraysExt.jl new file mode 100644 index 0000000..5b48257 --- /dev/null +++ b/ext/SparseArraysExt.jl @@ -0,0 +1,14 @@ +module SparseArraysExt + +using DistributedArrays: DArray, localpart +using DistributedArrays.Distributed: remotecall_fetch +using SparseArrays: SparseArrays, nnz + +function SparseArrays.nnz(A::DArray) + B = asyncmap(A.pids) do p + remotecall_fetch(nnz∘localpart, p, A) + end + return reduce(+, B) +end + +end diff --git a/ext/StatisticsExt.jl b/ext/StatisticsExt.jl new file mode 100644 index 0000000..e8b06cf --- /dev/null +++ b/ext/StatisticsExt.jl @@ -0,0 +1,8 @@ +module StatisticsExt + +using DistributedArrays: DArray +using Statistics: Statistics + +Statistics._mean(f, A::DArray, region) = sum(f, A, dims = region) ./ prod((size(A, i) for i in region)) + +end diff --git a/src/DistributedArrays.jl b/src/DistributedArrays.jl index 05428cd..51f50ce 100644 --- a/src/DistributedArrays.jl +++ b/src/DistributedArrays.jl @@ -7,8 +7,6 @@ using Distributed: Distributed, RemoteChannel, Future, myid, nworkers, procs, re using LinearAlgebra: LinearAlgebra, Adjoint, Diagonal, I, Transpose, adjoint, adjoint!, axpy!, dot, lmul!, mul!, norm, rmul!, transpose, transpose! using Random: Random, rand! using Serialization: Serialization, AbstractSerializer, deserialize, serialize -using SparseArrays: SparseArrays, nnz -using Statistics: Statistics using Primes: factor diff --git a/src/mapreduce.jl b/src/mapreduce.jl index a02a54a..ecf9fc7 100644 --- a/src/mapreduce.jl +++ b/src/mapreduce.jl @@ -117,13 +117,6 @@ function Base.count(f, A::DArray) return sum(B) end -function SparseArrays.nnz(A::DArray) - B = asyncmap(A.pids) do p - remotecall_fetch(nnz∘localpart, p, A) - end - return reduce(+, B) -end - function Base.extrema(d::DArray) r = asyncmap(procs(d)) do p remotecall_fetch(p) do @@ -133,8 +126,6 @@ function Base.extrema(d::DArray) return reduce((t,s) -> (min(t[1], s[1]), max(t[2], s[2])), r) end -Statistics._mean(f, A::DArray, region) = sum(f, A, dims = region) ./ prod((size(A, i) for i in region)) - # Unary vector functions Base.:(-)(D::DArray) = map(-, D)