Skip to content

Commit

Permalink
Specialize isassigned for AbstractFill
Browse files Browse the repository at this point in the history
  • Loading branch information
jishnub committed Feb 9, 2024
1 parent 9482273 commit 501716c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/FillArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ end
Base.@propagate_inbounds getindex(F::AbstractFill, k::Integer) = _fill_getindex(F, k)
Base.@propagate_inbounds getindex(F::AbstractFill{T, N}, kj::Vararg{Integer, N}) where {T, N} = _fill_getindex(F, kj...)

@inline function Base.isassigned(F::AbstractFill, i::Union{Integer, CartesianIndex}...)
@boundscheck checkbounds(Bool, F, i...) || return false
return true
end

@inline function setindex!(F::AbstractFill, v, k::Integer)
@boundscheck checkbounds(F, k)
v == getindex_value(F) || throw(ArgumentError("Cannot setindex! to $v for an AbstractFill with value $(getindex_value(F))."))
Expand Down
8 changes: 8 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,14 @@ end
end
end

@testset "isassigned" begin
for f in (Fill("", 3, 4), Zeros(3,4), Ones(3,4))
@test !isassigned(f, 0, 0)
@test isassigned(f, 2, 2)
@test !isassigned(f, 10, 10)
end
end

@testset "indexing" begin
A = Fill(3.0,5)
@test A[1:3] Fill(3.0,3)
Expand Down

0 comments on commit 501716c

Please sign in to comment.