Skip to content

Commit

Permalink
specialize isassigned for performance (#15)
Browse files Browse the repository at this point in the history
Fixes #14
  • Loading branch information
nsajko authored Apr 21, 2024
1 parent 4a1613e commit 5353022
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/FixedSizeArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ function Base.similar(::FixedSizeArray, ::Type{S}, size::NTuple{N,Int}) where {S
FixedSizeArray{S,N}(undef, size...)
end

Base.isassigned(a::FixedSizeArray, i::Int) = isassigned(a.mem, i)

# broadcasting

function Base.BroadcastStyle(::Type{<:FixedSizeArray})
Expand Down
24 changes: 24 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,28 @@ using FixedSizeArrays
@test (@inferred (m33 .+ m33)) isa FixedSizeMatrix{Int}
end
end

@testset "`isassigned`" begin
for dim_count 1:3
for elem_type (Int, FixedSizeMatrix{Nothing})
size = ntuple(Returns(3), dim_count)
a = FixedSizeArray{elem_type, dim_count}(undef, size)
for i_style (IndexLinear(), IndexCartesian())
for i eachindex(i_style, a)
@test isassigned(a, i) == isbitstype(elem_type)
end
end
end
@testset "some assigned" begin
a = FixedSizeMatrix{FixedSizeMatrix{Nothing}}(undef, 3, 3)
assigned_inds = ((1, 2), (2, 3), (3, 3))
for ij assigned_inds
a[ij...] = FixedSizeMatrix{Nothing}(undef, 1, 1)
end
for ij Iterators.product(1:3, 1:3)
@test isassigned(a, ij...) == (ij assigned_inds)
end
end
end
end
end

0 comments on commit 5353022

Please sign in to comment.