Skip to content

Commit

Permalink
Type-inference improvement in reduce over Ones (#291)
Browse files Browse the repository at this point in the history
* Type-inference improvement in reduce over Ones

* reduce_first on the value
  • Loading branch information
jishnub authored Aug 23, 2023
1 parent 5abd5f6 commit fef31cd
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 2 additions & 0 deletions src/fillalgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,))
Expand Down

0 comments on commit fef31cd

Please sign in to comment.