@@ -167,7 +167,7 @@ function _build_function(target::JuliaTarget, rhss, args...;
167
167
checkbounds = false , constructor= nothing ,
168
168
linenumbers = false , multithread= nothing ,
169
169
headerfun= addheader, outputidxs= nothing ,
170
- parallel= SerialForm ())
170
+ skipzeros = false , parallel= SerialForm ())
171
171
172
172
if multithread isa Bool
173
173
@warn (" multithraded is deprecated for the parallel argument. See the documentation." )
@@ -207,37 +207,49 @@ function _build_function(target::JuliaTarget, rhss, args...;
207
207
for (i, rhsel) ∈ enumerate (_rhss)
208
208
for (j, rhsel2) ∈ enumerate (rhsel)
209
209
for (k, rhs) ∈ enumerate (rhsel2. nzval)
210
- push! (ip_sys_exprs, :($ X[$ i][$ j]. nzval[$ k] = $ (conv (rhs))))
210
+ rhs′ = conv (rhs)
211
+ (skipzeros && rhs′ isa Number && iszero (rhs′)) && continue
212
+ push! (ip_sys_exprs, :($ X[$ i][$ j]. nzval[$ k] = $ rhs′))
211
213
end
212
214
end
213
215
end
214
216
elseif is_array_array_matrix (rhss) # Array of arrays of arrays
215
217
for (i, rhsel) ∈ enumerate (_rhss)
216
218
for (j, rhsel2) ∈ enumerate (rhsel)
217
219
for (k, rhs) ∈ enumerate (rhsel2)
218
- push! (ip_sys_exprs, :($ X[$ i][$ j][$ k] = $ (conv (rhs))))
220
+ rhs′ = conv (rhs)
221
+ (skipzeros && rhs′ isa Number && iszero (rhs′)) && continue
222
+ push! (ip_sys_exprs, :($ X[$ i][$ j][$ k] = $ rhs′))
219
223
end
220
224
end
221
225
end
222
226
elseif is_array_sparse_matrix (rhss) # Array of sparse matrices
223
227
for (i, rhsel) ∈ enumerate (_rhss)
224
228
for (j, rhs) ∈ enumerate (rhsel. nzval)
225
- push! (ip_sys_exprs, :($ X[$ i]. nzval[$ j] = $ (conv (rhs))))
229
+ rhs′ = conv (rhs)
230
+ (skipzeros && rhs′ isa Number && iszero (rhs′)) && continue
231
+ push! (ip_sys_exprs, :($ X[$ i]. nzval[$ j] = $ rhs′))
226
232
end
227
233
end
228
234
elseif is_array_matrix (rhss) # Array of arrays
229
235
for (i, rhsel) ∈ enumerate (_rhss)
230
236
for (j, rhs) ∈ enumerate (rhsel)
231
- push! (ip_sys_exprs, :($ X[$ i][$ j] = $ (conv (rhs))))
237
+ rhs′ = conv (rhs)
238
+ (skipzeros && rhs′ isa Number && iszero (rhs′)) && continue
239
+ push! (ip_sys_exprs, :($ X[$ i][$ j] = $ rhs′))
232
240
end
233
241
end
234
242
elseif rhss isa SparseMatrixCSC
235
243
for (i, rhs) ∈ enumerate (_rhss)
236
- push! (ip_sys_exprs, :($ X. nzval[$ i] = $ (conv (rhs))))
244
+ rhs′ = conv (rhs)
245
+ (skipzeros && rhs′ isa Number && iszero (rhs′)) && continue
246
+ push! (ip_sys_exprs, :($ X. nzval[$ i] = $ rhs′))
237
247
end
238
248
else
239
249
for (i, rhs) ∈ enumerate (_rhss)
240
- push! (ip_sys_exprs, :($ X[$ i] = $ (conv (rhs))))
250
+ rhs′ = conv (rhs)
251
+ (skipzeros && rhs′ isa Number && iszero (rhs′)) && continue
252
+ push! (ip_sys_exprs, :($ X[$ i] = $ rhs′))
241
253
end
242
254
end
243
255
0 commit comments