Skip to content

Commit 2379d0d

Browse files
committed
Move SparseArrays and Statistics to extensions
1 parent 1faf00f commit 2379d0d

File tree

5 files changed

+32
-12
lines changed

5 files changed

+32
-12
lines changed

Project.toml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,28 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
88
Primes = "27ebfcd6-29c5-5fa9-bf4b-fb8fc14df3ae"
99
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1010
Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
11+
12+
[weakdeps]
1113
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1214
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
1315

16+
[extensions]
17+
SparseArraysExt = "SparseArrays"
18+
StatisticsExt = "Statistics"
19+
1420
[compat]
1521
ExplicitImports = "1.13.2"
1622
Primes = "0.4, 0.5"
23+
SparseArrays = "<0.0.1, 1"
1724
Statistics = "<0.0.1, 1"
1825
julia = "1.10"
1926

2027
[extras]
2128
ExplicitImports = "7d51a73a-1435-4ff3-83d9-f097790105c7"
29+
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
2230
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
31+
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
2332
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2433

2534
[targets]
26-
test = ["ExplicitImports", "Test", "SpecialFunctions"]
35+
test = ["ExplicitImports", "SparseArrays", "SpecialFunctions", "Statistics", "Test"]

ext/SparseArraysExt.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module SparseArraysExt
2+
3+
using DistributedArrays: DArray, localpart
4+
using DistributedArrays.Distributed: remotecall_fetch
5+
using SparseArrays: SparseArrays, nnz
6+
7+
function SparseArrays.nnz(A::DArray)
8+
B = asyncmap(A.pids) do p
9+
remotecall_fetch(nnzlocalpart, p, A)
10+
end
11+
return reduce(+, B)
12+
end
13+
14+
end

ext/StatisticsExt.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module StatisticsExt
2+
3+
using DistributedArrays: DArray
4+
using Statistics: Statistics
5+
6+
Statistics._mean(f, A::DArray, region) = sum(f, A, dims = region) ./ prod((size(A, i) for i in region))
7+
8+
end

src/DistributedArrays.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ using Distributed: Distributed, RemoteChannel, Future, myid, nworkers, procs, re
77
using LinearAlgebra: LinearAlgebra, Adjoint, Diagonal, I, Transpose, adjoint, adjoint!, axpy!, dot, lmul!, mul!, norm, rmul!, transpose, transpose!
88
using Random: Random, rand!
99
using Serialization: Serialization, AbstractSerializer, deserialize, serialize
10-
using SparseArrays: SparseArrays, nnz
11-
using Statistics: Statistics
1210

1311
using Primes: factor
1412

src/mapreduce.jl

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,6 @@ function Base.count(f, A::DArray)
117117
return sum(B)
118118
end
119119

120-
function SparseArrays.nnz(A::DArray)
121-
B = asyncmap(A.pids) do p
122-
remotecall_fetch(nnzlocalpart, p, A)
123-
end
124-
return reduce(+, B)
125-
end
126-
127120
function Base.extrema(d::DArray)
128121
r = asyncmap(procs(d)) do p
129122
remotecall_fetch(p) do
@@ -133,8 +126,6 @@ function Base.extrema(d::DArray)
133126
return reduce((t,s) -> (min(t[1], s[1]), max(t[2], s[2])), r)
134127
end
135128

136-
Statistics._mean(f, A::DArray, region) = sum(f, A, dims = region) ./ prod((size(A, i) for i in region))
137-
138129
# Unary vector functions
139130
Base.:(-)(D::DArray) = map(-, D)
140131

0 commit comments

Comments
 (0)