Skip to content

Commit b05454f

Browse files
dkarraschfredrikekrethchr
authored
Handle Statistics dep as Pkg extension (JuliaArrays#1172)
* Handle Statistics dep as Pkg extension * rm import * `using` unexported functions * Apply suggestions from code review Co-authored-by: Fredrik Ekre <ekrefredrik@gmail.com> * declare usage of Statistics in tests * list Statistics.jl in extras * Apply suggestions from code review Co-authored-by: Thomas Christensen <tchr@mit.edu> * broken test passes on v1.10 --------- Co-authored-by: Fredrik Ekre <ekrefredrik@gmail.com> Co-authored-by: Thomas Christensen <tchr@mit.edu>
1 parent b4fbf2f commit b05454f

File tree

5 files changed

+33
-13
lines changed

5 files changed

+33
-13
lines changed

Project.toml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
name = "StaticArrays"
22
uuid = "90137ffa-7385-5640-81b9-e52037218182"
3-
version = "1.5.26"
3+
version = "1.6.0"
44

55
[deps]
66
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
77
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
88
StaticArraysCore = "1e83bf80-4336-4d27-bf5d-d5a4f845583c"
99
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
1010

11+
[weakdeps]
12+
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
13+
14+
[extensions]
15+
StaticArraysStatisticsExt = "Statistics"
16+
1117
[compat]
1218
julia = "1.6"
1319
StaticArraysCore = "~1.4.0"
@@ -16,8 +22,9 @@ StaticArraysCore = "~1.4.0"
1622
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
1723
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
1824
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
25+
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
1926
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2027
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
2128

2229
[targets]
23-
test = ["InteractiveUtils", "Test", "BenchmarkTools", "OffsetArrays", "Unitful"]
30+
test = ["InteractiveUtils", "Test", "BenchmarkTools", "OffsetArrays", "Statistics", "Unitful"]

ext/StaticArraysStatisticsExt.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module StaticArraysStatisticsExt
2+
3+
import Statistics: mean
4+
5+
using StaticArrays
6+
using StaticArrays: _InitialValue, _reduce, _mapreduce
7+
8+
_mean_denom(a, ::Colon) = length(a)
9+
_mean_denom(a, dims::Int) = size(a, dims)
10+
_mean_denom(a, ::Val{D}) where {D} = size(a, D)
11+
12+
@inline mean(a::StaticArray; dims=:) = _reduce(+, a, dims) / _mean_denom(a, dims)
13+
@inline mean(f::Function, a::StaticArray; dims=:) = _mapreduce(f, +, dims, _InitialValue(), Size(a), a) / _mean_denom(a, dims)
14+
15+
end # module

src/StaticArrays.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import Base: getindex, setindex!, size, similar, vec, show, length, convert, pro
88
iszero, sum, prod, count, any, all, minimum, maximum, extrema,
99
copy, read, read!, write, reverse
1010

11-
import Statistics: mean
12-
1311
using Random
1412
import Random: rand, randn, randexp, rand!, randn!, randexp!
1513
using Core.Compiler: return_type
@@ -133,6 +131,10 @@ include("flatten.jl")
133131
include("io.jl")
134132
include("pinv.jl")
135133

134+
@static if !isdefined(Base, :get_extension) # VERSION < v"1.9-"
135+
include("../ext/StaticArraysStatisticsExt.jl")
136+
end
137+
136138
include("precompile.jl")
137139
_precompile_()
138140

src/mapreduce.jl

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -301,14 +301,6 @@ reduce(::typeof(hcat), A::StaticArray{<:Tuple,<:StaticVecOrMatLike}) =
301301

302302
@inline Base.in(x, a::StaticArray) = _mapreduce(==(x), |, :, false, Size(a), a)
303303

304-
_mean_denom(a, dims::Colon) = length(a)
305-
_mean_denom(a, dims::Int) = size(a, dims)
306-
_mean_denom(a, ::Val{D}) where {D} = size(a, D)
307-
_mean_denom(a, ::Type{Val{D}}) where {D} = size(a, D)
308-
309-
@inline mean(a::StaticArray; dims=:) = _reduce(+, a, dims) / _mean_denom(a, dims)
310-
@inline mean(f::Function, a::StaticArray; dims=:) = _mapreduce(f, +, dims, _InitialValue(), Size(a), a) / _mean_denom(a, dims)
311-
312304
@inline minimum(a::StaticArray; dims=:) = _reduce(min, a, dims) # base has mapreduce(identity, scalarmin, a)
313305
@inline minimum(f::Function, a::StaticArray; dims=:) = _mapreduce(f, min, dims, _InitialValue(), Size(a), a)
314306

test/svd.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ using StaticArrays, Test, LinearAlgebra
7878
# This only seems to work on v"1.5" due to unknown compiler improvements; seems
7979
# to have stopped working again on v"1.6" and later?
8080
svd_full_false(A) = svd(A, full=false)
81-
@test_broken @inferred(svd_full_false(m_sing2)).S svd(Matrix(m_sing2)).S
81+
if VERSION < v"1.10-"
82+
@test svd_full_false(m_sing2).S svd(Matrix(m_sing2)).S
83+
else
84+
@test @inferred(svd_full_false(m_sing2)).S svd(Matrix(m_sing2)).S
85+
end
8286

8387
@testinf svd(mc_sing) \ v svd(Matrix(mc_sing)) \ Vector(v)
8488
@testinf svd(mc_sing) \ vc svd(Matrix(mc_sing)) \ Vector(vc)

0 commit comments

Comments
 (0)