Skip to content

Commit 5353022

Browse files
authored
specialize isassigned for performance (#15)
Fixes #14
1 parent 4a1613e commit 5353022

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/FixedSizeArrays.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ function Base.similar(::FixedSizeArray, ::Type{S}, size::NTuple{N,Int}) where {S
3636
FixedSizeArray{S,N}(undef, size...)
3737
end
3838

39+
Base.isassigned(a::FixedSizeArray, i::Int) = isassigned(a.mem, i)
40+
3941
# broadcasting
4042

4143
function Base.BroadcastStyle(::Type{<:FixedSizeArray})

test/runtests.jl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,28 @@ using FixedSizeArrays
9191
@test (@inferred (m33 .+ m33)) isa FixedSizeMatrix{Int}
9292
end
9393
end
94+
95+
@testset "`isassigned`" begin
96+
for dim_count 1:3
97+
for elem_type (Int, FixedSizeMatrix{Nothing})
98+
size = ntuple(Returns(3), dim_count)
99+
a = FixedSizeArray{elem_type, dim_count}(undef, size)
100+
for i_style (IndexLinear(), IndexCartesian())
101+
for i eachindex(i_style, a)
102+
@test isassigned(a, i) == isbitstype(elem_type)
103+
end
104+
end
105+
end
106+
@testset "some assigned" begin
107+
a = FixedSizeMatrix{FixedSizeMatrix{Nothing}}(undef, 3, 3)
108+
assigned_inds = ((1, 2), (2, 3), (3, 3))
109+
for ij assigned_inds
110+
a[ij...] = FixedSizeMatrix{Nothing}(undef, 1, 1)
111+
end
112+
for ij Iterators.product(1:3, 1:3)
113+
@test isassigned(a, ij...) == (ij assigned_inds)
114+
end
115+
end
116+
end
117+
end
94118
end

0 commit comments

Comments
 (0)