diff --git a/Project.toml b/Project.toml index 138df586..343e2469 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "FillArrays" uuid = "1a297f60-69ca-5386-bcde-b61e274b549b" -version = "1.6.0" +version = "1.6.1" [deps] LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" diff --git a/src/fillalgebra.jl b/src/fillalgebra.jl index f0f7d044..1ac9e21d 100644 --- a/src/fillalgebra.jl +++ b/src/fillalgebra.jl @@ -353,6 +353,8 @@ end -(a::Zeros) = a -(a::AbstractFill) = Fill(-getindex_value(a), size(a)) +# special-cased for type-stability, as Ones + Ones is not a Ones +Base.reduce_first(::typeof(+), x::Ones) = Fill(Base.reduce_first(+, getindex_value(x)), axes(x)) function +(a::Zeros{T}, b::Zeros{V}) where {T, V} # for disambiguity promote_shape(a,b) diff --git a/test/runtests.jl b/test/runtests.jl index 3dbe80b1..50d42c54 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -825,6 +825,9 @@ end @test diff(Ones{Float64}(10)) ≡ Zeros{Float64}(9) @test_throws UndefKeywordError cumsum(Fill(1,1,5)) + @test @inferred(sum([Ones(4)])) ≡ Fill(1.0, 4) + @test @inferred(sum([Trues(4)])) ≡ Fill(1, 4) + @testset "infinite arrays" begin r = InfiniteArrays.OneToInf() A = Ones{Int}((r,))