diff --git a/src/FillArrays.jl b/src/FillArrays.jl index 581e8252..d8db9f5d 100644 --- a/src/FillArrays.jl +++ b/src/FillArrays.jl @@ -33,6 +33,10 @@ const AbstractFillVecOrMat{T} = Union{AbstractFillVector{T},AbstractFillMatrix{T ==(a::AbstractFill, b::AbstractFill) = axes(a) == axes(b) && getindex_value(a) == getindex_value(b) +@inline function Base.isassigned(F::AbstractFill, i::Integer...) + @boundscheck checkbounds(Bool, F, to_indices(F, i)...) || return false + return true +end @inline function _fill_getindex(F::AbstractFill, kj::Integer...) @boundscheck checkbounds(F, kj...) diff --git a/src/oneelement.jl b/src/oneelement.jl index b731071f..f6204abb 100644 --- a/src/oneelement.jl +++ b/src/oneelement.jl @@ -97,6 +97,11 @@ julia> FillArrays.getindex_value(A) """ getindex_value(A::OneElement) = all(in.(A.ind, axes(A))) ? A.val : zero(eltype(A)) +@inline function Base.isassigned(F::OneElement, i::Integer...) + @boundscheck checkbounds(Bool, F, to_indices(F, i)...) || return false + return true +end + Base.AbstractArray{T,N}(A::OneElement{<:Any,N}) where {T,N} = OneElement(T(A.val), A.ind, A.axes) Base.replace_in_print_matrix(o::OneElementVector, k::Integer, j::Integer, s::AbstractString) = diff --git a/test/runtests.jl b/test/runtests.jl index 2fd3c5ca..8af5ed45 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -261,6 +261,15 @@ 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) + @test_throws ArgumentError isassigned(f, true) + end +end + @testset "indexing" begin A = Fill(3.0,5) @test A[1:3] ≡ Fill(3.0,3) @@ -2184,6 +2193,14 @@ end @test adjoint(A) == OneElement(3, (1,2), (1,4)) end + @testset "isassigned" begin + f = OneElement(2, (3,3), (4,4)) + @test !isassigned(f, 0, 0) + @test isassigned(f, 2, 2) + @test !isassigned(f, 10, 10) + @test_throws ArgumentError isassigned(f, true) + end + @testset "matmul" begin A = reshape(Float64[1:9;], 3, 3) v = reshape(Float64[1:3;], 3)