Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 7 additions & 1 deletion src/FillArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Base: size, getindex, setindex!, IndexStyle, checkbounds, convert,
+, -, *, /, \, diff, sum, cumsum, maximum, minimum, sort, sort!,
any, all, axes, isone, iterate, unique, allunique, permutedims, inv,
copy, vec, setindex!, count, ==, reshape, _throw_dmrs, map, zero,
show, view
show, view, in

import LinearAlgebra: rank, svdvals!, tril, triu, tril!, triu!, diag, transpose, adjoint, fill!,
norm2, norm1, normInf, normMinusInf, normp, lmul!, rmul!, diagzero, AbstractTriangular, AdjointAbsVec
Expand Down Expand Up @@ -572,6 +572,12 @@ count(x::Ones{Bool}) = length(x)
count(x::Zeros{Bool}) = 0
count(f, x::AbstractFill) = f(getindex_value(x)) ? length(x) : 0

#########
# in
#########
in(x, A::Union{Ones, Zeros, Fill}) = x == getindex_value(A)
in(x, A::RectDiagonal) = iszero(x) || x in A.diag

include("fillalgebra.jl")
include("fillbroadcast.jl")
include("trues.jl")
Expand Down
11 changes: 11 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,17 @@ import FillArrays: AbstractFill, RectDiagonal, SquareEye
@test vec(Zeros{Int}(5,10,20)) ≡ Zeros{Int}(1000)
@test vec(Fill(1,5,10)) ≡ Fill(1,50)
end

@testset "in" begin
for T in [Zeros, Ones, Fill, Trues, Falses]
A = T(4, 4)
@test FillArrays.getindex_value(A) in A
@test !(FillArrays.getindex_value(A) + 1 in A)
end
A = FillArrays.RectDiagonal([1, 2, 3])
@test 3 in A
@test !(4 in A)
end
end

@testset "indexing" begin
Expand Down