From 899fb0af2d75337d5c04607fe94d64712b41468d Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Sun, 20 Oct 2024 13:46:13 +0530 Subject: [PATCH 1/3] Don't import require_one_based_indexing from StaticArraysCore (#1279) --- src/StaticArrays.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/StaticArrays.jl b/src/StaticArrays.jl index be48eced..023c45f5 100644 --- a/src/StaticArrays.jl +++ b/src/StaticArrays.jl @@ -27,7 +27,7 @@ using PrecompileTools # from StaticArraysCore to make transitioning definitions to StaticArraysCore easier. using StaticArraysCore: StaticArraysCore, StaticArray, StaticScalar, StaticVector, StaticMatrix, StaticVecOrMat, tuple_length, tuple_prod, - tuple_minimum, size_to_tuple, require_one_based_indexing + tuple_minimum, size_to_tuple using StaticArraysCore: FieldArray, FieldMatrix, FieldVector using StaticArraysCore: StaticArrayStyle using StaticArraysCore: Dynamic, StaticDimension From b2f2fb096bddf7b943f60284b15eda9d694ccb55 Mon Sep 17 00:00:00 2001 From: Thomas Christensen Date: Mon, 21 Oct 2024 15:34:53 +0200 Subject: [PATCH 2/3] Let `count`, `sum`, and `prod` take an `init` kwarg (#1281) * let `count` take an `init` kwarg - `Base.count` allows the `init` kwarg since v1.6 - bump StaticArrays to 1.9.8 * add `init` kwarg to `sum` and `prod` as well (fix #1119) * run invalidations action on julia lts * Move `solve.jl` tests to group B to hopefully OOM issues on Julia 1.6 CI --------- Co-authored-by: Mateusz Baran --- .github/workflows/Invalidations.yml | 2 +- Project.toml | 2 +- src/mapreduce.jl | 16 ++++++++-------- test/mapreduce.jl | 6 ++++++ test/runtests.jl | 2 +- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/.github/workflows/Invalidations.yml b/.github/workflows/Invalidations.yml index acc07495..a99bfe26 100644 --- a/.github/workflows/Invalidations.yml +++ b/.github/workflows/Invalidations.yml @@ -18,7 +18,7 @@ jobs: steps: - uses: julia-actions/setup-julia@v2 with: - version: '1' + version: 'lts' - uses: actions/checkout@v4 - uses: julia-actions/julia-buildpkg@v1 - uses: julia-actions/julia-invalidations@v1 diff --git a/Project.toml b/Project.toml index 376a9bf3..481144ad 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "StaticArrays" uuid = "90137ffa-7385-5640-81b9-e52037218182" -version = "1.9.7" +version = "1.9.8" [deps] LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" diff --git a/src/mapreduce.jl b/src/mapreduce.jl index c71875ba..2df6cd04 100644 --- a/src/mapreduce.jl +++ b/src/mapreduce.jl @@ -284,16 +284,16 @@ reduce(::typeof(hcat), A::StaticArray{<:Tuple,<:StaticVecOrMatLike}) = # TODO: change to use Base.reduce_empty/Base.reduce_first @inline iszero(a::StaticArray{<:Tuple,T}) where {T} = reduce((x,y) -> x && iszero(y), a, init=true) -@inline sum(a::StaticArray{<:Tuple,T}; dims=:) where {T} = _reduce(+, a, dims) -@inline sum(f, a::StaticArray{<:Tuple,T}; dims=:) where {T} = _mapreduce(f, +, dims, _InitialValue(), Size(a), a) -@inline sum(f::Union{Function, Type}, a::StaticArray{<:Tuple,T}; dims=:) where {T} = _mapreduce(f, +, dims, _InitialValue(), Size(a), a) # avoid ambiguity +@inline sum(a::StaticArray{<:Tuple,T}; dims=:, init=_InitialValue()) where {T} = _reduce(+, a, dims, init) +@inline sum(f, a::StaticArray{<:Tuple,T}; dims=:, init=_InitialValue()) where {T} = _mapreduce(f, +, dims, init, Size(a), a) +@inline sum(f::Union{Function, Type}, a::StaticArray{<:Tuple,T}; dims=:, init=_InitialValue()) where {T} = _mapreduce(f, +, dims, init, Size(a), a) # avoid ambiguity -@inline prod(a::StaticArray{<:Tuple,T}; dims=:) where {T} = _reduce(*, a, dims) -@inline prod(f, a::StaticArray{<:Tuple,T}; dims=:) where {T} = _mapreduce(f, *, dims, _InitialValue(), Size(a), a) -@inline prod(f::Union{Function, Type}, a::StaticArray{<:Tuple,T}; dims=:) where {T} = _mapreduce(f, *, dims, _InitialValue(), Size(a), a) +@inline prod(a::StaticArray{<:Tuple,T}; dims=:, init=_InitialValue()) where {T} = _reduce(*, a, dims, init) +@inline prod(f, a::StaticArray{<:Tuple,T}; dims=:, init=_InitialValue()) where {T} = _mapreduce(f, *, dims, init, Size(a), a) +@inline prod(f::Union{Function, Type}, a::StaticArray{<:Tuple,T}; dims=:, init=_InitialValue()) where {T} = _mapreduce(f, *, dims, init, Size(a), a) -@inline count(a::StaticArray{<:Tuple,Bool}; dims=:) = _reduce(+, a, dims) -@inline count(f, a::StaticArray; dims=:) = _mapreduce(x->f(x)::Bool, +, dims, _InitialValue(), Size(a), a) +@inline count(a::StaticArray{<:Tuple,Bool}; dims=:, init=0) = _reduce(+, a, dims, init) +@inline count(f, a::StaticArray; dims=:, init=0) = _mapreduce(x->f(x)::Bool, +, dims, init, Size(a), a) @inline all(a::StaticArray{<:Tuple,Bool}; dims=:) = _reduce(&, a, dims, true) # non-branching versions @inline all(f::Function, a::StaticArray; dims=:) = _mapreduce(x->f(x)::Bool, &, dims, true, Size(a), a) diff --git a/test/mapreduce.jl b/test/mapreduce.jl index 68f347f1..902aa0ac 100644 --- a/test/mapreduce.jl +++ b/test/mapreduce.jl @@ -130,16 +130,22 @@ using Statistics: mean @test sum(sa, dims=Val(2)) === RSArray2(sum(a, dims=2)) @test sum(abs2, sa; dims=2) === RSArray2(sum(abs2, a, dims=2)) @test sum(abs2, sa; dims=Val(2)) === RSArray2(sum(abs2, a, dims=2)) + @test sum(sa, init=2) == sum(a, init=2) ≈ sum(sa) + 2 # Float64 is non-associative + @test sum(sb, init=2) == sum(b, init=2) == sum(sb) + 2 @test prod(sa) === prod(a) @test prod(abs2, sa) === prod(abs2, a) @test prod(sa, dims=Val(2)) === RSArray2(prod(a, dims=2)) @test prod(abs2, sa, dims=Val(2)) === RSArray2(prod(abs2, a, dims=2)) + @test prod(sa, init=2) == prod(a, init=2) ≈ 2*prod(sa) # Float64 is non-associative + @test prod(sb, init=2) == prod(b, init=2) == 2*prod(sb) @test count(sb) === count(b) @test count(x->x>0, sa) === count(x->x>0, a) @test count(sb, dims=Val(2)) === RSArray2(reshape([count(b[i,:,k]) for i = 1:I, k = 1:K], (I,1,K))) @test count(x->x>0, sa, dims=Val(2)) === RSArray2(reshape([count(x->x>0, a[i,:,k]) for i = 1:I, k = 1:K], (I,1,K))) + @test count(sb, init=3) == count(b, init=3) == count(sb) + 3 + @test count(x->x>0, sa, init=-2) == count(x->x>0, a, init=-2) == count(x->x>0, sa) - 2 @test all(sb) === all(b) @test all(x->x>0, sa) === all(x->x>0, a) diff --git a/test/runtests.jl b/test/runtests.jl index 1570a072..b86f343c 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -67,7 +67,6 @@ if TEST_GROUP ∈ ["", "all", "group-A"] addtests("det.jl") addtests("inv.jl") addtests("pinv.jl") - addtests("solve.jl") # special logic required since we need to start a new # Julia process for these tests @@ -78,6 +77,7 @@ if TEST_GROUP ∈ ["", "all", "group-A"] end if TEST_GROUP ∈ ["", "all", "group-B"] + addtests("solve.jl") addtests("eigen.jl") addtests("expm.jl") addtests("sqrtm.jl") From b62e2579f77983f48f7bc52e96d5d31d5d8e42b2 Mon Sep 17 00:00:00 2001 From: Antoine Levitt Date: Mon, 21 Oct 2024 15:35:13 +0200 Subject: [PATCH 3/3] Force convert diagonal to real in eigen(::Hermitian) (#1280) This matches the behavior for normal arrays --- src/eigen.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/eigen.jl b/src/eigen.jl index 9c599fd4..60208f08 100644 --- a/src/eigen.jl +++ b/src/eigen.jl @@ -57,9 +57,9 @@ end end Sreal = real(S) - @inbounds a11 = convert(Sreal, A.data[1]) - @inbounds a22 = convert(Sreal, A.data[5]) - @inbounds a33 = convert(Sreal, A.data[9]) + @inbounds a11 = convert(Sreal, real(A.data[1])) + @inbounds a22 = convert(Sreal, real(A.data[5])) + @inbounds a33 = convert(Sreal, real(A.data[9])) if A.uplo == 'U' @inbounds a12 = convert(S, A.data[4]) @inbounds a13 = convert(S, A.data[7])