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

Commit df36fb5

Browse files
author
Langwen Huang
committed
fix oop jac for sparsemat
1 parent 95e4b27 commit df36fb5

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/differentiation/compute_jacobian_ad.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,12 @@ function forwarddiff_color_jacobian(f,x::AbstractArray{<:Number},jac_cache::Forw
111111
len_rows = length(pick_inds)
112112
unused_rows = setdiff(1:nrows,rows_index_c)
113113
perm_rows = sortperm(vcat(rows_index_c,unused_rows))
114-
cols_index_c = vcat(cols_index_c,zeros(Int,nrows-len_rows))[perm_rows]
115-
Ji = [j==cols_index_c[i] ? dx[i] : false for i in 1:nrows, j in 1:ncols]
114+
if J isa SparseMatrixCSC
115+
Ji = sparse(rows_index_c, cols_index_c, dx[rows_index_c],nrows,ncols)
116+
else
117+
cols_index_c = vcat(cols_index_c,zeros(Int,nrows-len_rows))[perm_rows]
118+
Ji = [j==cols_index_c[i] ? dx[i] : false for i in 1:nrows, j in 1:ncols]
119+
end
116120
J = J + Ji
117121
color_i += 1
118122
(color_i > maxcolor) && return J

0 commit comments

Comments
 (0)