Skip to content

avoid accidental dense sparse matrices will fill! #130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/jacobians.jl
Original file line number Diff line number Diff line change
Expand Up @@ -345,12 +345,16 @@ function finite_difference_jacobian!(
end

if sparsity !== nothing
fill!(J,false)
if J isa SparseMatrixCSC
fill!(nonzeros(J),false)
else
fill!(J,false)
end
end

# fast path if J and sparsity are both SparseMatrixCSC and have the same sparsity pattern
sparseCSC_common_sparsity = _use_sparseCSC_common_sparsity(J, sparsity)

if fdtype == Val(:forward)
vfx1 = _vec(fx1)

Expand Down Expand Up @@ -424,7 +428,7 @@ function finite_difference_jacobian!(
f(fx1, x1)
f(fx, x)
@. vfx1 = (vfx1 - vfx) / 2epsilon
if ArrayInterface.fast_scalar_indexing(x1)
if ArrayInterface.fast_scalar_indexing(x1)
if sparseCSC_common_sparsity
_colorediteration!(J,vfx1,colorvec,color_i,n)
else
Expand Down Expand Up @@ -454,7 +458,7 @@ function finite_difference_jacobian!(
@. x1 = x1 + im * epsilon * (_color == color_i)
f(fx,x1)
@. vfx = imag(vfx) / epsilon
if ArrayInterface.fast_scalar_indexing(x1)
if ArrayInterface.fast_scalar_indexing(x1)
if sparseCSC_common_sparsity
_colorediteration!(J,vfx,colorvec,color_i,n)
else
Expand Down