Skip to content
This repository was archived by the owner on Aug 22, 2025. It is now read-only.

Commit fe1402b

Browse files
don't fill! on a SparseMatrix
```julia julia> x = sprand(2,2,0.5) 2×2 SparseMatrixCSC{Float64, Int64} with 1 stored entry: 0.507603 ⋅ ⋅ ⋅ julia> fill!(x, true) 2×2 SparseMatrixCSC{Float64, Int64} with 4 stored entries: 1.0 1.0 1.0 1.0 ``` Seems like an issue for Base.
1 parent de19848 commit fe1402b

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/differentiation/compute_jacobian_ad.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,11 @@ function forwarddiff_color_jacobian!(J::AbstractMatrix{<:Number},
296296
color_i = 1
297297
maxcolor = maximum(colorvec)
298298

299-
fill!(J, zero(eltype(J)))
299+
if J isa SparseMatrixCSC
300+
fill!(nonzeros(J), zero(eltype(J)))
301+
else
302+
fill!(J, zero(eltype(J)))
303+
end
300304

301305
if FiniteDiff._use_findstructralnz(sparsity)
302306
rows_index, cols_index = ArrayInterface.findstructralnz(sparsity)

0 commit comments

Comments
 (0)