Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/FillArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,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...)
Expand Down
5 changes: 5 additions & 0 deletions src/oneelement.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ end

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) =
Expand Down
17 changes: 17 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -2119,6 +2128,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)
Expand Down