Skip to content

Commit 3d7f094

Browse files
committed
Fix map
1 parent 09d1591 commit 3d7f094

File tree

1 file changed

+11
-6
lines changed
  • src/abstractblocksparsearray

1 file changed

+11
-6
lines changed

src/abstractblocksparsearray/map.jl

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,18 @@ end
9696
end
9797
subblock_dest = @view block_dest[BI_dest.indices...]
9898
subblock_srcs = ntuple(i -> @view(block_srcs[i][BI_srcs[i].indices...]), length(a_srcs))
99-
if f_preserves_zeros && any(!iszero, subblock_srcs)
100-
# TODO: Use `map!!` to handle immutable blocks.
101-
map!(f, subblock_dest, subblock_srcs...)
102-
# Replace the entire block, handles initializing new blocks
103-
# or if blocks are immutable.
104-
blocks(a_dest)[Int.(Tuple(_block(BI_dest)))...] = block_dest
99+
I_dest = CartesianIndex(Int.(Tuple(_block(BI_dest))))
100+
# If the function preserves zero values and all of the source blocks are zero,
101+
# the output block will be zero. In that case, if the block isn't stored yet,
102+
# don't do anything.
103+
if f_preserves_zeros && all(iszero, subblock_srcs) && !isstored(blocks(a_dest), I_dest)
104+
continue
105105
end
106+
# TODO: Use `map!!` to handle immutable blocks.
107+
map!(f, subblock_dest, subblock_srcs...)
108+
# Replace the entire block, handles initializing new blocks
109+
# or if blocks are immutable.
110+
blocks(a_dest)[I_dest] = block_dest
106111
end
107112
return a_dest
108113
end

0 commit comments

Comments
 (0)