Skip to content

Commit ee32732

Browse files
committed
Improve coefficients of lincomb nodes in C generated code
+ Use consecutive indices starting from 0 for non-identity nodes + Do not generate code for combinations with coefficient 0
1 parent 1af8990 commit ee32732

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/code_gen/gen_c_code.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,15 +457,20 @@ function execute_operation!(lang::LangC, T, graph, node, dealloc_list, mem)
457457
coeff_is_real = Vector()
458458
parent_mems = Vector()
459459
id_coefficient = 0
460+
counter = 1
460461
for (i, v) in enumerate(graph.coeffs[node])
461462
n = graph.parents[node][i]
463+
if v == 0
464+
continue
465+
end
462466
if (n == :I)
463467
# Coefficient of identities.
464468
id_coefficient += v
465469
else
466470
# Coefficient of other nodes.
467471
(coeff_real, coeff_i, coeff_i_code) = declare_coeff(lang, v,
468-
"$node" * "_" * "$i")
472+
"$node" * "_" * "$counter")
473+
counter += 1
469474
push_code!(code, coeff_i_code)
470475
push!(coeff_names, coeff_i)
471476
push!(coeff_is_real, coeff_real)

0 commit comments

Comments
 (0)