From 4881e7a0f70bd796cc12bd53c68c6732492a3043 Mon Sep 17 00:00:00 2001 From: Lilith Orion Hafner Date: Sun, 30 Apr 2023 12:25:35 -0500 Subject: [PATCH] Simplify `getindex` and remove usage of `getkey` --- src/direct/sparseblocks.jl | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/direct/sparseblocks.jl b/src/direct/sparseblocks.jl index 18d6ce7..cbbc11a 100644 --- a/src/direct/sparseblocks.jl +++ b/src/direct/sparseblocks.jl @@ -163,11 +163,8 @@ struct SparseBlockIndex end function Base.getindex(blocks::SparseBlocks, i1::UnitRange, i2::UnitRange) - block0 = BlockIndices(i1, i2, false) - block = getkey(blocks.inds, block0, nothing) - if isnothing(block) - throw(KeyError((i1, i2))) - end + block = BlockIndices(i1, i2, false) + haskey(blocks.inds, block) || throw(KeyError((i1, i2))) SparseBlockIndex(block, blocks.inds[block]) end @@ -295,4 +292,4 @@ function Broadcast.materialize!(B::SparseBlockView, bc::Broadcast.Broadcasted{<: B[r,c] = bc[i] end end -end \ No newline at end of file +end