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

Commit f724afa

Browse files
author
Langwen Huang
committed
small optimization
1 parent df36fb5 commit f724afa

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/differentiation/compute_jacobian_ad.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,12 @@ function forwarddiff_color_jacobian(f,x::AbstractArray{<:Number},jac_cache::Forw
108108
pick_inds = [i for i in 1:length(rows_index) if colorvec[cols_index[i]] == color_i]
109109
rows_index_c = rows_index[pick_inds]
110110
cols_index_c = cols_index[pick_inds]
111-
len_rows = length(pick_inds)
112-
unused_rows = setdiff(1:nrows,rows_index_c)
113-
perm_rows = sortperm(vcat(rows_index_c,unused_rows))
114111
if J isa SparseMatrixCSC
115112
Ji = sparse(rows_index_c, cols_index_c, dx[rows_index_c],nrows,ncols)
116113
else
114+
len_rows = length(pick_inds)
115+
unused_rows = setdiff(1:nrows,rows_index_c)
116+
perm_rows = sortperm(vcat(rows_index_c,unused_rows))
117117
cols_index_c = vcat(cols_index_c,zeros(Int,nrows-len_rows))[perm_rows]
118118
Ji = [j==cols_index_c[i] ? dx[i] : false for i in 1:nrows, j in 1:ncols]
119119
end

0 commit comments

Comments
 (0)