Skip to content

Commit 8369959

Browse files
authored
Merge pull request #659 from SBuercklin/sbuercklin/dy-zero
Use `eltype` to determine the proper zero to `fill!` in _zerolike_writeat
2 parents 148fa88 + 03ba34f commit 8369959

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/rulesets/Base/array.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,9 +537,11 @@ end
537537
# This function is roughly `setindex!(zero(x), dy, inds...)`:
538538

539539
function _zerolike_writeat(x::AbstractArray{<:Number}, dy, dims, inds...)
540+
_zero_fill = eltype(dy) == Any ? 0 : zero(eltype(dy))
541+
540542
# It's unfortunate to close over `x`, but `similar(typeof(x), axes(x))` doesn't
541543
# allow `eltype(dy)`, nor does it work for many structured matrices.
542-
dx = fill!(similar(x, eltype(dy), axes(x)), 0)
544+
dx = fill!(similar(x, eltype(dy), axes(x)), _zero_fill)
543545
view(dx, inds...) .= dy # possibly 0-dim view, allows dy::Number and dy::Array, and dx::CuArray
544546
dx
545547
end

0 commit comments

Comments
 (0)